{"thread":{"id":"31730","subject":"[PATCH] pretty.c: Fix a compiler warning","startedAt":"2012-10-04T18:06:37Z","lastAt":"2012-10-04T18:06:37Z","messageCount":1,"participants":["Ramsay Jones"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"200531","messageId":"506DD02D.2060809@ramsay1.demon.co.uk","threadId":"31730","inReplyTo":null,"subject":"[PATCH] pretty.c: Fix a compiler warning","fromName":"Ramsay Jones","fromEmail":"ramsay@ramsay1.demon.co.uk","sentAt":"2012-10-04T18:06:37Z","receivedAt":"2012-10-04T18:06:37Z","isPatch":true,"sender":{"key":"ramsay@ramsayjones.plus.com","avatar":"https://avatars.githubusercontent.com/u/33702710?v=4"},"body":"\nIn particular, gcc complains thus:\n\n        CC pretty.o\n    pretty.c: In function 'format_commit_item':\n    pretty.c:1282: warning: 'offset' might be used uninitialized in \\\n        this function\n\nIn order to suppress the warning we simply initialize the 'offset'\nvariable in it's declarartion.\n\nSigned-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>\n---\n\nHi Nguyen,\n\nIf you need to re-roll your 'nd/pretty-placeholder-with-color-option'\nbranch, could you please squash this (or something like it) into the\nrelevant commit. [commit f1da75df (\"pretty: support padding placeholders,\n%< %> and %><\", 23-09-2012). NOTE: this patch is on top of pu@a78f4186]\n\nAn alternative solution looks like (this will probably break git-am):\n\n--- >8 ---\ndiff --git a/pretty.c b/pretty.c\nindex deeacf2..25d8eb2 100644\n--- a/pretty.c\n+++ b/pretty.c\n@@ -1292,6 +1292,8 @@ static size_t format_and_pad_commit(struct strbuf *sb, /* in UTF-8 */\n \t\t\tbreak;\n \t\tcase flush_left_and_steal:\n \t\tcase no_flush: /* to make gcc happy */\n+\t\tdefault:\n+\t\t\toffset = 0;\n \t\t\tbreak;\n \t\t}\n \t\t/*\n--- 8< ---\n\n... but this disables the \"enumeration value 'no_flush' not handled in switch\"\ntype warnings.\n\n[Actually, I would not bother with a switch at all; I find this:\n\n\t} else {\n\t\tint sb_len = sb->len, offset = 0;\n\t\tif (c->flush_type == flush_left)\n\t\t\toffset = padding - len;\n\t\telse if (c->flush_type == flush_both)\n\t\t\toffset = (padding - len) / 2;\n\t\t...\n\n... much more readable. But that's just me ... :-D ]\n\nThanks!\n\nATB,\nRamsay Jones\n\n pretty.c | 2 +-\n 1 file changed, 1 insertion(+), 1 deletion(-)\n\ndiff --git a/pretty.c b/pretty.c\nindex deeacf2..d26428b 100644\n--- a/pretty.c\n+++ b/pretty.c\n@@ -1279,7 +1279,7 @@ static size_t format_and_pad_commit(struct strbuf *sb, /* in UTF-8 */\n \t\t}\n \t\tstrbuf_addstr(sb, local_sb.buf);\n \t} else {\n-\t\tint sb_len = sb->len, offset;\n+\t\tint sb_len = sb->len, offset = 0;\n \t\tswitch (c->flush_type) {\n \t\tcase flush_left:\n \t\t\toffset = padding - len;\n-- \n1.7.12\n"}]}