Skip to content

Commit

Permalink
Followup: avoid dereference null pointer (#971)
Browse files Browse the repository at this point in the history
Changing _root->find_clicked(..) to just find_clicked(..)
includes the check of _root for NULL, which is probably better
than doing a repeat explicit check and early exit.
  • Loading branch information
erco77 committed May 9, 2024
1 parent 324fcfc commit 5496885
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/Fl_Tree.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -383,8 +383,7 @@ int Fl_Tree::handle(int e) {
case FL_PUSH: { // clicked on tree
last_my = Fl::event_y(); // save for dragging direction..
if (Fl::visible_focus() && handle(FL_FOCUS)) Fl::focus(this);
if ( ! _root ) return(ret); // issue #971
Fl_Tree_Item *item = _root->find_clicked(_prefs, 0);
Fl_Tree_Item *item = find_clicked(0);
// Tell FL_DRAG what was pushed
_lastpushed = item ? item->event_on_collapse_icon(_prefs) ? PUSHED_OPEN_CLOSE // open/close icon clicked
: item->event_on_user_icon(_prefs) ? PUSHED_USER_ICON // usericon clicked
Expand Down Expand Up @@ -471,7 +470,7 @@ int Fl_Tree::handle(int e) {
// During drag, only interested in left-mouse operations.
//
if ( Fl::event_button() != FL_LEFT_MOUSE ) break;
Fl_Tree_Item *item = _root->find_clicked(_prefs, 1); // item we're on, vertically
Fl_Tree_Item *item = find_clicked(1); // item we're on, vertically
if ( !item ) break; // not near item? ignore drag event
ret |= 1; // acknowledge event
if (_prefs.selectmode() != FL_TREE_SELECT_SINGLE_DRAGGABLE)
Expand Down Expand Up @@ -506,7 +505,7 @@ int Fl_Tree::handle(int e) {
case FL_RELEASE:
if (_prefs.selectmode() == FL_TREE_SELECT_SINGLE_DRAGGABLE &&
Fl::event_button() == FL_LEFT_MOUSE) {
Fl_Tree_Item *item = _root->find_clicked(_prefs, 1); // item mouse is over (vertically)
Fl_Tree_Item *item = find_clicked(1); // item mouse is over (vertically)
if (item && // mouse over valid item?
_lastselect && // item being dragged is valid?
item != _lastselect) { // item we're over not same as drag item?
Expand Down Expand Up @@ -749,7 +748,7 @@ void Fl_Tree::draw() {
if (_prefs.selectmode() == FL_TREE_SELECT_SINGLE_DRAGGABLE && // drag mode?
Fl::pushed() == this) { // item clicked is the one we're drawing?

Fl_Tree_Item *item = _root->find_clicked(_prefs, 1); // item we're on, vertically
Fl_Tree_Item *item = find_clicked(1); // item we're on, vertically
if (item && // we're over a valid item?
item != _item_focus) { // item doesn't have keyboard focus?
// Are we dropping above or below the target item?
Expand Down

0 comments on commit 5496885

Please sign in to comment.