[PATCH 1/3] gdbstub: prevent uninitialized warning

Chen Qun posted 3 patches 8 weeks ago
Maintainers: "Daniel P. Berrangé" <berrange@redhat.com>, "Gonglei (Arei)" <arei.gonglei@huawei.com>, "Philippe Mathieu-Daudé" <philmd@redhat.com>, "Michael S. Tsirkin" <mst@redhat.com>, "Alex Bennée" <alex.bennee@linaro.org>

[PATCH 1/3] gdbstub: prevent uninitialized warning

Posted by Chen Qun 8 weeks ago
According to the glib function requirements, we need initialise
     the variable. Otherwise there will be compilation warnings:

qemu/gdbstub.c: In function ‘handle_query_thread_extra’:
/usr/include/glib-2.0/glib/glib-autocleanups.h:28:3: warning:
 ‘cpu_name’ may be used uninitialized in this function [-Wmaybe-uninitialized]
   g_free (*pp);
   ^~~~~~~~~~~~

Reported-by: Euler Robot <euler.robot@huawei.com>
Signed-off-by: Chen Qun <kuhn.chenqun@huawei.com>
---
Cc: "Alex Bennée" <alex.bennee@linaro.org>
Cc: "Philippe Mathieu-Daudé" <philmd@redhat.com>
---
 gdbstub.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/gdbstub.c b/gdbstub.c
index 013fb1ac0f..171e150950 100644
--- a/gdbstub.c
+++ b/gdbstub.c
@@ -2060,8 +2060,8 @@ static void handle_query_thread_extra(GdbCmdContext *gdb_ctx, void *user_ctx)
         /* Print the CPU model and name in multiprocess mode */
         ObjectClass *oc = object_get_class(OBJECT(cpu));
         const char *cpu_model = object_class_get_name(oc);
