git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Fix an "variable might be used uninitialized" gcc warning
@ 2011-12-16 22:44 Ramsay Jones
  2011-12-16 23:59 ` Jonathan Nieder
  0 siblings, 1 reply; 7+ messages in thread
From: Ramsay Jones @ 2011-12-16 22:44 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: GIT Mailing-list


In particular, gcc issues the following warning:

        CC builtin/checkout.o
    builtin/checkout.c: In function `cmd_checkout':
    builtin/checkout.c:160: warning: 'mode' might be used uninitialized \
        in this function

However, the analysis performed by gcc is too conservative, in this
case, since the mode variable will not be used uninitialised. Note that,
if the mode variable is not set in the loop, then "threeway[1]" will
also still be set to the null SHA1. This will then result in control
leaving the function, almost directly after the loop, well before the
potential use in the call to make_cache_entry().

In order to suppress the warning, we initialise the mode variable to
zero in it's declaration.

Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
---

Just in case you haven't found the time to apply your own patch!

[Note that only 2 out of the 3 versions of gcc I use issues this
warning]

ATB,
Ramsay Jones

 builtin/checkout.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/builtin/checkout.c b/builtin/checkout.c
index 787d468..f1984d9 100644
--- a/builtin/checkout.c
+++ b/builtin/checkout.c
@@ -157,7 +157,7 @@ static int checkout_merged(int pos, struct checkout *state)
 	unsigned char sha1[20];
 	mmbuffer_t result_buf;
 	unsigned char threeway[3][20];
-	unsigned mode;
+	unsigned mode = 0;
 
 	memset(threeway, 0, sizeof(threeway));
 	while (pos < active_nr) {
-- 
1.7.8

^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2012-02-02 18:38 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-12-16 22:44 [PATCH] Fix an "variable might be used uninitialized" gcc warning Ramsay Jones
2011-12-16 23:59 ` Jonathan Nieder
2011-12-17 10:22   ` Andreas Schwab
2012-01-31 18:36   ` Ramsay Jones
2012-01-31 19:43     ` Jonathan Nieder
2012-02-01  7:16       ` Miles Bader
2012-02-02 18:25       ` Ramsay Jones

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).