Skip to content

Commit be0fd57

Browse files
avarttaylorr
authored andcommitted
maintenance --unregister: fix uninit'd data use & -Wdeclaration-after-statement
Since (maintenance: add option to register in a specific config, 2022-11-09) we've been unable to build with "DEVELOPER=1" without "DEVOPTS=no-error", as the added code triggers a "-Wdeclaration-after-statement" warning. And worse than that, the data handed to git_configset_clear() is uninitialized, as can be spotted with e.g.: ./t7900-maintenance.sh -vixd --run=23 --valgrind [...] + git maintenance unregister --force Conditional jump or move depends on uninitialised value(s) at 0x6B5F1E: git_configset_clear (config.c:2367) by 0x4BA64E: maintenance_unregister (gc.c:1619) by 0x4BD278: cmd_maintenance (gc.c:2650) by 0x409905: run_builtin (git.c:466) by 0x40A21C: handle_builtin (git.c:721) by 0x40A58E: run_argv (git.c:788) by 0x40AF68: cmd_main (git.c:926) by 0x5D39FE: main (common-main.c:57) Uninitialised value was created by a stack allocation at 0x4BA22C: maintenance_unregister (gc.c:1557) Let's fix both of these issues, and also move the scope of the variable to the "if" statement it's used in, to make it obvious where it's used. Helped-by: Johannes Schindelin <[email protected]> Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Taylor Blau <[email protected]>
1 parent 1f80129 commit be0fd57

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

builtin/gc.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1550,11 +1550,13 @@ static int maintenance_unregister(int argc, const char **argv, const char *prefi
15501550
usage_with_options(builtin_maintenance_unregister_usage,
15511551
options);
15521552

1553-
struct config_set cs;
15541553
if (config_file) {
1554+
struct config_set cs;
1555+
15551556
git_configset_init(&cs);
15561557
git_configset_add_file(&cs, config_file);
15571558
list = git_configset_get_value_multi(&cs, key);
1559+
git_configset_clear(&cs);
15581560
} else {
15591561
list = git_config_get_value_multi(key);
15601562
}
@@ -1590,7 +1592,6 @@ static int maintenance_unregister(int argc, const char **argv, const char *prefi
15901592
die(_("repository '%s' is not registered"), maintpath);
15911593
}
15921594

1593-
git_configset_clear(&cs);
15941595
free(maintpath);
15951596
return 0;
15961597
}

0 commit comments

Comments
 (0)