git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
To: Nguyen Thai Ngoc Duy <pclouds@gmail.com>
Cc: Junio C Hamano <gitster@pobox.com>,
	GIT Mailing-list <git@vger.kernel.org>
Subject: [PATCH] column.c: Fix an "variable might be used uninitialized" warning
Date: Sat, 17 Mar 2012 18:30:45 +0000	[thread overview]
Message-ID: <4F64D855.4010302@ramsay1.demon.co.uk> (raw)


In particular, gcc complains as follows:

        CC column.o
    column.c: In function 'print_columns':
    column.c:305: warning: 'len' may be used uninitialized \
        in this function

The compiler can determine that the 'len' variable, which is
passed by reference to the largest_block() function, may indeed
not be set. For example, if largest_block() returns zero, then
the 'len' output parameter will not be assigned to, which would
result in the local 'len' variable remaining uninitialised.
This would not lead to 'len' actually being used, however, since
the code checks for this case ('size' will be set to zero) and
will not execute the remainder of the loop body.

In order to suppress the warning, we simply initialise the 'len'
variable to zero.

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

Hi Nguyen,

Could you please squash this into the relevant commit in your
nd/column series. Thanks!

[gcc v4.1.2 (on Linux) complains, but gcc v3.4.4 and gcc v4.4.0
do *not* complain.]

ATB,
Ramsay Jones

 column.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/column.c b/column.c
index 8214a9b..80183ea 100644
--- a/column.c
+++ b/column.c
@@ -302,7 +302,7 @@ static struct area *find_large_blocks(const struct string_list *list, int *nr_p)
 	memset(&last, 0, sizeof(last));
 
 	for (i = 0; i < list->nr; i++) {
-		int len, size = largest_block(list, i, 0, &len);
+		int len = 0, size = largest_block(list, i, 0, &len);
 		if (!size || len == 1)
 			continue;
 		/* the new found area is overlapped with the old one,
-- 
1.7.9

                 reply	other threads:[~2012-03-17 18:32 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=4F64D855.4010302@ramsay1.demon.co.uk \
    --to=ramsay@ramsay1.demon.co.uk \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=pclouds@gmail.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 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).