Skip to content

Commit 8df1cfc

Browse files
authored
Merge pull request libgit2#4086 from libgit2/ethomson/fixes
WIP: some coverity & compiler warning fixes
2 parents 9b51cc8 + 1f813cf commit 8df1cfc

File tree

4 files changed

+16
-18
lines changed

4 files changed

+16
-18
lines changed

src/attrcache.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,20 +121,22 @@ static int attr_cache_remove(git_attr_cache *cache, git_attr_file *file)
121121
{
122122
int error = 0;
123123
git_attr_file_entry *entry;
124+
git_attr_file *old = NULL;
124125

125126
if (!file)
126127
return 0;
128+
127129
if ((error = attr_cache_lock(cache)) < 0)
128130
return error;
129131

130132
if ((entry = attr_cache_lookup_entry(cache, file->entry->path)) != NULL)
131-
file = git__compare_and_swap(&entry->file[file->source], file, NULL);
133+
old = git__compare_and_swap(&entry->file[file->source], file, NULL);
132134

133135
attr_cache_unlock(cache);
134136

135-
if (file) {
136-
GIT_REFCOUNT_OWN(file, NULL);
137-
git_attr_file__free(file);
137+
if (old) {
138+
GIT_REFCOUNT_OWN(old, NULL);
139+
git_attr_file__free(old);
138140
}
139141

140142
return error;

src/integer.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,16 +55,16 @@ GIT_INLINE(bool) git__add_uint64_overflow(uint64_t *out, uint64_t one, uint64_t
5555
}
5656

5757
/* Use clang/gcc compiler intrinsics whenever possible */
58-
#if (SIZE_MAX == UINT_MAX) && __has_builtin(__builtin_uadd_overflow)
59-
# define git__add_sizet_overflow(out, one, two) \
60-
__builtin_uadd_overflow(one, two, out)
61-
# define git__multiply_sizet_overflow(out, one, two) \
62-
__builtin_umul_overflow(one, two, out)
63-
#elif (SIZE_MAX == ULONG_MAX) && __has_builtin(__builtin_uaddl_overflow)
58+
#if (SIZE_MAX == ULONG_MAX) && __has_builtin(__builtin_uaddl_overflow)
6459
# define git__add_sizet_overflow(out, one, two) \
6560
__builtin_uaddl_overflow(one, two, out)
6661
# define git__multiply_sizet_overflow(out, one, two) \
6762
__builtin_umull_overflow(one, two, out)
63+
#elif (SIZE_MAX == UINT_MAX) && __has_builtin(__builtin_uadd_overflow)
64+
# define git__add_sizet_overflow(out, one, two) \
65+
__builtin_uadd_overflow(one, two, out)
66+
# define git__multiply_sizet_overflow(out, one, two) \
67+
__builtin_umul_overflow(one, two, out)
6868
#else
6969

7070
/**

src/submodule.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,7 @@ static int load_submodule_names(git_strmap *out, git_config *cfg)
188188
git_buf_put(&buf, fdot + 1, ldot - fdot - 1);
189189
git_strmap_insert(out, entry->value, git_buf_detach(&buf), rval);
190190
if (rval < 0) {
191-
giterr_set(GITERR_NOMEMORY, "Error inserting submodule into hash table");
192-
free_submodule_names(out);
191+
giterr_set(GITERR_NOMEMORY, "error inserting submodule into hash table");
193192
return -1;
194193
}
195194
}
@@ -513,12 +512,12 @@ int git_submodule__map(git_repository *repo, git_strmap *map)
513512
goto cleanup;
514513
}
515514
/* add back submodule information from index */
516-
if (idx) {
515+
if (mods && idx) {
517516
if ((error = submodules_from_index(map, idx, mods)) < 0)
518517
goto cleanup;
519518
}
520519
/* add submodule information from HEAD */
521-
if (head) {
520+
if (mods && head) {
522521
if ((error = submodules_from_head(map, head, mods)) < 0)
523522
goto cleanup;
524523
}

tests/checkout/tree.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,7 @@ void test_checkout_tree__pathlist_checkout_ignores_non_matches(void)
441441
cl_assert(git_path_exists("testrepo/link_to_new.txt"));
442442
cl_assert(git_path_exists("testrepo/new.txt"));
443443

444+
git_object_free(g_object);
444445
cl_git_pass(git_revparse_single(&g_object, g_repo, "8496071c1b46c854b31185ea97743be6a8774479"));
445446

446447
g_opts.checkout_strategy =
@@ -454,10 +455,6 @@ void test_checkout_tree__pathlist_checkout_ignores_non_matches(void)
454455
cl_assert(!git_path_exists("testrepo/branch_file.txt"));
455456
cl_assert(!git_path_exists("testrepo/link_to_new.txt"));
456457
cl_assert(git_path_exists("testrepo/new.txt"));
457-
458-
git_object_free(g_object);
459-
g_object = NULL;
460-
461458
}
462459

463460
void test_checkout_tree__can_disable_pattern_match(void)

0 commit comments

Comments
 (0)