Re: [PATCH] notes: Initialize variable to appease Sun Studio
- From
Ramsay Jones <ramsay@ramsay1.demon.co.uk>
- Date
- Jun 21, 2010, 20:53 UTC
- Message-ID
- <4C1FD160.6010700@ramsay1.demon.co.uk>
- In-Reply-To
- <AANLkTimmnlHmt6LTHFKUtJZ7taSF10p4Pkna4CCb1G_J@mail.gmail.com>
Ævar Arnfjörð Bjarmason wrote:
Show 10 quoted lines
> On Sat, Jun 19, 2010 at 04:52, Junio C Hamano <gitster@pobox.com> wrote: >> Ævar Arnfjörð Bjarmason <avarab@gmail.com> writes: >> >>> Sun Studio 12 Update 1 thinks that *t could be uninitialized, >>> ostensibly because it doesn't take rewrite_cmd into account in its >>> static analysis. >> Hmm, I am wondering if I should apply this or just tell you to fix your >> compiler ;-) > > I just noticed it when testing on Solaris, I don't use it regularly.
gcc version 3.4.4 issues exactly the same warning (but gcc versions 4.1.2 and 4.4.0 don't).
However, gcc 3.4.4 also issues a warning for notes.c, thus:
notes.c: In function `write_each_non_note_until':
notes.c:719: warning: 'cmp' might be used uninitialized in this functionThe obvious patch is below, ;-)
ATB, Ramsay Jones
-- >8 -- From: Ramsay Jones <ramsay@ramsay1.demon.co.uk> Date: Mon, 21 Jun 2010 19:52:29 +0100 Subject: [PATCH] notes: Initialise variable to appease gcc
gcc version 3.4.4 thinks that the 'cmp' variable could be used while uninitialised and complains thus:
notes.c: In function `write_each_non_note_until':
notes.c:719: warning: 'cmp' might be used uninitialized in \
this functionNote that gcc versions 4.1.2 and 4.4.0 do not issue this warning.
Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk> --- notes.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/notes.c b/notes.c index 6ee04e7..30d6ded 100644 --- a/notes.c +++ b/notes.c @@ -716,7 +716,7 @@ static int write_each_non_note_until(const char *note_path, struct write_each_note_data *d) { struct non_note *n = d->next_non_note; - int cmp, ret; + int cmp = 0, ret; while (n && (!note_path || (cmp = strcmp(n->path, note_path)) <= 0)) { if (note_path && cmp == 0) ; /* do nothing, prefer note to non-note */
-- 1.7.1