warning/error about possibly uninitialized 'exact' in find_line_symtab

Joel Brobecker brobecker@adacore.com
Mon Feb 23 04:07:00 GMT 2009


Jay,

> So maybe I'll go back to that.

For future contributes, I would appreciate if you did indeed send
patches applying to the HEAD.  Otherwise, it can just introduce
confusion.

As mentioned previously, please make sure to read gdb/CONTRIBUTE
to make sure that your contributions follow the proper procedure.

> Sure, now it may be unoptimally unnecessarily initialized but
> I don't think that is worth worrying about.

Agreed. And I can see how the compiler might think that this
variable might be used before being initialized (the value is
set during a call to a function that's passed a pointer to this
variable, so technically the function might not change its value).

> I use { 0 } instead of 0 because it is a more generic form that
> can zero initialize "anything", except some unions on some compilers,
> it might not always zero the entire thing.

That's right, but really in this case, we're initializing an int.
The day we change it to another type, we'll be careful to initialize
it properly... In the meantime, I checked in the attached patch, which
uses the simple integer initialization...

I mentioned copyright assignment in my previous email to you. We're
able to accept this contribution in this particular case, because
the change is very small and relatively obvious.  Besides, I changed
the implementation, so technically you only contributed ideas,
which are not copyrightable, but I decided to credit the change
to you nonetheless.

2009-02-23  Jay Krell  <jay.krell@cornell.edu>  (tiny change)

        * symtab.c (find_line_symtab): Initialize exact to avoid
        a compiler warning.

Tested on x86-linux. Checked in.

(thinking aloud - do we need a more descriptive comment about why
we initialize this variable here? I don't think it's necessary,
but let me know otherwise)

-- 
Joel
-------------- next part --------------
diff --git a/gdb/symtab.c b/gdb/symtab.c
index 1ef92a8..d51c7aa 100644
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -2361,7 +2361,7 @@ find_pc_line (CORE_ADDR pc, int notcurrent)
 struct symtab *
 find_line_symtab (struct symtab *symtab, int line, int *index, int *exact_match)
 {
-  int exact;
+  int exact = 0;  /* Initialized here to avoid a compiler warning.  */
 
   /* BEST_INDEX and BEST_LINETABLE identify the smallest linenumber > LINE
      so far seen.  */


More information about the Gdb-patches mailing list