All of lore.kernel.org
 help / color / mirror / Atom feed
From: Denton Liu <liu.denton@gmail.com>
To: Git Mailing List <git@vger.kernel.org>
Subject: [PATCH] Fix -Wmaybe-uninitialized warnings under -O0
Date: Wed,  1 Apr 2020 03:30:16 -0400	[thread overview]
Message-ID: <33984eeaabbfbcfd4b9d3903549d8b7d6c4ced7e.1585726172.git.liu.denton@gmail.com> (raw)

When compiling Git under -O0, gcc (Arch Linux 9.3.0-1) 9.3.0 produces
many -Wmaybe-uninitialized warnings. These are false positives since
when Git is compiled under -O2, gcc is smart enough to see that the
code paths that use these variables all initialise them beforehand.
Nonetheless, these warnings block the compilation process when
DEVELOPER=1 is enabled (which enables -Werror).

Fix these warnings by initializing these variables with dummy values (0,
-1 or NULL as appropriate).

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 builtin/branch.c          | 2 +-
 diff.c                    | 2 +-
 fast-import.c             | 4 ++--
 http-backend.c            | 2 +-
 ref-filter.c              | 2 +-
 refs/packed-backend.c     | 2 +-
 t/helper/test-ref-store.c | 2 +-
 trace2/tr2_dst.c          | 2 +-
 trailer.c                 | 2 +-
 9 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/builtin/branch.c b/builtin/branch.c
