Skip to content

Commit 19bca3d

Browse files
authored
Merge pull request libgit2#4922 from tiennou/fix/coverity-cids
Coverity fixes
2 parents fba70a9 + a74f4fb commit 19bca3d

File tree

6 files changed

+32
-1
lines changed

6 files changed

+32
-1
lines changed

script/user_model.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,3 +73,26 @@ int git_buf_set(git_buf *buf, const void *data, size_t len)
7373
buf->size = len + 1;
7474
return 0;
7575
}
76+
77+
void clar__fail(
78+
const char *file,
79+
int line,
80+
const char *error,
81+
const char *description,
82+
int should_abort)
83+
{
84+
if (should_abort)
85+
__coverity_panic__();
86+
}
87+
88+
void clar__assert(
89+
int condition,
90+
const char *file,
91+
int line,
92+
const char *error,
93+
const char *description,
94+
int should_abort)
95+
{
96+
if (!condition && should_abort)
97+
__coverity_panic__();
98+
}

src/config.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,8 @@ int git_config_backend_foreach_match(
513513
regex_t regex;
514514
int error = 0;
515515

516+
assert(backend && cb);
517+
516518
if (regexp != NULL) {
517519
if ((error = p_regcomp(&regex, regexp, REG_EXTENDED)) != 0) {
518520
giterr_set_regex(&regex, error);

src/diff_tform.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -816,6 +816,8 @@ int git_diff_find_similar(
816816
diff_find_match *best_match;
817817
git_diff_file swap;
818818

819+
assert(diff);
820+
819821
if ((error = normalize_find_opts(diff, &opts, given_opts)) < 0)
820822
return error;
821823

src/refs.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -709,6 +709,8 @@ int git_reference_rename(
709709
git_signature *who;
710710
int error;
711711

712+
assert(out && ref);
713+
712714
if ((error = git_reference__log_signature(&who, ref->db->repo)) < 0)
713715
return error;
714716

src/submodule.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ static int load_submodule_names(git_strmap **out, git_repository *repo, git_conf
208208
if ((error = git_config_iterator_glob_new(&iter, cfg, key)) < 0)
209209
goto out;
210210

211-
while (git_config_next(&entry, iter) == 0) {
211+
while ((error = git_config_next(&entry, iter)) == 0) {
212212
const char *fdot, *ldot;
213213
fdot = strchr(entry->name, '.');
214214
ldot = strrchr(entry->name, '.');

tests/index/crlf.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,7 @@ void test_index_crlf__safecrlf_true_autocrlf_input_text_auto_attr(void)
353353

354354
cl_git_pass(git_index_add_bypath(g_index, "newfile.txt"));
355355
entry = git_index_get_bypath(g_index, "newfile.txt", 0);
356+
cl_assert(entry);
356357

357358
cl_git_pass(git_oid_fromstr(&oid, FILE_OID_LF));
358359
cl_assert_equal_oid(&oid, &entry->id);
@@ -373,6 +374,7 @@ void test_index_crlf__safecrlf_true_autocrlf_input_text__no_attr(void)
373374

374375
cl_git_pass(git_index_add_bypath(g_index, "newfile.txt"));
375376
entry = git_index_get_bypath(g_index, "newfile.txt", 0);
377+
cl_assert(entry);
376378

377379
cl_git_pass(git_oid_fromstr(&oid, FILE_OID_LF));
378380
cl_assert_equal_oid(&oid, &entry->id);

0 commit comments

Comments
 (0)