This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [PATCH] Fix uninitialized use of variables.
- From: Carlos O'Donell <carlos at codesourcery dot com>
- To: Jim Blandy <jimb at codesourcery dot com>
- Cc: gdb-patches at sourceware dot org, Daniel Jacobowitz <dan at codesourcery dot com>
- Date: Wed, 24 Oct 2007 13:15:45 -0400
- Subject: Re: [PATCH] Fix uninitialized use of variables.
- References: <20071020172137.GC28823@lios> <m3wstdo1yu.fsf@codesourcery.com>
On Tue, Oct 23, 2007 at 04:17:29PM -0700, Jim Blandy wrote:
>
> Carlos O'Donell <carlos at codesourcery.com> writes:
> > In symtab.c (find_line_common) the variable *exact_match is not set if
> > no match is found. Callers of find_line_common expect *exact_match to be
> > set. The solution is to initialize *exact_match to zero, assuming an
> > inexact match. In the case that we don't find a match in
> > find_line_common, the statement `(best_index < 0 || !exact)' in
> > symtab.c:2267 is true, instead of undefined. The comment is adjusted to
> > indicate that one must look at another symtab if we failed to find a
> > match `best_index < 0' or we found an inexact match `!exact.'
>
> As far as the symtab.c change is concerned: the specification of
> find_line_common is that *EXACT_MATCH is set only if the function
> returns a match (a non-negative value). As far as I can see,
> find_line_symtab doesn't actually use the value of 'exact' unless the
> corresponding call to find_line_common returned a match. So the
> warning looks spurious to me.
>
> (I don't mind initializing 'exact' in find_line_symtab to placate the
> compiler.)
Sorry, yes, the boolean short circuit avoids the evaluation of !exact.
The compiler probably can't see that though and warns that it *may* be
an uninitialized use of the variable.
I'll whip up a patch that initializes exact in find_line_symtab.
Thanks for the review.
Cheers,
Carlos.
--
Carlos O'Donell
CodeSourcery
carlos@codesourcery.com
(650) 331-3385 x716