-        g_autofree char *cpu_name;
-        cpu_name  = object_get_canonical_path_component(OBJECT(cpu));
+        g_autofree char *cpu_name =
+            object_get_canonical_path_component(OBJECT(cpu));
         g_string_printf(rs, "%s %s [%s]", cpu_model, cpu_name,
                         cpu->halted ? "halted " : "running");
     } else {
-- 
2.23.0



Re: [PATCH 1/3] gdbstub: prevent uninitialized warning

Posted by Alex Bennée 8 weeks ago
Chen Qun <kuhn.chenqun@huawei.com> writes:

> According to the glib function requirements, we need initialise
>      the variable. Otherwise there will be compilation warnings:
>
> qemu/gdbstub.c: In function ‘handle_query_thread_extra’:
> /usr/include/glib-2.0/glib/glib-autocleanups.h:28:3: warning:
>  ‘cpu_name’ may be used uninitialized in this function [-Wmaybe-uninitialized]
>    g_free (*pp);
>    ^~~~~~~~~~~~
>
> Reported-by: Euler Robot <euler.robot@huawei.com>
> Signed-off-by: Chen Qun <kuhn.chenqun@huawei.com>

Thanks,

I've pulled in a duplicate fix from:

  Message-Id: <20200326151407.25046-1-dplotnikov@virtuozzo.com>

and added your Reported-by's

> ---
> Cc: "Alex Bennée" <alex.bennee@linaro.org>
> Cc: "Philippe Mathieu-Daudé" <philmd@redhat.com>
> ---
>  gdbstub.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/gdbstub.c b/gdbstub.c
> index 013fb1ac0f..171e150950 100644
> --- a/gdbstub.c
> +++ b/gdbstub.c
> @@ -2060,8 +2060,8 @@ static void handle_query_thread_extra(GdbCmdContext *gdb_ctx, void *user_ctx)
>          /* Print the CPU model and name in multiprocess mode */
>          ObjectClass *oc = object_get_class(OBJECT(cpu));
>          const char *cpu_model = object_class_get_name(oc);
> -        g_autofree char *cpu_name;
> -        cpu_name  = object_get_canonical_path_component(OBJECT(cpu));
> +        g_autofree char *cpu_name =
> +            object_get_canonical_path_component(OBJECT(cpu));
>          g_string_printf(rs, "%s %s [%s]", cpu_model, cpu_name,
>                          cpu->halted ? "halted " : "running");
>      } else {


-- 
Alex Bennée

RE: [PATCH 1/3] gdbstub: prevent uninitialized warning

Posted by Chenqun (kuhn) 8 weeks ago
>-----Original Message-----
>From: Alex Bennée [mailto:alex.bennee@linaro.org]
>Sent: Friday, March 27, 2020 5:13 PM
>To: Chenqun (kuhn) <kuhn.chenqun@huawei.com>
>Cc: qemu-devel@nongnu.org; qemu-trivial@nongnu.org; Zhanghailiang
><zhang.zhanghailiang@huawei.com>; laurent@vivier.eu; Euler Robot
><euler.robot@huawei.com>; Philippe Mathieu-Daudé <philmd@redhat.com>
>Subject: Re: [PATCH 1/3] gdbstub: prevent uninitialized warning
>
>
>Chen Qun <kuhn.chenqun@huawei.com> writes:
>
>> According to the glib function requirements, we need initialise
>>      the variable. Otherwise there will be compilation warnings:
>>
>> qemu/gdbstub.c: In function ‘handle_query_thread_extra’:
>> /usr/include/glib-2.0/glib/glib-autocleanups.h:28:3: warning:
>>  ‘cpu_name’ may be used uninitialized in this function [-Wmaybe-uninitialized]
>>    g_free (*pp);
>>    ^~~~~~~~~~~~
>>
>> Reported-by: Euler Robot <euler.robot@huawei.com>
>> Signed-off-by: Chen Qun <kuhn.chenqun@huawei.com>
>
>Thanks,
>
>I've pulled in a duplicate fix from:
>
>  Message-Id: <20200326151407.25046-1-dplotnikov@virtuozzo.com>
>
>and added your Reported-by's

OK,  If possible, bring Miroslav Rezanina's  "Reviewed-by" tag.

https://lists.gnu.org/archive/html/qemu-devel/2020-03/msg07651.html

Thanks.
>
>> ---
>> Cc: "Alex Bennée" <alex.bennee@linaro.org>
>> Cc: "Philippe Mathieu-Daudé" <philmd@redhat.com>
>> ---
>>  gdbstub.c | 4 ++--
>>  1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/gdbstub.c b/gdbstub.c
>> index 013fb1ac0f..171e150950 100644
>> --- a/gdbstub.c
>> +++ b/gdbstub.c
>> @@ -2060,8 +2060,8 @@ static void
>handle_query_thread_extra(GdbCmdContext *gdb_ctx, void *user_ctx)
>>          /* Print the CPU model and name in multiprocess mode */
>>          ObjectClass *oc = object_get_class(OBJECT(cpu));
>>          const char *cpu_model = object_class_get_name(oc);
>> -        g_autofree char *cpu_name;
>> -        cpu_name  = object_get_canonical_path_component(OBJECT(cpu));
>> +        g_autofree char *cpu_name =
>> +            object_get_canonical_path_component(OBJECT(cpu));
>>          g_string_printf(rs, "%s %s [%s]", cpu_model, cpu_name,
>>                          cpu->halted ? "halted " : "running");
>>      } else {
>
>
>--
>Alex Bennée

Re: [PATCH 1/3] gdbstub: prevent uninitialized warning

Posted by Miroslav Rezanina 8 weeks ago
On Wed, Mar 25, 2020 at 05:21:35PM +0800, Chen Qun wrote:
> According to the glib function requirements, we need initialise
>      the variable. Otherwise there will be compilation warnings:
> 
> qemu/gdbstub.c: In function ‘handle_query_thread_extra’:
> /usr/include/glib-2.0/glib/glib-autocleanups.h:28:3: warning:
>  ‘cpu_name’ may be used uninitialized in this function [-Wmaybe-uninitialized]
>    g_free (*pp);
>    ^~~~~~~~~~~~
> 
> Reported-by: Euler Robot <euler.robot@huawei.com>
> Signed-off-by: Chen Qun <kuhn.chenqun@huawei.com>
> ---
> Cc: "Alex Bennée" <alex.bennee@linaro.org>
> Cc: "Philippe Mathieu-Daudé" <philmd@redhat.com>
> ---
>  gdbstub.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/gdbstub.c b/gdbstub.c
> index 013fb1ac0f..171e150950 100644
> --- a/gdbstub.c
> +++ b/gdbstub.c
> @@ -2060,8 +2060,8 @@ static void handle_query_thread_extra(GdbCmdContext *gdb_ctx, void *user_ctx)
>          /* Print the CPU model and name in multiprocess mode */
>          ObjectClass *oc = object_get_class(OBJECT(cpu));
>          const char *cpu_model = object_class_get_name(oc);
> -        g_autofree char *cpu_name;
> -        cpu_name  = object_get_canonical_path_component(OBJECT(cpu));
> +        g_autofree char *cpu_name =
> +            object_get_canonical_path_component(OBJECT(cpu));
>          g_string_printf(rs, "%s %s [%s]", cpu_model, cpu_name,
>                          cpu->halted ? "halted " : "running");
>      } else {
> -- 
> 2.23.0
> 
> 
>

Fixing broken build with -Wall.

Reviewed-by: Miroslav Rezanina <mrezanin@redhat.com>