]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
hashmap: avoid uninitialized variable warning in internal_hashmap_clear()
authorThomas Haller <thaller@redhat.com>
Sun, 3 Feb 2019 11:56:24 +0000 (12:56 +0100)
committerThomas Haller <thaller@redhat.com>
Mon, 4 Feb 2019 08:36:08 +0000 (09:36 +0100)
GCC 8.2 with LTO and -O2 emits a false warning:

    src/basic/hashmap.c: In function 'internal_hashmap_free.constprop':
    src/basic/hashmap.c:898:33: error: 'k' may be used uninitialized in this function [-Werror=maybe-uninitialized]
                      free_key(k);
                      ^

Avoid it by initializing the variable.

src/basic/hashmap.c

index f2e33d22656389459f669d2015ef77ca351182e1..80fec8fb53549051cb800d83ab850cf5ffe90d00 100644 (file)
@@ -888,7 +888,8 @@ void internal_hashmap_clear(HashmapBase *h, free_func_t default_free_key, free_f
                  * themselves from our hash table a second time, the entry is already gone. */
 
                 while (internal_hashmap_size(h) > 0) {
-                        void *v, *k;
+                        void *k = NULL;
+                        void *v;
 
                         v = internal_hashmap_first_key_and_value(h, true, &k);