qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: [PATCH-for-5.2? 1/2] tests/qtest: variable defined by g_autofree nee


From: Chenqun (kuhn)
Subject: RE: [PATCH-for-5.2? 1/2] tests/qtest: variable defined by g_autofree need to be initialized
Date: Thu, 19 Nov 2020 08:35:20 +0000

> -----Original Message-----
> From: Peter Maydell [mailto:peter.maydell@linaro.org]
> Sent: Thursday, November 19, 2020 4:26 PM
> To: Chenqun (kuhn) <kuhn.chenqun@huawei.com>
> Cc: QEMU Developers <qemu-devel@nongnu.org>; QEMU Trivial
> <qemu-trivial@nongnu.org>; Hao Wu <wuhaotsh@google.com>; Havard
> Skinnemoen <hskinnemoen@google.com>; Zhanghailiang
> <zhang.zhanghailiang@huawei.com>; Thomas Huth <thuth@redhat.com>;
> Laurent Vivier <lvivier@redhat.com>; Euler Robot <euler.robot@huawei.com>
> Subject: Re: [PATCH-for-5.2? 1/2] tests/qtest: variable defined by g_autofree
> need to be initialized
> 
> On Wed, 18 Nov 2020 at 11:57, Chen Qun <kuhn.chenqun@huawei.com>
> 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);
> >       |   ^~~~~~~~~~~~
> >
> >  static void tim_add_test(const char *name, const TestData *td,
> > GTestDataFunc fn)  {
> > -    g_autofree char *full_name;
> > -
> > -    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);
> 
> Which compiler is so unintelligent that it cannot see that a declaration
> immediately followed by an assignment must always initialize the variable ???
> 
Hi Peter,
  Glib requires that all g_auto* macros must be initialized.
  
https://developer.gnome.org/glib/stable/glib-Miscellaneous-Macros.html#g-autofree

Thanks,
Chen Qun



reply via email to

[Prev in Thread] Current Thread [Next in Thread]