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 <ram...@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

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to