From 6ffdd9c7276427bd784e71a7c1f47ffb3cc1c01f Mon Sep 17 00:00:00 2001 From: Ramsay Jones Date: Mon, 19 Mar 2018 17:54:35 +0000 Subject: [PATCH] PATCH 1/2] -Wuninitialized: remove some 'init-self' workarounds The 'self-initialised' variables construct (ie var = var;) has been used to silence gcc '-W[maybe-]uninitialized' warnings. This has, unfortunately, caused MSVC to issue 'uninitialized variable' warnings. Also, using clang static analysis causes complaints about an 'Assigned value is garbage or undefined'. There are six such constructs in the current codebase. Only one of the six causes gcc to issue a '-Wmaybe-uninitialized' warning (which will be addressed elsewhere). The remaining five 'init-self' gcc workarounds are noted below, along with the commit which introduced them: 1. builtin/rev-list.c: 'reaches' and 'all', see commit 457f08a030 ("git-rev-list: add --bisect-vars option.", 2007-03-21). 2. merge-recursive.c:2064 'mrtree', see commit f120ae2a8e ("merge- recursive.c: mrtree in merge() is not used before set", 2007-10-29). 3. fast-import.c:3023 'oe', see commit 85c62395b1 ("fast-import: let importers retrieve blobs", 2010-11-28). 4. fast-import.c:3006 'oe', see commit 28c7b1f7b7 ("fast-import: add a get-mark command", 2015-07-01). Remove the 'self-initialised' variable constructs noted above. Signed-off-by: Ramsay Jones --- builtin/rev-list.c | 3 +-- fast-import.c | 4 ++-- merge-recursive.c | 2 +- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/builtin/rev-list.c b/builtin/rev-list.c index 49325f6f05eb66..fbfc62de41468b 100644 --- a/builtin/rev-list.c +++ b/builtin/rev-list.c @@ -479,8 +479,7 @@ int cmd_rev_list(int argc, const char **argv, const char *prefix) mark_edges_uninteresting(&revs, show_edge); if (bisect_list) { - FAKE_INIT(int, reaches, 0); - FAKE_INIT(int, all, 0); + int reaches, all; find_bisection(&revs.commits, &reaches, &all, bisect_find_all); diff --git a/fast-import.c b/fast-import.c index 04023e7c5fda52..1f01a220550605 100644 --- a/fast-import.c +++ b/fast-import.c @@ -3003,7 +3003,7 @@ static void cat_blob(struct object_entry *oe, struct object_id *oid) static void parse_get_mark(const char *p) { - FAKE_INIT(struct object_entry *, oe, NULL); + struct object_entry *oe; char output[GIT_MAX_HEXSZ + 2]; /* get-mark SP LF */ @@ -3020,7 +3020,7 @@ static void parse_get_mark(const char *p) static void parse_cat_blob(const char *p) { - FAKE_INIT(struct object_entry *, oe, NULL); + struct object_entry *oe; struct object_id oid; /* cat-blob SP LF */ diff --git a/merge-recursive.c b/merge-recursive.c index 12c968eeaa2ced..7dad1646921d4f 100644 --- a/merge-recursive.c +++ b/merge-recursive.c @@ -2070,7 +2070,7 @@ int merge_recursive(struct merge_options *o, { struct commit_list *iter; struct commit *merged_common_ancestors; - FAKE_INIT(struct tree *, mrtree, NULL); + struct tree *mrtree; int clean; if (show(o, 4)) {