[file-roller/wip/jtojnar/clang-analysis: 12/12] dlg-update: Fix false null dereference warning




commit 8545455b819f7893826932f0cc5bcb655fd7c1a8
Author: Jan Tojnar <jtojnar gmail com>
Date:   Mon Sep 5 20:10:08 2022 +0200

    dlg-update: Fix false null dereference warning
    
    Clang’s scan-build tool complains:
    
        ../../../src/dlg-update.c:152:20: warning: Access to field 'data' results in a dereference of a null 
pointer (loaded from field 'file_list') [core.NullDereference]
                        OpenFile *file = data->file_list->data;
                                         ^~~~~~~~~~~~~~~~~~~~~
    
    But if `file_list` was NULL, the g_list_length would return 0 and so the `n_files == 1` branch would not 
be entered.

 src/dlg-update.c | 19 +++++++++----------
 1 file changed, 9 insertions(+), 10 deletions(-)
---
diff --git a/src/dlg-update.c b/src/dlg-update.c
index 05527950..63887301 100644
--- a/src/dlg-update.c
+++ b/src/dlg-update.c
@@ -123,6 +123,15 @@ update_file_list (DialogData *data)
        GList       *scan;
        GtkTreeIter  iter;
 
+       /*gtk_window_set_modal (GTK_WINDOW (data->update_files_dialog), FALSE);*/
+       gtk_widget_hide (data->update_files_dialog);
+       /*gtk_window_set_modal (GTK_WINDOW (data->update_file_dialog), FALSE);*/
+       gtk_widget_hide (data->update_file_dialog);
+
+       if (data->file_list == NULL) {
+               return;
+       }
+
        n_files = g_list_length (data->file_list);
 
        /* update the file list */
@@ -208,23 +217,13 @@ update_file_list (DialogData *data)
        /* show the appropriate dialog */
 
        if (n_files == 1) {
-               /*gtk_window_set_modal (GTK_WINDOW (data->update_files_dialog), FALSE);*/
-               gtk_widget_hide (data->update_files_dialog);
                /*gtk_window_set_modal (GTK_WINDOW (data->update_file_dialog), TRUE);*/
                gtk_widget_show (data->update_file_dialog);
        }
        else if (n_files > 1) {
-               /*gtk_window_set_modal (GTK_WINDOW (data->update_file_dialog), FALSE);*/
-               gtk_widget_hide (data->update_file_dialog);
                /*gtk_window_set_modal (GTK_WINDOW (data->update_files_dialog), TRUE);*/
                gtk_widget_show (data->update_files_dialog);
        }
-       else { /* n_files == 0 */
-               /*gtk_window_set_modal (GTK_WINDOW (data->update_files_dialog), FALSE);*/
-               gtk_widget_hide (data->update_files_dialog);
-               /*gtk_window_set_modal (GTK_WINDOW (data->update_file_dialog), FALSE);*/
-               gtk_widget_hide (data->update_file_dialog);
-       }
 }
 
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]