Le 08/11/2021 à 21:07, Stefan Weil a écrit :
A build with gcc (Debian 10.2.1-6) 10.2.1 20210110 fails:

../../../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]
   560 |     int namelen, retval;
       |                  ^~~~~~

This is not a real error, but the compiler can be satisfied with a small change.

Fixes: b863f0b75852 ("device_tree: Add qemu_fdt_add_path")
Signed-off-by: Stefan Weil <s...@weilnetz.de>
---
  softmmu/device_tree.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/softmmu/device_tree.c b/softmmu/device_tree.c
index 3965c834ca..9e96f5ecd5 100644
--- a/softmmu/device_tree.c
+++ b/softmmu/device_tree.c
@@ -564,7 +564,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);
@@ -584,7 +584,7 @@ int qemu_fdt_add_path(void *fdt, const char *path)
          }
parent = retval;
-    }
+    } while (p);
return retval;
  }


I think to add a "g_assert_nonull(p);" before the loop would inform the compiler that we always go in the loop and remove the compiler error.

Thanks,
Laurent

Reply via email to