diff options
| author | Albrecht Schlosser <albrechts.fltk@online.de> | 2024-10-25 02:39:47 +0200 |
|---|---|---|
| committer | Albrecht Schlosser <albrechts.fltk@online.de> | 2024-10-25 02:39:47 +0200 |
| commit | c0e07d3452a65cc0f0ea7f56ec149ffd7e6e934f (patch) | |
| tree | 8414128c297f35a997131139fd81b2c693cfdd55 | |
| parent | f9f89be7d739ae9816bef49deef81c85781b11f9 (diff) | |
Add range check to Fl_Group::child(int)
Returns NULL if n is out of range to prevent accessing undefined
memory.
| -rw-r--r-- | FL/Fl_Group.H | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/FL/Fl_Group.H b/FL/Fl_Group.H index 173f8754b..27c68ef8a 100644 --- a/FL/Fl_Group.H +++ b/FL/Fl_Group.H @@ -29,7 +29,7 @@ class Fl_Rect; /** - The Fl_Group class is the FLTK container widget. It maintains + The Fl_Group class is the main FLTK container widget. It maintains an array of child widgets. These children can themselves be any widget including Fl_Group. The most important subclass of Fl_Group is Fl_Window, however groups can also be used to control radio buttons @@ -95,11 +95,23 @@ public: /** Returns how many child widgets the group has. */ - int children() const {return children_;} + int children() const { return children_; } + /** - Returns array()[n]. <i>No range checking is done!</i> + Returns the n'th child. + + Returns \c NULL if \c n is out of range (since FLTK 1.4.0). + + <i>No range checking was done in FLTK 1.3 and older versions!</i> + + \param[in] n index of child (0 .. children() - 1) + \return pointer to the n'th child or NULL if out of range */ - Fl_Widget* child(int n) const {return array()[n];} + Fl_Widget *child(int n) const { + if (n < 0 || n > children() - 1) return NULL; + return array()[n]; + } + int find(const Fl_Widget*) const; /** See int Fl_Group::find(const Fl_Widget *w) const |
