diff mbox series

[v3,12/19] tests/plugin: prevent uninitialized warning

Message ID 20200225124710.14152-13-alex.bennee@linaro.org
State New
Headers show
Series testing & plugin updates | expand

Commit Message

Alex Bennée Feb. 25, 2020, 12:47 p.m. UTC
From: Chen Qun <kuhn.chenqun@huawei.com>

According to the glibc function requirements, we need initialise
 the variable. Otherwise there will be compilation warnings:

glib-autocleanups.h:28:3: warning: ‘out’ 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>
Reviewed-by: Thomas Huth <thuth@redhat.com>
Message-Id: <20200206093238.203984-1-kuhn.chenqun@huawei.com>
[AJB: uses Thomas's single line allocation]
Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
---
 tests/plugin/bb.c   | 6 +++---
 tests/plugin/insn.c | 3 +--
 2 files changed, 4 insertions(+), 5 deletions(-)

Comments

Philippe Mathieu-Daudé Feb. 26, 2020, 1:59 p.m. UTC | #1
On 2/25/20 1:47 PM, Alex Bennée wrote:
> From: Chen Qun <kuhn.chenqun@huawei.com>
> 
> According to the glibc function requirements, we need initialise

GLib?

>   the variable. Otherwise there will be compilation warnings:
> 
> glib-autocleanups.h:28:3: warning: ‘out’ 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>
> Reviewed-by: Thomas Huth <thuth@redhat.com>
> Message-Id: <20200206093238.203984-1-kuhn.chenqun@huawei.com>
> [AJB: uses Thomas's single line allocation]
> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
> Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
> ---
>   tests/plugin/bb.c   | 6 +++---
>   tests/plugin/insn.c | 3 +--
>   2 files changed, 4 insertions(+), 5 deletions(-)
> 
> diff --git a/tests/plugin/bb.c b/tests/plugin/bb.c
> index f30bea08dcc..df19fd359df 100644
> --- a/tests/plugin/bb.c
> +++ b/tests/plugin/bb.c
> @@ -22,9 +22,9 @@ static bool do_inline;
>   
>   static void plugin_exit(qemu_plugin_id_t id, void *p)
>   {
> -    g_autofree gchar *out;
> -    out = g_strdup_printf("bb's: %" PRIu64", insns: %" PRIu64 "\n",
> -                          bb_count, insn_count);
> +    g_autofree gchar *out = g_strdup_printf(
> +        "bb's: %" PRIu64", insns: %" PRIu64 "\n",
> +        bb_count, insn_count);
>       qemu_plugin_outs(out);
>   }
>   
> diff --git a/tests/plugin/insn.c b/tests/plugin/insn.c
> index 0a8f5a0000e..a9a6e412373 100644
> --- a/tests/plugin/insn.c
> +++ b/tests/plugin/insn.c
> @@ -44,8 +44,7 @@ static void vcpu_tb_trans(qemu_plugin_id_t id, struct qemu_plugin_tb *tb)
>   
>   static void plugin_exit(qemu_plugin_id_t id, void *p)
>   {
> -    g_autofree gchar *out;
> -    out = g_strdup_printf("insns: %" PRIu64 "\n", insn_count);
> +    g_autofree gchar *out = g_strdup_printf("insns: %" PRIu64 "\n", insn_count);
>       qemu_plugin_outs(out);
>   }
>   
>
Chen Qun Feb. 27, 2020, 7:01 a.m. UTC | #2
>-----Original Message-----
>From: Philippe Mathieu-Daudé [mailto:philmd@redhat.com]
>Sent: Wednesday, February 26, 2020 10:00 PM
>To: Alex Bennée <alex.bennee@linaro.org>; qemu-devel@nongnu.org
>Cc: fam@euphon.net; Thomas Huth <thuth@redhat.com>;
>berrange@redhat.com; robert.foley@linaro.org; pbonzini@redhat.com;
>stefanb@linux.vnet.ibm.com; Euler Robot <euler.robot@huawei.com>;
>richard.henderson@linaro.org; f4bug@amsat.org; robhenry@microsoft.com;
>marcandre.lureau@redhat.com; aaron@os.amperecomputing.com;
>cota@braap.org; stefanha@redhat.com; Chenqun (kuhn)
><kuhn.chenqun@huawei.com>; peter.puhov@linaro.org;
>aurelien@aurel32.net
>Subject: Re: [PATCH v3 12/19] tests/plugin: prevent uninitialized warning
>
>On 2/25/20 1:47 PM, Alex Bennée wrote:
>> From: Chen Qun <kuhn.chenqun@huawei.com>
>>
>> According to the glibc function requirements, we need initialise
>
>GLib?
Yes, Glib function requirements.
https://developer.gnome.org/glib/stable/glib-Miscellaneous-Macros.html#g-autofree

Thanks.
>
>>   the variable. Otherwise there will be compilation warnings:
>>
>> glib-autocleanups.h:28:3: warning: ‘out’ 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>
>> Reviewed-by: Thomas Huth <thuth@redhat.com>
>> Message-Id: <20200206093238.203984-1-kuhn.chenqun@huawei.com>
>> [AJB: uses Thomas's single line allocation]
>> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
>> Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
>> ---
>>   tests/plugin/bb.c   | 6 +++---
>>   tests/plugin/insn.c | 3 +--
>>   2 files changed, 4 insertions(+), 5 deletions(-)
>>
>> diff --git a/tests/plugin/bb.c b/tests/plugin/bb.c index
>> f30bea08dcc..df19fd359df 100644
>> --- a/tests/plugin/bb.c
>> +++ b/tests/plugin/bb.c
>> @@ -22,9 +22,9 @@ static bool do_inline;
>>
>>   static void plugin_exit(qemu_plugin_id_t id, void *p)
>>   {
>> -    g_autofree gchar *out;
>> -    out = g_strdup_printf("bb's: %" PRIu64", insns: %" PRIu64 "\n",
>> -                          bb_count, insn_count);
>> +    g_autofree gchar *out = g_strdup_printf(
>> +        "bb's: %" PRIu64", insns: %" PRIu64 "\n",
>> +        bb_count, insn_count);
>>       qemu_plugin_outs(out);
>>   }
>>
>> diff --git a/tests/plugin/insn.c b/tests/plugin/insn.c index
>> 0a8f5a0000e..a9a6e412373 100644
>> --- a/tests/plugin/insn.c
>> +++ b/tests/plugin/insn.c
>> @@ -44,8 +44,7 @@ static void vcpu_tb_trans(qemu_plugin_id_t id,
>> struct qemu_plugin_tb *tb)
>>
>>   static void plugin_exit(qemu_plugin_id_t id, void *p)
>>   {
>> -    g_autofree gchar *out;
>> -    out = g_strdup_printf("insns: %" PRIu64 "\n", insn_count);
>> +    g_autofree gchar *out = g_strdup_printf("insns: %" PRIu64 "\n",
>> + insn_count);
>>       qemu_plugin_outs(out);
>>   }
>>
>>
diff mbox series

Patch

diff --git a/tests/plugin/bb.c b/tests/plugin/bb.c
index f30bea08dcc..df19fd359df 100644
--- a/tests/plugin/bb.c
+++ b/tests/plugin/bb.c
@@ -22,9 +22,9 @@  static bool do_inline;
 
 static void plugin_exit(qemu_plugin_id_t id, void *p)
 {
-    g_autofree gchar *out;
-    out = g_strdup_printf("bb's: %" PRIu64", insns: %" PRIu64 "\n",
-                          bb_count, insn_count);
+    g_autofree gchar *out = g_strdup_printf(
+        "bb's: %" PRIu64", insns: %" PRIu64 "\n",
+        bb_count, insn_count);
     qemu_plugin_outs(out);
 }
 
diff --git a/tests/plugin/insn.c b/tests/plugin/insn.c
index 0a8f5a0000e..a9a6e412373 100644
--- a/tests/plugin/insn.c
+++ b/tests/plugin/insn.c
@@ -44,8 +44,7 @@  static void vcpu_tb_trans(qemu_plugin_id_t id, struct qemu_plugin_tb *tb)
 
 static void plugin_exit(qemu_plugin_id_t id, void *p)
 {
-    g_autofree gchar *out;
-    out = g_strdup_printf("insns: %" PRIu64 "\n", insn_count);
+    g_autofree gchar *out = g_strdup_printf("insns: %" PRIu64 "\n", insn_count);
     qemu_plugin_outs(out);
 }