* [PATCH] softmmu/device_tree: Silence compiler warning with --enable-sanitizers
@ 2022-01-07 13:38 Thomas Huth
2022-01-07 14:45 ` Andrew Jones
` (5 more replies)
0 siblings, 6 replies; 8+ messages in thread
From: Thomas Huth @ 2022-01-07 13:38 UTC (permalink / raw)
To: qemu-devel, Alistair Francis
Cc: Yanan Wang, qemu-trivial, Andrew Jones, David Gibson
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 <thuth@redhat.com>
---
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;
}
--
2.27.0
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH] softmmu/device_tree: Silence compiler warning with --enable-sanitizers
2022-01-07 13:38 [PATCH] softmmu/device_tree: Silence compiler warning with --enable-sanitizers Thomas Huth
@ 2022-01-07 14:45 ` Andrew Jones
2022-01-07 14:47 ` Philippe Mathieu-Daudé
` (4 subsequent siblings)
5 siblings, 0 replies; 8+ messages in thread
From: Andrew Jones @ 2022-01-07 14:45 UTC (permalink / raw)
To: Thomas Huth
Cc: Yanan Wang, qemu-trivial, Alistair Francis, qemu-devel, David Gibson
On Fri, Jan 07, 2022 at 02:38:44PM +0100, Thomas Huth wrote:
> 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 <thuth@redhat.com>
> ---
> 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;
> }
> --
> 2.27.0
>
Reviewed-by: Andrew Jones <drjones@redhat.com>
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] softmmu/device_tree: Silence compiler warning with --enable-sanitizers
2022-01-07 13:38 [PATCH] softmmu/device_tree: Silence compiler warning with --enable-sanitizers Thomas Huth
2022-01-07 14:45 ` Andrew Jones
@ 2022-01-07 14:47 ` Philippe Mathieu-Daudé
2022-01-07 20:18 ` Richard Henderson
` (3 subsequent siblings)
5 siblings, 0 replies; 8+ messages in thread
From: Philippe Mathieu-Daudé @ 2022-01-07 14:47 UTC (permalink / raw)
To: Thomas Huth, qemu-devel, Alistair Francis
Cc: Yanan Wang, qemu-trivial, Andrew Jones, David Gibson
On 7/1/22 14:38, Thomas Huth wrote:
> 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 <thuth@redhat.com>
> ---
> softmmu/device_tree.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] softmmu/device_tree: Silence compiler warning with --enable-sanitizers
2022-01-07 13:38 [PATCH] softmmu/device_tree: Silence compiler warning with --enable-sanitizers Thomas Huth
2022-01-07 14:45 ` Andrew Jones
2022-01-07 14:47 ` Philippe Mathieu-Daudé
@ 2022-01-07 20:18 ` Richard Henderson
2022-01-10 2:10 ` wangyanan (Y) via
2022-01-08 0:22 ` Alistair Francis
` (2 subsequent siblings)
5 siblings, 1 reply; 8+ messages in thread
From: Richard Henderson @ 2022-01-07 20:18 UTC (permalink / raw)
To: Thomas Huth, qemu-devel, Alistair Francis
Cc: Yanan Wang, qemu-trivial, Andrew Jones, David Gibson
On 1/7/22 5:38 AM, Thomas Huth wrote:
> 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);
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
In addition, the copy between 'path' and 'p' is unnecessary -- one of the variables should
be removed. Either rename the parameter to 'p', or rename all uses to 'path'.
r~
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] softmmu/device_tree: Silence compiler warning with --enable-sanitizers
2022-01-07 13:38 [PATCH] softmmu/device_tree: Silence compiler warning with --enable-sanitizers Thomas Huth
` (2 preceding siblings ...)
2022-01-07 20:18 ` Richard Henderson
@ 2022-01-08 0:22 ` Alistair Francis
2022-01-10 2:03 ` wangyanan (Y) via
2022-01-10 6:39 ` Alistair Francis
5 siblings, 0 replies; 8+ messages in thread
From: Alistair Francis @ 2022-01-08 0:22 UTC (permalink / raw)
To: Thomas Huth
Cc: Andrew Jones, QEMU Trivial, qemu-devel@nongnu.org Developers,
Yanan Wang, Alistair Francis, David Gibson
On Fri, Jan 7, 2022 at 11:41 PM Thomas Huth <thuth@redhat.com> wrote:
>
> 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 <thuth@redhat.com>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
Alistair
> ---
> 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;
> }
> --
> 2.27.0
>
>
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] softmmu/device_tree: Silence compiler warning with --enable-sanitizers
2022-01-07 13:38 [PATCH] softmmu/device_tree: Silence compiler warning with --enable-sanitizers Thomas Huth
` (3 preceding siblings ...)
2022-01-08 0:22 ` Alistair Francis
@ 2022-01-10 2:03 ` wangyanan (Y) via
2022-01-10 6:39 ` Alistair Francis
5 siblings, 0 replies; 8+ messages in thread
From: wangyanan (Y) via @ 2022-01-10 2:03 UTC (permalink / raw)
To: Thomas Huth, qemu-devel, Alistair Francis
Cc: Andrew Jones, David Gibson, qemu-trivial
On 2022/1/7 21:38, Thomas Huth wrote:
> 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 <thuth@redhat.com>
> ---
> softmmu/device_tree.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
Reviewed-by: Yanan Wang <wangyanan55@huawei.com>
> 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;
> }
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] softmmu/device_tree: Silence compiler warning with --enable-sanitizers
2022-01-07 20:18 ` Richard Henderson
@ 2022-01-10 2:10 ` wangyanan (Y) via
0 siblings, 0 replies; 8+ messages in thread
From: wangyanan (Y) via @ 2022-01-10 2:10 UTC (permalink / raw)
To: Richard Henderson, Thomas Huth
Cc: qemu-trivial, Andrew Jones, David Gibson, qemu-devel, Alistair Francis
On 2022/1/8 4:18, Richard Henderson wrote:
> On 1/7/22 5:38 AM, Thomas Huth wrote:
>> 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);
>
> Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
>
> In addition, the copy between 'path' and 'p' is unnecessary -- one of
> the variables should be removed. Either rename the parameter to 'p',
> or rename all uses to 'path'.
>
Yes. We can simply remove "const char *p = path;" and directly
using the parameter "path" passed in would be fine enough.
Thanks for catching this.
Thanks,
Yanan
>
> r~
> .
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] softmmu/device_tree: Silence compiler warning with --enable-sanitizers
2022-01-07 13:38 [PATCH] softmmu/device_tree: Silence compiler warning with --enable-sanitizers Thomas Huth
` (4 preceding siblings ...)
2022-01-10 2:03 ` wangyanan (Y) via
@ 2022-01-10 6:39 ` Alistair Francis
5 siblings, 0 replies; 8+ messages in thread
From: Alistair Francis @ 2022-01-10 6:39 UTC (permalink / raw)
To: Thomas Huth
Cc: Andrew Jones, QEMU Trivial, qemu-devel@nongnu.org Developers,
Yanan Wang, Alistair Francis, David Gibson
On Fri, Jan 7, 2022 at 11:41 PM Thomas Huth <thuth@redhat.com> wrote:
>
> 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 <thuth@redhat.com>
Thanks!
Applied to riscv-to-apply.next
If anyone else (trivial maybe?) wants to take this feel free to as
well, otherwise I'll just take this via the RISC-V tree.
Alistair
> ---
> 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;
> }
> --
> 2.27.0
>
>
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2022-01-10 6:56 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-07 13:38 [PATCH] softmmu/device_tree: Silence compiler warning with --enable-sanitizers Thomas Huth
2022-01-07 14:45 ` Andrew Jones
2022-01-07 14:47 ` Philippe Mathieu-Daudé
2022-01-07 20:18 ` Richard Henderson
2022-01-10 2:10 ` wangyanan (Y) via
2022-01-08 0:22 ` Alistair Francis
2022-01-10 2:03 ` wangyanan (Y) via
2022-01-10 6:39 ` Alistair Francis
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.