Coverity: Forward NULL: CID 59, 58, 56
authorNelson Ferreira <nelson.ferreira@ieee.org>
Wed, 18 Jan 2012 20:29:11 +0000 (15:29 -0500)
committerNelson Ferreira <nelson.ferreira@ieee.org>
Wed, 18 Jan 2012 20:29:11 +0000 (15:29 -0500)
* src/ui/lwlib/lwlib-Xaw.c (xaw_generic_callback): Make sure you
do not dereference possible NULL val.

* src/ui/lwlib/lwlib-Xaw.c (wm_delete_window): Make sure widget
and kids are only used when valid.

* src/ui/lwlib/lwlib.c (replace_widget_value_tree): Make sure node
is only used if != NULL.

* src/ui/lwlib/lwlib.c (lw_map_widget_values): Make sure info is
only used if != NULL.

Signed-off-by: Nelson Ferreira <nelson.ferreira@ieee.org>
src/ui/lwlib/lwlib-Xaw.c
src/ui/lwlib/lwlib.c

index acdae40..fdfe288 100644 (file)
@@ -583,7 +583,7 @@ xaw_generic_callback(Widget widget, XtPointer closure, XtPointer call_data)
                /* If the widget is a buffer/gutter widget then we already have
                   the one we are looking for, so don't try and descend the widget
                   tree. */
-               if (val->contents) {
+               if (val && val->contents) {
                        char *name = XtName(widget);
                        val = val->contents;
                        while (val) {
@@ -591,10 +591,11 @@ xaw_generic_callback(Widget widget, XtPointer closure, XtPointer call_data)
                                        break;
                                val = val->next;
                        }
-                       if (!val)
-                               abort();
                }
-               user_data = val->call_data;
+               if (val)
+                       user_data = val->call_data;
+               else 
+                       abort();
        }
 #endif
 
@@ -617,22 +618,23 @@ wm_delete_window(Widget shell, XtPointer closure, XtPointer call_data)
        XtGetValues(shell, al, 1);
        if (!kids || !*kids)
                abort();
-       widget = kids[0];
-       if (!XtIsSubclass(widget, dialogWidgetClass))
-               abort();
-       id = lw_get_widget_id(widget);
-       if (!id)
-               abort();
-
-       {
-               widget_info *info = lw_get_widget_info(id);
-               if (!info)
+       else {
+               widget = kids[0];
+               if (!XtIsSubclass(widget, dialogWidgetClass))
                        abort();
-               if (info->selection_cb)
-                       info->selection_cb(widget, id, (XtPointer) - 1);
-       }
+               id = lw_get_widget_id(widget);
+               if (!id)
+                       abort();
+               else {
+                       widget_info *info = lw_get_widget_info(id);
+                       if (!info)
+                               abort();
+                       else if (info->selection_cb)
+                               info->selection_cb(widget, id, (XtPointer) - 1);
+               }
 
-       lw_destroy_all_widgets(id);
+               lw_destroy_all_widgets(id);
+       }
        return NULL;
 }
 
index f0d257b..8730a4e 100644 (file)
@@ -318,12 +318,15 @@ widget_value *replace_widget_value_tree(widget_value * node,
 
        if (!node || !newtree)
                abort();
+       else {
 
-       copy = copy_widget_value_tree(newtree, STRUCTURAL_CHANGE);
+               copy = copy_widget_value_tree(newtree, STRUCTURAL_CHANGE);
 
-       free_widget_value_contents(node);
-       *node = *copy;
-       free_widget_value(copy);        /* free the node, but not its contents. */
+               free_widget_value_contents(node);
+               *node = *copy;
+                /* free the node, but not its contents. */
+               free_widget_value(copy);        
+       }
        return node;
 }
 
@@ -447,8 +450,7 @@ lw_map_widget_values(LWLIB_ID id, int (*mapfunc) (widget_value * value,
 
        if (!info)
                abort();
-
-       if (info->val)
+       else if (info->val)
                return map_widget_values(info->val, mapfunc, closure);
        return 0;
 }