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.
This commit is contained in:
Albrecht Schlosser 2020-06-02 14:53:36 +02:00
parent 930013638b
commit c12408b53f

View File

@ -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;
}