All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
To: Junio C Hamano <gitster@pobox.com>
Cc: GIT Mailing-list <git@vger.kernel.org>
Subject: [PATCH] Fix an "variable might be used uninitialized" gcc warning
Date: Fri, 16 Dec 2011 22:44:38 +0000	[thread overview]
Message-ID: <4EEBC9D6.6010204@ramsay1.demon.co.uk> (raw)


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

             reply	other threads:[~2011-12-16 22:58 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-12-16 22:44 Ramsay Jones [this message]
2011-12-16 23:59 ` [PATCH] Fix an "variable might be used uninitialized" gcc warning 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4EEBC9D6.6010204@ramsay1.demon.co.uk \
    --to=ramsay@ramsay1.demon.co.uk \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.