> -----Original Message-----
> From: Philippe Mathieu-Daudé [mailto:phi...@redhat.com]
> Sent: Wednesday, November 18, 2020 8:14 PM
> To: Chenqun (kuhn) <kuhn.chen...@huawei.com>; qemu-devel@nongnu.org;
> qemu-triv...@nongnu.org
> Cc: lviv...@redhat.com; peter.mayd...@linaro.org; th...@redhat.com;
> Zhanghailiang <zhang.zhanghaili...@huawei.com>;
> hskinnem...@google.com; wuhao...@google.com; Euler Robot
> <euler.ro...@huawei.com>
> Subject: Re: [PATCH-for-5.2? 1/2] tests/qtest: variable defined by g_autofree
> need to be initialized
> 
> On 11/18/20 12:56 PM, Chen Qun wrote:
> > According to the glib function requirements, we need initialise  the
> > variable. Otherwise there will be compilation warnings:
> >
> > glib-autocleanups.h:28:3: warning: ‘full_name’ may be used
> > uninitialized in this function [-Wmaybe-uninitialized]
> >    28 |   g_free (*pp);
> >       |   ^~~~~~~~~~~~
> >
> > Reported-by: Euler Robot <euler.ro...@huawei.com>
> > Signed-off-by: Chen Qun <kuhn.chen...@huawei.com>
> > ---
> >  tests/qtest/npcm7xx_timer-test.c | 8 +++-----
> >  1 file changed, 3 insertions(+), 5 deletions(-)
> >
> > diff --git a/tests/qtest/npcm7xx_timer-test.c
> > b/tests/qtest/npcm7xx_timer-test.c
> > index f08b0cd62a..83774a5b90 100644
> > --- a/tests/qtest/npcm7xx_timer-test.c
> > +++ b/tests/qtest/npcm7xx_timer-test.c
> > @@ -512,11 +512,9 @@ static void
> test_disable_on_expiration(gconstpointer test_data)
> >   */
> >  static void tim_add_test(const char *name, const TestData *td,
> > GTestDataFunc fn)  {
> 
> Or:
> 
> > -    g_autofree char *full_name;
>   +    g_autofree char *full_name = NULL;
> 
Yes, this also meets the glib requirements.
But, the assignment statement following is not complex, so we could do both of 
variable definition and assignment in a statement.

Thanks,
Chen Qun
> > -
> > -    full_name = g_strdup_printf("npcm7xx_timer/tim[%d]/timer[%d]/%s",
> > -                                tim_index(td->tim),
> timer_index(td->timer),
> > -                                name);
> > +    g_autofree char *full_name = g_strdup_printf(
> > +        "npcm7xx_timer/tim[%d]/timer[%d]/%s", tim_index(td->tim),
> > +        timer_index(td->timer), name);
> >      qtest_add_data_func(full_name, td, fn);  }
> >
> >

Reply via email to