summaryrefslogtreecommitdiff
path: root/src/Fl_Tree_Item.cxx
diff options
context:
space:
mode:
authorAlbrecht Schlosser <albrechts.fltk@online.de>2019-01-25 17:39:20 +0100
committerAlbrecht Schlosser <albrechts.fltk@online.de>2019-01-25 17:40:51 +0100
commit2c5ba944582a8101cd3fd7445814a2e50b4701bd (patch)
treeee8f8dbe9fc9e5aab1aedee44cadafd4ba976cab /src/Fl_Tree_Item.cxx
parent9b272cfa4e664b0a90540256edf030c43e4bfbb0 (diff)
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.
Diffstat (limited to 'src/Fl_Tree_Item.cxx')
-rw-r--r--src/Fl_Tree_Item.cxx15
1 files changed, 11 insertions, 4 deletions
diff --git a/src/Fl_Tree_Item.cxx b/src/Fl_Tree_Item.cxx
index 2b3e3602a..666a54674 100644
--- a/src/Fl_Tree_Item.cxx
+++ b/src/Fl_Tree_Item.cxx
@@ -387,10 +387,17 @@ Fl_Tree_Item *Fl_Tree_Item::add(const Fl_Tree_Prefs &prefs,
: 0; // failed? error
}
-/// Insert a new item named \p 'new_label' into current item's
-/// children at a specified position \p 'pos'.
-/// \returns the new item inserted.
-///
+/**
+ Insert a new item named \p 'new_label' into current item's
+ children at a specified 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().
+
+ \returns the new item inserted
+ \see Fl_Tree::insert()
+*/
Fl_Tree_Item *Fl_Tree_Item::insert(const Fl_Tree_Prefs &prefs, const char *new_label, int pos) {
Fl_Tree_Item *item = new Fl_Tree_Item(_tree);
item->label(new_label);