From: Thomas Huth Date: Fri, 7 Jan 2022 13:38:44 +0000 (+0100) Subject: softmmu/device_tree: Silence compiler warning with --enable-sanitizers X-Git-Tag: qemu-xen-4.17.0-rc4~123^2~44 X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=cfeeeb482a5279f240407a9d7266274c67c21d2e;p=qemu-xen.git softmmu/device_tree: Silence compiler warning with --enable-sanitizers If I configure my build with --enable-sanitizers, my GCC (v8.5.0) complains: .../softmmu/device_tree.c: In function ‘qemu_fdt_add_path’: .../softmmu/device_tree.c:560:18: error: ‘retval’ may be used uninitialized in this function [-Werror=maybe-uninitialized] int namelen, retval; ^~~~~~ It's a false warning since the while loop is always executed at least once (p has to be non-NULL, otherwise the derefence in the if-statement earlier will crash). Thus let's switch to a do-while loop here instead to make the compiler happy in all cases. Signed-off-by: Thomas Huth Reviewed-by: Andrew Jones Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Richard Henderson Reviewed-by: Alistair Francis Reviewed-by: Yanan Wang Message-id: 20220107133844.145039-1-thuth@redhat.com Signed-off-by: Alistair Francis --- diff --git a/softmmu/device_tree.c b/softmmu/device_tree.c index 31d1066940..0a433c98e2 100644 --- a/softmmu/device_tree.c +++ b/softmmu/device_tree.c @@ -566,7 +566,7 @@ int qemu_fdt_add_path(void *fdt, const char *path) return -1; } - while (p) { + do { name = p + 1; p = strchr(name, '/'); namelen = p != NULL ? p - name : strlen(name); @@ -586,7 +586,7 @@ int qemu_fdt_add_path(void *fdt, const char *path) } parent = retval; - } + } while (p); return retval; }