Skip to content

Commit

Permalink
PATCH 1/2] -Wuninitialized: remove some 'init-self' workarounds
Browse files Browse the repository at this point in the history
The 'self-initialised' variables construct (ie <type> 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 457f08a
     ("git-rev-list: add --bisect-vars option.", 2007-03-21).

  2. merge-recursive.c:2064 'mrtree', see commit f120ae2 ("merge-
     recursive.c: mrtree in merge() is not used before set", 2007-10-29).

  3. fast-import.c:3023 'oe', see commit 85c6239 ("fast-import: let
     importers retrieve blobs", 2010-11-28).

  4. fast-import.c:3006 'oe', see commit 28c7b1f ("fast-import: add a
     get-mark command", 2015-07-01).

Remove the 'self-initialised' variable constructs noted above.

Signed-off-by: Ramsay Jones <ramsay@ramsayjones.plus.com>
  • Loading branch information
ramsay-jones authored and dscho committed Mar 20, 2018
1 parent 52f89a9 commit 6ffdd9c
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 5 deletions.
3 changes: 1 addition & 2 deletions builtin/rev-list.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
4 changes: 2 additions & 2 deletions fast-import.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 <object> LF */
Expand All @@ -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 <object> LF */
Expand Down
2 changes: 1 addition & 1 deletion merge-recursive.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down

0 comments on commit 6ffdd9c

Please sign in to comment.