diff options
| author | Albrecht Schlosser <albrechts.fltk@online.de> | 2016-09-23 14:04:56 +0000 |
|---|---|---|
| committer | Albrecht Schlosser <albrechts.fltk@online.de> | 2016-09-23 14:04:56 +0000 |
| commit | 67f98ae4f30f92357960d678091e4d60744eb508 (patch) | |
| tree | 561b14937d4b2164f9216781d80f4a7e0e335c5b /src/Fl_Tabs.cxx | |
| parent | 0250c5a98af506f2f107f8bd2e9e2c2c87a10c10 (diff) | |
Fix potential crash when using keyboard nav. on Fl_Tabs (STR #3333).
Also: more consistent use of 'const int nc = children()'. Added 'const'
qualifier for clarity only. This does not change the behavior.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3-porting@11971 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
Diffstat (limited to 'src/Fl_Tabs.cxx')
| -rw-r--r-- | src/Fl_Tabs.cxx | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/src/Fl_Tabs.cxx b/src/Fl_Tabs.cxx index f0117b431..26e092f3e 100644 --- a/src/Fl_Tabs.cxx +++ b/src/Fl_Tabs.cxx @@ -3,7 +3,7 @@ // // Tab widget for the Fast Light Tool Kit (FLTK). // -// Copyright 1998-2015 by Bill Spitzak and others. +// Copyright 1998-2016 by Bill Spitzak and others. // // This library is free software. Distribution and use rights are outlined in // the file "COPYING" which should have been included with this file. If this @@ -41,7 +41,7 @@ // Return value is the index of the selected item. int Fl_Tabs::tab_positions() { - int nc = children(); + const int nc = children(); if (nc != tab_count) { clear_tab_positions(); if (nc) { @@ -86,7 +86,7 @@ int Fl_Tabs::tab_positions() { for (i = 0; i<nc; i++) { if (tab_pos[i] >= i*EXTRASPACE) break; tab_pos[i] = i*EXTRASPACE; - int W = w()-1-EXTRASPACE*(children()-i) - tab_pos[i]; + int W = w()-1-EXTRASPACE*(nc-i) - tab_pos[i]; if (tab_width[i] > W) tab_width[i] = W; } // adjust edges according to visiblity: @@ -130,7 +130,7 @@ Fl_Widget *Fl_Tabs::which(int event_x, int event_y) { } if (event_x < x()) return 0; Fl_Widget *ret = 0L; - int nc = children(); + const int nc = children(); tab_positions(); for (int i=0; i<nc; i++) { if (event_x < x()+tab_pos[i+1]) { @@ -223,6 +223,7 @@ int Fl_Tabs::handle(int event) { case FL_KEYBOARD: switch (Fl::event_key()) { case FL_Left: + if (!children()) return 0; if (child(0)->visible()) return 0; for (i = 1; i < children(); i ++) if (child(i)->visible()) break; @@ -231,6 +232,7 @@ int Fl_Tabs::handle(int event) { do_callback(); return 1; case FL_Right: + if (!children()) return 0; if (child(children() - 1)->visible()) return 0; for (i = 0; i < children(); i ++) if (child(i)->visible()) break; @@ -350,7 +352,7 @@ void Fl_Tabs::draw() { if (v) update_child(*v); } if (damage() & (FL_DAMAGE_SCROLL|FL_DAMAGE_ALL)) { - int nc = children(); + const int nc = children(); int selected = tab_positions(); int i; Fl_Widget*const* a = array(); |
