From 02418490c69132313d6b612878cdfaaf8b5ef35b Mon Sep 17 00:00:00 2001 From: Felipe Contreras Date: Sat, 10 May 2014 23:07:55 -0500 Subject: [PATCH] Silence gcc warnings with -O3 MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Commit a469a10 (silence some -Wuninitialized false positives) tried to silence some uninitialized false-positives with a hack. This hack triggered many more warnings on clang, and eventually gcc 4.9.0 as well. While more hacks can be used to silence the new warnings, it's much better to decouple ourselves from such hacks and help the compilers directly. We can do that by either initializing the variables, or manually returning the error value (-1) without depending on error() to do it. This fixes warnings while compiling with gcc -O3. parse-options.c: In function ‘get_value’: parse-options.c:183:24: warning: ‘arg’ may be used uninitialized in this function [-Wmaybe-uninitialized] *(int *)opt->value = strtol(arg, (char **)&s, 10); ^ Signed-off-by: Felipe Contreras --- parse-options.c | 6 ++++-- remote.c | 2 +- vcs-svn/svndiff.c | 15 ++++++++++----- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/parse-options.c b/parse-options.c index f7abbb092a..1a5f3ac421 100644 --- a/parse-options.c +++ b/parse-options.c @@ -39,8 +39,10 @@ static int get_arg(struct parse_opt_ctx_t *p, const struct option *opt, } else if (p->argc > 1) { p->argc--; *arg = *++p->argv; - } else - return opterror(opt, "requires a value", flags); + } else { + opterror(opt, "requires a value", flags); + return -1; + } return 0; } diff --git a/remote.c b/remote.c index fc02698587..8935693ed8 100644 --- a/remote.c +++ b/remote.c @@ -1147,7 +1147,7 @@ static int match_explicit(struct ref *src, struct ref *dst, struct refspec *rs) { struct ref *matched_src, *matched_dst; - int allocated_src; + int allocated_src = 0; const char *dst_value = rs->dst; char *dst_guess; diff --git a/vcs-svn/svndiff.c b/vcs-svn/svndiff.c index 74c97c4543..cf7cb81f7a 100644 --- a/vcs-svn/svndiff.c +++ b/vcs-svn/svndiff.c @@ -64,14 +64,17 @@ static int write_strbuf(struct strbuf *sb, FILE *out) { if (fwrite(sb->buf, 1, sb->len, out) == sb->len) /* Success. */ return 0; - return error("cannot write delta postimage: %s", strerror(errno)); + error("cannot write delta postimage: %s", strerror(errno)); + return -1; } static int error_short_read(struct line_buffer *input) { if (buffer_ferror(input)) - return error("error reading delta: %s", strerror(errno)); - return error("invalid delta: unexpected end of file"); + error("error reading delta: %s", strerror(errno)); + else + error("invalid delta: unexpected end of file"); + return -1; } static int read_chunk(struct line_buffer *delta, off_t *delta_len, @@ -97,7 +100,8 @@ static int read_magic(struct line_buffer *in, off_t *len) } if (memcmp(sb.buf, magic, sizeof(magic))) { strbuf_release(&sb); - return error("invalid delta: unrecognized file type"); + error("invalid delta: unrecognized file type"); + return -1; } strbuf_release(&sb); return 0; @@ -140,7 +144,8 @@ static int parse_int(const char **buf, size_t *result, const char *end) *buf = pos + 1; return 0; } - return error("invalid delta: unexpected end of instructions section"); + error("invalid delta: unexpected end of instructions section"); + return -1; } static int read_offset(struct line_buffer *in, off_t *result, off_t *len) -- 2.32.0.93.g670b81a890