[augeas-devel] [PATCH v2] don't use variables uninitialized upon error

Dominic Cleal dcleal at redhat.com
Sat Dec 24 19:54:57 UTC 2011


On 23/12/11 22:32, Jim Meyering wrote:
> Jim Meyering wrote:
>> > Building with gcc-4.7.0..., I saw this:
>> >
>> >     transform.c: In function 'transform_load':
>> >     transform.c:697:5: warning: 'pathc' may be used uninitialized in
>> >       this function [-Wmaybe-uninitialized]
>> >
>> > That warning is legit, since the function looks like this:
>> >
>> >     ...
>> >     list_for_each(f, xfm->children) {
>> >         ...
>> >         if (r != 0 && r != GLOB_NOMATCH) {
>> >             ret = -1;
>> >             goto error;
>> >         }
>> >         gl_flags |= GLOB_APPEND;
>> >     }
>> >
>> >     ...
>> >
>> >     char **pathv = NULL;
>> >     int pathc = globbuf.gl_pathc, pathind = 0;
>> >
>> >     ...
>> >
>> >  error:
>> >     if (pathv != NULL)
>> >         for (int i=0; i < pathc; i++)
>> >             free(pathv[i]);
>> >     free(pathv);
>> >     ret = -1;
>> >     goto done;
>> > }
>> >
>> > So control can reach the uses of pathv and pathc without
>> > before they are initialized.
> Oops.
> That patch was not right.  It moved the use of globbuf up to before set.

Thanks for the patch Jim, applied.

Cheers,

-- 
Dominic Cleal
Red Hat Consulting
m: +44 (0)7817 878113




More information about the augeas-devel mailing list