From 2c5ba944582a8101cd3fd7445814a2e50b4701bd Mon Sep 17 00:00:00 2001 From: Albrecht Schlosser Date: Fri, 25 Jan 2019 17:39:20 +0100 Subject: Fix Fl_Tree::insert() with pos out ouf range (#18) The given position to insert a new item was not checked against the valid range so the program could crash if a position less than zero or greater than children() was given. The position is now clamped to the valid range, i.e. the item is either prepended or appended. Fixes issue #18. --- src/Fl_Tree.cxx | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src/Fl_Tree.cxx') diff --git a/src/Fl_Tree.cxx b/src/Fl_Tree.cxx index a658a38c7..1b83dda96 100644 --- a/src/Fl_Tree.cxx +++ b/src/Fl_Tree.cxx @@ -874,6 +874,14 @@ Fl_Tree_Item* Fl_Tree::insert_above(Fl_Tree_Item *above, const char *name) { /** Insert a new item \p 'name' into \p 'item's children at position \p 'pos'. + + If \p pos is out of range the new item is + - prepended if \p pos \< 0 or + - appended if \p pos \> item->children(). + + Note: \p pos == children() is not considered out of range: the item is + appended to the child list. + Example: \par \code -- cgit v1.2.3