Ticket #3955: mc-3955-dialog.c-cleanup-null-dereference-warning.patch

File mc-3955-dialog.c-cleanup-null-dereference-warning.patch, 1.6 KB (added by and, 5 years ago)
  • lib/widget/dialog.c

    From e4b64e4c07d5e87d6ee06f3b821860b6175d8655 Mon Sep 17 00:00:00 2001
    From: Andreas Mohr <and@gmx.li>
    Date: Fri, 11 Jan 2019 15:37:25 +0000
    Subject: [PATCH] dialog.c: cleanup -Wnull-dereference warning
    
    Found by GCC8
    
    dialog.c:136:17: error: 'w' may be used uninitialized in this function [-Werror=maybe-uninitialized]
             while ((widget_get_state (w, WST_DISABLED) || !widget_get_options (w, WOP_SELECTABLE))
                     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    dialog.c:134:15: error: null pointer dereference [-Werror=null-dereference]
                 w = WIDGET (l->data);
    
    dialog.c:139:25: error: potential null pointer dereference [-Werror=null-dereference]
             widget_select (l->data);
                            ~^~~~~~
    
    Signed-off-by: Andreas Mohr <and@gmx.li>
    ---
     lib/widget/dialog.c | 9 +++++----
     1 file changed, 5 insertions(+), 4 deletions(-)
    
    diff --git a/lib/widget/dialog.c b/lib/widget/dialog.c
    index cddd27a0e..45b177c93 100644
    a b dlg_select_next_or_prev (WDialog * h, gboolean next) 
    126126    if (h->widgets != NULL && h->current != NULL) 
    127127    { 
    128128        GList *l = h->current; 
    129         Widget *w; 
     129        Widget *w = NULL; 
    130130 
    131131        do 
    132132        { 
    133             l = dlg_get_next_or_prev_of (l, next); 
    134             w = WIDGET (l->data); 
     133            if ((l = dlg_get_next_or_prev_of (l, next)) != NULL) 
     134                w = WIDGET (l->data); 
    135135        } 
    136136        while ((widget_get_state (w, WST_DISABLED) || !widget_get_options (w, WOP_SELECTABLE)) 
    137137               && l != h->current); 
    138138 
    139         widget_select (l->data); 
     139        if (l != NULL) 
     140            widget_select (l->data); 
    140141    } 
    141142} 
    142143