Merge pull request #4922 from tiennou/fix/coverity-cids Coverity 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
diff --git a/script/user_model.c b/script/user_model.c
index a933d73..4942527 100644
--- a/script/user_model.c
+++ b/script/user_model.c
@@ -73,3 +73,26 @@ int git_buf_set(git_buf *buf, const void *data, size_t len)
buf->size = len + 1;
return 0;
}
+
+void clar__fail(
+ const char *file,
+ int line,
+ const char *error,
+ const char *description,
+ int should_abort)
+{
+ if (should_abort)
+ __coverity_panic__();
+}
+
+void clar__assert(
+ int condition,
+ const char *file,
+ int line,
+ const char *error,
+ const char *description,
+ int should_abort)
+{
+ if (!condition && should_abort)
+ __coverity_panic__();
+}
diff --git a/src/config.c b/src/config.c
index 569b69f..30d9730 100644
--- a/src/config.c
+++ b/src/config.c
@@ -513,6 +513,8 @@ int git_config_backend_foreach_match(
regex_t regex;
int error = 0;
+ assert(backend && cb);
+
if (regexp != NULL) {
if ((error = p_regcomp(®ex, regexp, REG_EXTENDED)) != 0) {
giterr_set_regex(®ex, error);
diff --git a/src/diff_tform.c b/src/diff_tform.c
index 8c5abbf..3a8924d 100644
--- a/src/diff_tform.c
+++ b/src/diff_tform.c
@@ -816,6 +816,8 @@ int git_diff_find_similar(
diff_find_match *best_match;
git_diff_file swap;
+ assert(diff);
+
if ((error = normalize_find_opts(diff, &opts, given_opts)) < 0)
return error;
diff --git a/src/refs.c b/src/refs.c
index 50afb26..85599da 100644
--- a/src/refs.c
+++ b/src/refs.c
@@ -709,6 +709,8 @@ int git_reference_rename(
git_signature *who;
int error;
+ assert(out && ref);
+
if ((error = git_reference__log_signature(&who, ref->db->repo)) < 0)
return error;
diff --git a/src/submodule.c b/src/submodule.c
index f52b658..c468a96 100644
--- a/src/submodule.c
+++ b/src/submodule.c
@@ -208,7 +208,7 @@ static int load_submodule_names(git_strmap **out, git_repository *repo, git_conf
if ((error = git_config_iterator_glob_new(&iter, cfg, key)) < 0)
goto out;
- while (git_config_next(&entry, iter) == 0) {
+ while ((error = git_config_next(&entry, iter)) == 0) {
const char *fdot, *ldot;
fdot = strchr(entry->name, '.');
ldot = strrchr(entry->name, '.');
diff --git a/tests/index/crlf.c b/tests/index/crlf.c
index 31050f8..ddf01fe 100644
--- a/tests/index/crlf.c
+++ b/tests/index/crlf.c
@@ -353,6 +353,7 @@ void test_index_crlf__safecrlf_true_autocrlf_input_text_auto_attr(void)
cl_git_pass(git_index_add_bypath(g_index, "newfile.txt"));
entry = git_index_get_bypath(g_index, "newfile.txt", 0);
+ cl_assert(entry);
cl_git_pass(git_oid_fromstr(&oid, FILE_OID_LF));
cl_assert_equal_oid(&oid, &entry->id);
@@ -373,6 +374,7 @@ void test_index_crlf__safecrlf_true_autocrlf_input_text__no_attr(void)
cl_git_pass(git_index_add_bypath(g_index, "newfile.txt"));
entry = git_index_get_bypath(g_index, "newfile.txt", 0);
+ cl_assert(entry);
cl_git_pass(git_oid_fromstr(&oid, FILE_OID_LF));
cl_assert_equal_oid(&oid, &entry->id);