* warning/error about possibly uninitialized 'exact' in find_line_symtab
@ 2009-02-23 2:32 Jay
2009-02-23 4:07 ` Joel Brobecker
0 siblings, 1 reply; 3+ messages in thread
From: Jay @ 2009-02-23 2:32 UTC (permalink / raw)
To: gdb-patches
I didn't want to deal with the stdint.h issue
I hit in 6.8 so I'm building 6.7.1.
I see now the mail threads where it was fixed pretty simply.
So maybe I'll go back to that.
In the meantime, with 6.7.1, I hit a simple problem (so far, still compiling)
warning variable 'exact' may be used uninitialized + -Werror.
Here is my patch:
-bash-3.2$ gdiff -u symtab.c.orig symtab.c
--- symtab.c.orig 2009-02-22 20:25:52.000000000 -0800
+++ symtab.c 2009-02-22 19:38:25.000000000 -0800
@@ -2249,7 +2249,7 @@
struct symtab *
find_line_symtab (struct symtab *symtab, int line, int *index, int *exact_match
)
{
- int exact;
+ int exact = { 0 };
/* BEST_INDEX and BEST_LINETABLE identify the smallest linenumber> LINE
so far seen. */
Sure, now it may be unoptimally unnecessarily initialized but
I don't think that is worth worrying about.
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.
Current source looks about the same.
My system is:
-bash-3.2$ gcc32 -v
Using built-in specs.
Target: hppa2.0w-hp-hpux11.11
Configured with: /src/gcc-4.3.3/configure -disable-nls -disable-bootstrap -prefi
x=/usr/local/32 -with-as=/usr/local/32/bin/gas -verbose
Thread model: posix
gcc version 4.3.3 (GCC)
-bash-3.2$ uname -a
HP-UX unknown B.11.11 U 9000/800 1595760578 unlimited-user license
gdb configured with:
$ /src/gdb-6.7.1/configure -disable-nls -prefix=/usr/local/32
and I rm -rf /src/gdb*/intl
and maybe altering PATH and/or CC, e.g. CC=gcc32, but gcc first
in $PATH is the same so that shouldn't matter here, by far.
Thanks,
- Jay
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: warning/error about possibly uninitialized 'exact' in find_line_symtab
2009-02-23 2:32 warning/error about possibly uninitialized 'exact' in find_line_symtab Jay
@ 2009-02-23 4:07 ` Joel Brobecker
2009-02-23 18:12 ` Tom Tromey
0 siblings, 1 reply; 3+ messages in thread
From: Joel Brobecker @ 2009-02-23 4:07 UTC (permalink / raw)
To: Jay; +Cc: gdb-patches
[-- Attachment #1: Type: text/plain, Size: 1822 bytes --]
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
[-- Attachment #2: symtab.c.diff --]
[-- Type: text/plain, Size: 464 bytes --]
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. */
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: warning/error about possibly uninitialized 'exact' in find_line_symtab
2009-02-23 4:07 ` Joel Brobecker
@ 2009-02-23 18:12 ` Tom Tromey
0 siblings, 0 replies; 3+ messages in thread
From: Tom Tromey @ 2009-02-23 18:12 UTC (permalink / raw)
To: Joel Brobecker; +Cc: Jay, gdb-patches
>>>>> "Joel" == Joel Brobecker <brobecker@adacore.com> writes:
Joel> (thinking aloud - do we need a more descriptive comment about why
Joel> we initialize this variable here? I don't think it's necessary,
Joel> but let me know otherwise)
I think it is fine as is.
Tom
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2009-02-23 17:15 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-02-23 2:32 warning/error about possibly uninitialized 'exact' in find_line_symtab Jay
2009-02-23 4:07 ` Joel Brobecker
2009-02-23 18:12 ` Tom Tromey
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox