[file-roller/wip/jtojnar/clang-analysis: 6/8] window: Fix false null dereference warning




commit 0653bcdde2be2c140687a3aeea76bcb0727c9116
Author: Jan Tojnar <jtojnar gmail com>
Date:   Sun Sep 4 00:12:20 2022 +0200

    window: Fix false null dereference warning
    
    Clang’s scan-build tool complains:
    
        ../../../src/fr-window.c:7320:10: warning: Access to field 'data' results in a dereference of a null 
pointer (loaded from field 'history_current') [core.NullDereference]
                        return private->history_current->data;
                               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    But we are already calling `fr_window_history_add` on the previous line,
    which updates the `history_current` with the new location.

 src/fr-window.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
---
diff --git a/src/fr-window.c b/src/fr-window.c
index 3d34ae21..54cf3952 100644
--- a/src/fr-window.c
+++ b/src/fr-window.c
@@ -7311,8 +7311,9 @@ fr_window_get_current_location (FrWindow *window)
 {
        FrWindowPrivate *private = fr_window_get_instance_private (window);
        if (private->history_current == NULL) {
-               fr_window_history_add (window, "/");
-               return private->history_current->data;
+               const char *path = "/";
+               fr_window_history_add (window, path);
+               return path;
        }
        else
                return (const char*) private->history_current->data;


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