FLTK logo

[master] 5496885 - Followup: avoid dereference null pointer (#971)

FLTK matrix user chat room
(using Element browser app)   FLTK gitter user chat room   GitHub FLTK Project   FLTK News RSS Feed  
  FLTK Apps      FLTK Library      Forums      Links     Login 
 All Forums  |  Back to fltk.commit  ]
 
Previous Message ]Next Message ]

[master] 5496885 - Followup: avoid dereference null pointer (#971) "Greg Ercolano" 01:02 May 09  
 
commit 549688598fd4f0d208c413b1db9e18aea74c92bc
Author:     Greg Ercolano <erco@seriss.com>
AuthorDate: Thu May 9 00:55:56 2024 -0700
Commit:     Greg Ercolano <erco@seriss.com>
CommitDate: Thu May 9 00:55:56 2024 -0700

    Followup: avoid dereference null pointer (#971)
    
    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.

 src/Fl_Tree.cxx | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git src/Fl_Tree.cxx src/Fl_Tree.cxx
index 50f13b9..40c2803 100644
--- src/Fl_Tree.cxx
+++ src/Fl_Tree.cxx
@@ -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
@@ -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)
@@ -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?
@@ -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?
Direct Link to Message ]
 
     
Previous Message ]Next Message ]
 
 

Comments are owned by the poster. All other content is copyright 1998-2024 by Bill Spitzak and others. This project is hosted by The FLTK Team. Please report site problems to 'erco@seriss.com'.