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] pretty.c: Fix a compiler warning
Date: Thu, 04 Oct 2012 19:06:37 +0100	[thread overview]
Message-ID: <506DD02D.2060809@ramsay1.demon.co.uk> (raw)


In particular, gcc complains thus:

        CC pretty.o
    pretty.c: In function 'format_commit_item':
    pretty.c:1282: warning: 'offset' might be used uninitialized in \
        this function

In order to suppress the warning we simply initialize the 'offset'
variable in it's declarartion.

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

Hi Nguyen,

If you need to re-roll your 'nd/pretty-placeholder-with-color-option'
branch, could you please squash this (or something like it) into the
relevant commit. [commit f1da75df ("pretty: support padding placeholders,
%< %> and %><", 23-09-2012). NOTE: this patch is on top of pu@a78f4186]

An alternative solution looks like (this will probably break git-am):

--- >8 ---
diff --git a/pretty.c b/pretty.c
index deeacf2..25d8eb2 100644
--- a/pretty.c
+++ b/pretty.c
@@ -1292,6 +1292,8 @@ static size_t format_and_pad_commit(struct strbuf *sb, /* in UTF-8 */
 			break;
 		case flush_left_and_steal:
 		case no_flush: /* to make gcc happy */
+		default:
+			offset = 0;
 			break;
 		}
 		/*
--- 8< ---

... but this disables the "enumeration value 'no_flush' not handled in switch"
type warnings.

[Actually, I would not bother with a switch at all; I find this:

	} else {
		int sb_len = sb->len, offset = 0;
		if (c->flush_type == flush_left)
			offset = padding - len;
		else if (c->flush_type == flush_both)
			offset = (padding - len) / 2;
		...

... much more readable. But that's just me ... :-D ]

Thanks!

ATB,
Ramsay Jones

 pretty.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pretty.c b/pretty.c
index deeacf2..d26428b 100644
--- a/pretty.c
+++ b/pretty.c
@@ -1279,7 +1279,7 @@ static size_t format_and_pad_commit(struct strbuf *sb, /* in UTF-8 */
 		}
 		strbuf_addstr(sb, local_sb.buf);
 	} else {
-		int sb_len = sb->len, offset;
+		int sb_len = sb->len, offset = 0;
 		switch (c->flush_type) {
 		case flush_left:
 			offset = padding - len;
-- 
1.7.12

                 reply	other threads:[~2012-10-04 22:12 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=506DD02D.2060809@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).