Merge pull request #4086 from libgit2/ethomson/fixes WIP: some coverity & compiler warning fixes
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
diff --git a/src/attrcache.c b/src/attrcache.c
index 0ade38c..cf0707e 100644
--- a/src/attrcache.c
+++ b/src/attrcache.c
@@ -121,20 +121,22 @@ static int attr_cache_remove(git_attr_cache *cache, git_attr_file *file)
{
int error = 0;
git_attr_file_entry *entry;
+ git_attr_file *old = NULL;
if (!file)
return 0;
+
if ((error = attr_cache_lock(cache)) < 0)
return error;
if ((entry = attr_cache_lookup_entry(cache, file->entry->path)) != NULL)
- file = git__compare_and_swap(&entry->file[file->source], file, NULL);
+ old = git__compare_and_swap(&entry->file[file->source], file, NULL);
attr_cache_unlock(cache);
- if (file) {
- GIT_REFCOUNT_OWN(file, NULL);
- git_attr_file__free(file);
+ if (old) {
+ GIT_REFCOUNT_OWN(old, NULL);
+ git_attr_file__free(old);
}
return error;
diff --git a/src/integer.h b/src/integer.h
index b08094c..61712ce 100644
--- a/src/integer.h
+++ b/src/integer.h
@@ -55,16 +55,16 @@ GIT_INLINE(bool) git__add_uint64_overflow(uint64_t *out, uint64_t one, uint64_t
}
/* Use clang/gcc compiler intrinsics whenever possible */
-#if (SIZE_MAX == UINT_MAX) && __has_builtin(__builtin_uadd_overflow)
-# define git__add_sizet_overflow(out, one, two) \
- __builtin_uadd_overflow(one, two, out)
-# define git__multiply_sizet_overflow(out, one, two) \
- __builtin_umul_overflow(one, two, out)
-#elif (SIZE_MAX == ULONG_MAX) && __has_builtin(__builtin_uaddl_overflow)
+#if (SIZE_MAX == ULONG_MAX) && __has_builtin(__builtin_uaddl_overflow)
# define git__add_sizet_overflow(out, one, two) \
__builtin_uaddl_overflow(one, two, out)
# define git__multiply_sizet_overflow(out, one, two) \
__builtin_umull_overflow(one, two, out)
+#elif (SIZE_MAX == UINT_MAX) && __has_builtin(__builtin_uadd_overflow)
+# define git__add_sizet_overflow(out, one, two) \
+ __builtin_uadd_overflow(one, two, out)
+# define git__multiply_sizet_overflow(out, one, two) \
+ __builtin_umul_overflow(one, two, out)
#else
/**
diff --git a/src/submodule.c b/src/submodule.c
index e1f59b8..fc3dcb4 100644
--- a/src/submodule.c
+++ b/src/submodule.c
@@ -188,8 +188,7 @@ static int load_submodule_names(git_strmap *out, git_config *cfg)
git_buf_put(&buf, fdot + 1, ldot - fdot - 1);
git_strmap_insert(out, entry->value, git_buf_detach(&buf), rval);
if (rval < 0) {
- giterr_set(GITERR_NOMEMORY, "Error inserting submodule into hash table");
- free_submodule_names(out);
+ giterr_set(GITERR_NOMEMORY, "error inserting submodule into hash table");
return -1;
}
}
@@ -513,12 +512,12 @@ int git_submodule__map(git_repository *repo, git_strmap *map)
goto cleanup;
}
/* add back submodule information from index */
- if (idx) {
+ if (mods && idx) {
if ((error = submodules_from_index(map, idx, mods)) < 0)
goto cleanup;
}
/* add submodule information from HEAD */
- if (head) {
+ if (mods && head) {
if ((error = submodules_from_head(map, head, mods)) < 0)
goto cleanup;
}
diff --git a/tests/checkout/tree.c b/tests/checkout/tree.c
index c9581fd..b3b860c 100644
--- a/tests/checkout/tree.c
+++ b/tests/checkout/tree.c
@@ -441,6 +441,7 @@ void test_checkout_tree__pathlist_checkout_ignores_non_matches(void)
cl_assert(git_path_exists("testrepo/link_to_new.txt"));
cl_assert(git_path_exists("testrepo/new.txt"));
+ git_object_free(g_object);
cl_git_pass(git_revparse_single(&g_object, g_repo, "8496071c1b46c854b31185ea97743be6a8774479"));
g_opts.checkout_strategy =
@@ -454,10 +455,6 @@ void test_checkout_tree__pathlist_checkout_ignores_non_matches(void)
cl_assert(!git_path_exists("testrepo/branch_file.txt"));
cl_assert(!git_path_exists("testrepo/link_to_new.txt"));
cl_assert(git_path_exists("testrepo/new.txt"));
-
- git_object_free(g_object);
- g_object = NULL;
-
}
void test_checkout_tree__can_disable_pattern_match(void)