summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlbrecht Schlosser <albrechts.fltk@online.de>2020-06-02 14:53:36 +0200
committerAlbrecht Schlosser <albrechts.fltk@online.de>2020-06-24 19:58:33 +0200
commitc12408b53fce13bc0138acfa3ad00aeabc214ba5 (patch)
treeaa4db4a344256b2765c0a09c6706f2dc060616b8
parent930013638bfc5d7765ca1bf2b680640d79bec2da (diff)
Avoid crash in Fl::next_window(win)
As documented, Fl::next_window(win) must only be called with a valid *shown* window. The old code would crash if the argument was NULL or the window was not shown. The new code avoids the crash, issues an error message, and returns NULL to the caller.
-rw-r--r--src/Fl.cxx7
1 files changed, 6 insertions, 1 deletions
diff --git a/src/Fl.cxx b/src/Fl.cxx
index 6742b0bc9..f6fef73e3 100644
--- a/src/Fl.cxx
+++ b/src/Fl.cxx
@@ -659,7 +659,12 @@ Fl_Window* Fl::first_window() {
\param[in] window must be shown and not NULL
*/
Fl_Window* Fl::next_window(const Fl_Window* window) {
- Fl_X* i = Fl_X::i(window)->next;
+ Fl_X* i = window ? Fl_X::i(window) : 0;
+ if (!i) {
+ Fl::error("Fl::next_window() failed: window (%p) not shown.", window);
+ return 0;
+ }
+ i = i->next;
return i ? i->w : 0;
}