[file-roller/wip/jtojnar/clang-analysis: 10/12] application: Fix possible null pointer dereference




commit dd1fe0e1a06d7d04896b8b0f3e216f3b297ff488
Author: Jan Tojnar <jtojnar gmail com>
Date:   Sat Sep 3 23:45:41 2022 +0200

    application: Fix possible null pointer dereference
    
    Discovered with Clang’s scan-build tool:
    
        ../../../src/fr-application.c:273:37: warning: Access to field 'data' results in a dereference of a 
null pointer (loaded from variable 'file_list') [core.NullDereference]
                                destination = g_file_get_parent (G_FILE (file_list->data));
                                                                 ^~~~~~~~~~~~~~~~~~~~~~~~
    
    Would occur when empty destination URI was passed to Compress D-Bus method.
    
    Introduced in https://gitlab.gnome.org/GNOME/file-roller/-/commit/34b64f3a897c4b4e8e180c028f326bc921eb08ec

 src/fr-application.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
---
diff --git a/src/fr-application.c b/src/fr-application.c
index a0097b9c..33227d0b 100644
--- a/src/fr-application.c
+++ b/src/fr-application.c
@@ -262,20 +262,22 @@ handle_method_call (GDBusConnection       *connection,
                gboolean    use_progress_dialog;
                int         i;
                GList      *file_list = NULL;
-               GFile      *destination;
+               GFile      *destination = NULL;
                GtkWidget  *window;
 
                g_variant_get (parameters, "(^assb)", &files, &destination_uri, &use_progress_dialog);
 
                if ((destination_uri != NULL) && (strcmp (destination_uri, "") != 0))
                        destination = g_file_new_for_uri (destination_uri);
-               else
-                       destination = g_file_get_parent (G_FILE (file_list->data));
 
                for (i = 0; files[i] != NULL; i++)
                        file_list = g_list_prepend (file_list, g_file_new_for_uri (files[i]));
                file_list = g_list_reverse (file_list);
 
+               if (destination == NULL && file_list != NULL) {
+                       destination = g_file_get_parent (G_FILE (file_list->data));
+               }
+
                window = fr_window_new ();
                fr_window_use_progress_dialog (FR_WINDOW (window), use_progress_dialog);
                fr_window_set_default_dir (FR_WINDOW (window), destination, TRUE);


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