pretty.c: Fix a compiler warning
PATCH 1/1 pretty.c: Fix a compiler warning
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.
---
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 ---
pretty.c +2 -0
@@ -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(-)
pretty.c +1 -1
@@ -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;
Signature · 1 line
1.7.12