index d8297f80ff..3669fba546 100644
--- a/builtin/branch.c
+++ b/builtin/branch.c
@@ -455,7 +455,7 @@ static void print_current_branch_name(void)
 {
 	int flags;
 	const char *refname = resolve_ref_unsafe("HEAD", 0, NULL, &flags);
-	const char *shortname;
+	const char *shortname = NULL;
 	if (!refname)
 		die(_("could not resolve HEAD"));
 	else if (!(flags & REF_ISSYMREF))
diff --git a/diff.c b/diff.c
index f2cfbf2214..99a35774d7 100644
--- a/diff.c
+++ b/diff.c
@@ -3263,7 +3263,7 @@ static void emit_binary_diff_body(struct diff_options *o,
 	void *delta;
 	void *deflated;
 	void *data;
-	unsigned long orig_size;
+	unsigned long orig_size = 0;
 	unsigned long delta_size;
 	unsigned long deflate_size;
 	unsigned long data_size;
diff --git a/fast-import.c b/fast-import.c
index b8b65a801c..0509c0b92f 100644
--- a/fast-import.c
+++ b/fast-import.c
@@ -1829,7 +1829,7 @@ static void parse_original_identifier(void)
 
 static int parse_data(struct strbuf *sb, uintmax_t limit, uintmax_t *len_res)
 {
-	const char *data;
+	const char *data = NULL;
 	strbuf_reset(sb);
 
 	if (!skip_prefix(command_buf.buf, "data ", &data))
@@ -2719,7 +2719,7 @@ static void parse_new_commit(const char *arg)
 static void parse_new_tag(const char *arg)
 {
 	static struct strbuf msg = STRBUF_INIT;
-	const char *from;
+	const char *from = NULL;
 	char *tagger;
 	struct branch *s;
 	struct tag *t;
diff --git a/http-backend.c b/http-backend.c
index ec3144b444..1091cdf2cd 100644
--- a/http-backend.c
+++ b/http-backend.c
@@ -252,7 +252,7 @@ static void http_config(void)
 
 static struct rpc_service *select_service(struct strbuf *hdr, const char *name)
 {
-	const char *svc_name;
+	const char *svc_name = NULL;
 	struct rpc_service *svc = NULL;
 	int i;
 
diff --git a/ref-filter.c b/ref-filter.c
index b1812cb69a..6abd48f81a 100644
--- a/ref-filter.c
+++ b/ref-filter.c
@@ -1938,7 +1938,7 @@ static int for_each_fullref_in_pattern(struct ref_filter *filter,
 {
 	struct string_list prefixes = STRING_LIST_INIT_DUP;
 	struct string_list_item *prefix;
-	int ret;
+	int ret = 0;
 
 	if (!filter->match_as_path) {
 		/*
diff --git a/refs/packed-backend.c b/refs/packed-backend.c
index 4458a0f69c..f37c6d19a6 100644
--- a/refs/packed-backend.c
+++ b/refs/packed-backend.c
@@ -627,7 +627,7 @@ static struct snapshot *create_snapshot(struct packed_ref_store *refs)
 
 	/* If the file has a header line, process it: */
 	if (snapshot->buf < snapshot->eof && *snapshot->buf == '#') {
-		char *tmp, *p, *eol;
+		char *tmp, *p = NULL, *eol;
 		struct string_list traits = STRING_LIST_INIT_NODUP;
 
 		eol = memchr(snapshot->buf, '\n',
diff --git a/t/helper/test-ref-store.c b/t/helper/test-ref-store.c
index 799fc00aa1..d82dcb83a3 100644
--- a/t/helper/test-ref-store.c
+++ b/t/helper/test-ref-store.c
@@ -19,7 +19,7 @@ static unsigned int arg_flags(const char *arg, const char *name)
 
 static const char **get_store(const char **argv, struct ref_store **refs)
 {
-	const char *gitdir;
+	const char *gitdir = NULL;
 
 	if (!argv[0]) {
 		die("ref store required");
diff --git a/trace2/tr2_dst.c b/trace2/tr2_dst.c
index ae052a07fe..910301a53d 100644
--- a/trace2/tr2_dst.c
+++ b/trace2/tr2_dst.c
@@ -227,7 +227,7 @@ static int tr2_dst_try_unix_domain_socket(struct tr2_dst *dst,
 {
 	unsigned int uds_try = 0;
 	int fd;
-	int e;
+	int e = 0;
 	const char *path = NULL;
 
 	/*
diff --git a/trailer.c b/trailer.c
index 0c414f2fed..cac9d0a4d9 100644
--- a/trailer.c
+++ b/trailer.c
@@ -507,7 +507,7 @@ static int git_trailer_config(const char *conf_key, const char *value, void *cb)
 	struct arg_item *item;
 	struct conf_info *conf;
 	char *name = NULL;
-	enum trailer_info_type type;
+	enum trailer_info_type type = -1;
 	int i;
 
 	if (!skip_prefix(conf_key, "trailer.", &trailer_item))
-- 
2.26.0.159.g23e2136ad0


             reply	other threads:[~2020-04-01  7:30 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-01  7:30 Denton Liu [this message]
     [not found] ` <CAPUEspgBkmxszgBee8C9hZnEwqztf-XKEj7LB_jWVFJaJCge0w@mail.gmail.com>
2020-04-01  9:05   ` [PATCH] Fix -Wmaybe-uninitialized warnings under -O0 Denton Liu
2020-04-01  9:52 ` Jeff King
2020-04-01 14:06   ` Denton Liu
2020-04-03 14:04     ` Jeff King
2020-04-03 14:38       ` Jeff King
2020-04-04 12:07       ` Denton Liu
2020-04-04 14:21         ` Jeff King
2021-05-05  8:40           ` [PATCH] trace2: refactor to avoid gcc warning under -O3 Ævar Arnfjörð Bjarmason
2021-05-05  9:47             ` Junio C Hamano
2021-05-05 13:34               ` Jeff King
2021-05-05 14:38             ` Johannes Schindelin
2021-05-06  1:26               ` Junio C Hamano
2021-05-06 20:29                 ` Johannes Schindelin
2021-05-06 21:10                   ` Junio C Hamano
2021-05-11 14:34                     ` Johannes Schindelin
2021-05-11 18:00                       ` Jeff King
2021-05-11 20:58                         ` Junio C Hamano
2021-05-11 21:07                           ` Jeff King
2021-05-11 21:33                             ` Junio C Hamano
2021-05-11  7:03             ` Junio C Hamano
2021-05-11 13:04             ` [PATCH v2] " Ævar Arnfjörð Bjarmason
2021-05-11 16:40               ` Jeff Hostetler
2021-05-11 17:54               ` Jeff King
2021-05-11 18:08                 ` Jeff King
2021-05-11 21:09                   ` Junio C Hamano
2021-05-20  0:20                   ` Junio C Hamano
2021-05-20 11:05                     ` [PATCH v3] " Ævar Arnfjörð Bjarmason
2021-05-20 13:13                       ` Jeff King
2021-05-20 22:08                         ` Junio C Hamano
2021-05-21  9:34                           ` Jeff King

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=33984eeaabbfbcfd4b9d3903549d8b7d6c4ced7e.1585726172.git.liu.denton@gmail.com \
    --to=liu.denton@gmail.com \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.