* [PATCH] pretty.c: Fix a compiler warning
@ 2012-10-04 18:06 Ramsay Jones
0 siblings, 0 replies; only message in thread
From: Ramsay Jones @ 2012-10-04 18:06 UTC (permalink / raw)
To: Nguyen Thai Ngoc Duy; +Cc: Junio C Hamano, GIT Mailing-list
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
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2012-10-04 22:12 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-10-04 18:06 [PATCH] pretty.c: Fix a compiler warning 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).