Re: [spice-server] stat: Silence gcc warning

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

 



> 
> On 01/20/2017 05:30 PM, Christophe Fergeau wrote:
> > Initializing 'node' to NULL silences this warning:
> >
> > stat-file.c: In function 'stat_file_add_node':
> > stat-file.c:180:15: error: 'node' may be used uninitialized in this
> > function [-Werror=maybe-uninitialized]
> >      g_strlcpy(node->name, name, sizeof(node->name));
> >                ^~~~
> > cc1: all warnings being treated as errors
> 
> Hi Christophe,
> 
> Looks good to me.
> 

it's actually a false positive, from 

    for (ref = 0; ref <= stat_file->max_nodes; ref++) {
        node = &stat_file->stat->nodes[ref];

node is always initialized as ref and max_nodes are unsigned so
at the beginning ref == 0 and start_file->max_nodes >= 0 so
ref <= 0 <= start_file->max_nodes and node is initialized.

> Some comments:
> 1. It would be nice to (unlock and) return if node == NULL below.

as said node cannot be NULL and by the way if it was NULL node->value
would crash so return is not reached.

> 2. (In the area) the check for  (stat_file->stat == NULL) should
>     be before the while

agreed, I would put 

    if (stat_file->stat == NULL || strlen(name) >= sizeof(node->name)) {
        return INVALID_STAT_REF;
    }   

stat_file->stat is used just after the lock.

> 3. For some reason the build does not fail for me (again :-()
> 
> If you want I can send patch(es) for 1 and 2
> 
> Thanks,
>      Uri.
> 

Frediano

> 
> > ---
> >  server/stat-file.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/server/stat-file.c b/server/stat-file.c
> > index c23f4f5..de455b6 100644
> > --- a/server/stat-file.c
> > +++ b/server/stat-file.c
> > @@ -144,7 +144,7 @@ StatNodeRef
> >  stat_file_add_node(RedStatFile *stat_file, StatNodeRef parent, const char
> >  *name, int visible)
> >  {
> >      StatNodeRef ref;
> > -    SpiceStatNode *node;
> > +    SpiceStatNode *node = NULL;
> >
> >      spice_assert(name && strlen(name) > 0);
> >      if (strlen(name) >= sizeof(node->name)) {
> >

_______________________________________________
Spice-devel mailing list
Spice-devel@xxxxxxxxxxxxxxxxxxxxx
https://lists.freedesktop.org/mailman/listinfo/spice-devel




[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]     [Monitors]