From d0c418c0bb150cce670bbfd1d9343f91f894125a Mon Sep 17 00:00:00 2001 From: Matthew Plough Date: Fri, 27 Jan 2017 12:49:48 -0500 Subject: [PATCH] Fix uninitialized variable warning Fix the following warning emitted by clang: [ 16%] Building C object CMakeFiles/libgit2_clar.dir/src/submodule.c.o /Users/mplough/devel/external/libgit2/src/submodule.c:408:6: warning: variable 'i' is used uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized] if ((error = load_submodule_names(names, cfg))) ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /Users/mplough/devel/external/libgit2/src/submodule.c:448:20: note: uninitialized use occurs here git_iterator_free(i); ^ /Users/mplough/devel/external/libgit2/src/submodule.c:408:2: note: remove the 'if' if its condition is always false if ((error = load_submodule_names(names, cfg))) ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /Users/mplough/devel/external/libgit2/src/submodule.c:404:17: note: initialize the variable 'i' to silence this warning git_iterator *i; ^ = NULL 1 warning generated. --- src/submodule.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/submodule.c b/src/submodule.c index fc3dcb406..1c17075bf 100644 --- a/src/submodule.c +++ b/src/submodule.c @@ -401,7 +401,7 @@ done: static int submodules_from_head(git_strmap *map, git_tree *head, git_config *cfg) { int error; - git_iterator *i; + git_iterator *i = NULL; const git_index_entry *entry; git_strmap *names = 0; git_strmap_alloc(&names); -- 2.39.5