This is the mail archive of the gdb-patches@sources.redhat.com mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: macrotab.c -Werror


On Mon, 13 May 2002, Andrew Cagney wrote:

> [second attempt at posting]
> 
> Jim,
> 
> FYI, I'm seeing:
> 
> gdb/macrotab.c:504: warning: `best_depth' might be used uninitialized in
> this function
> gmake: *** [macrotab.o] Error 1
> 
> for the code:
> 
>     /* It's not us.  Try all our children, and return the lowest.  */
>     {
>       struct macro_source_file *child;
>       struct macro_source_file *best = 0;
>       int best_depth;
> 
>       for (child = source->includes; child; child = child->next_included)
>         {
>           struct macro_source_file *result
>             = macro_lookup_inclusion (child, name);
> 
>           if (result)
>             {
>               int result_depth = inclusion_depth (result);
> 
>               if (! best || result_depth < best_depth) <-- HERE

It's an obvious false positive (!best will be true the first time through, 
meaning the only time we check best_depth, it's already been set at 
least once).

Here, you can't just initialize best_depth to 0, you have to initialize it 
to either INT_MAX, or inclusion_depth (result).

Sucks.
--Dan


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]