Skip to content

Commit 7e53e8c

Browse files
authored
Merge pull request libgit2#4167 from pks-t/pks/ci-fixes
Coverity fixes
2 parents 69d0b46 + e733001 commit 7e53e8c

File tree

6 files changed

+26
-12
lines changed

6 files changed

+26
-12
lines changed

src/blame_git.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -478,21 +478,24 @@ static git_blame__origin* find_origin(
478478
* The blobs of origin and porigin exactly match, so everything origin is
479479
* suspected for can be blamed on the parent.
480480
*/
481-
static void pass_whole_blame(git_blame *blame,
481+
static int pass_whole_blame(git_blame *blame,
482482
git_blame__origin *origin, git_blame__origin *porigin)
483483
{
484484
git_blame__entry *e;
485485

486-
if (!porigin->blob)
487-
git_object_lookup((git_object**)&porigin->blob, blame->repository,
488-
git_blob_id(origin->blob), GIT_OBJ_BLOB);
486+
if (!porigin->blob &&
487+
git_object_lookup((git_object**)&porigin->blob, blame->repository,
488+
git_blob_id(origin->blob), GIT_OBJ_BLOB) < 0)
489+
return -1;
489490
for (e=blame->ent; e; e=e->next) {
490491
if (!same_suspect(e->suspect, origin))
491492
continue;
492493
origin_incref(porigin);
493494
origin_decref(e->suspect);
494495
e->suspect = porigin;
495496
}
497+
498+
return 0;
496499
}
497500

498501
static int pass_blame(git_blame *blame, git_blame__origin *origin, uint32_t opt)
@@ -543,7 +546,8 @@ static int pass_blame(git_blame *blame, git_blame__origin *origin, uint32_t opt)
543546
}
544547
if (porigin->blob && origin->blob &&
545548
!git_oid_cmp(git_blob_id(porigin->blob), git_blob_id(origin->blob))) {
546-
pass_whole_blame(blame, origin, porigin);
549+
error = pass_whole_blame(blame, origin, porigin);
550+
goto finish;
547551
origin_decref(porigin);
548552
goto finish;
549553
}

src/config_file.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1041,8 +1041,9 @@ static int parse_section_header_ext(struct reader *reader, const char *line, con
10411041
GITERR_CHECK_ALLOC_ADD(&alloc_len, base_name_len, quoted_len);
10421042
GITERR_CHECK_ALLOC_ADD(&alloc_len, alloc_len, 2);
10431043

1044-
git_buf_grow(&buf, alloc_len);
1045-
git_buf_printf(&buf, "%s.", base_name);
1044+
if (git_buf_grow(&buf, alloc_len) < 0 ||
1045+
git_buf_printf(&buf, "%s.", base_name) < 0)
1046+
goto end_parse;
10461047

10471048
rpos = 0;
10481049

@@ -1082,6 +1083,11 @@ static int parse_section_header_ext(struct reader *reader, const char *line, con
10821083
} while (line + rpos < last_quote);
10831084

10841085
end_parse:
1086+
if (git_buf_oom(&buf)) {
1087+
git_buf_free(&buf);
1088+
return -1;
1089+
}
1090+
10851091
if (line[rpos] != '"' || line[rpos + 1] != ']') {
10861092
set_parse_error(reader, rpos, "Unexpected text after closing quotes");
10871093
git_buf_free(&buf);

src/diff_parse.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,11 @@ static git_diff_parsed *diff_parsed_alloc(void)
4444
diff->base.patch_fn = git_patch_parsed_from_diff;
4545
diff->base.free_fn = diff_parsed_free;
4646

47-
git_diff_init_options(&diff->base.opts, GIT_DIFF_OPTIONS_VERSION);
47+
if (git_diff_init_options(&diff->base.opts, GIT_DIFF_OPTIONS_VERSION) < 0) {
48+
git__free(&diff);
49+
return NULL;
50+
}
51+
4852
diff->base.opts.flags &= ~GIT_DIFF_IGNORE_CASE;
4953

5054
git_pool_init(&diff->base.pool, 1);

src/odb_pack.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ static int pack_backend__read_prefix(
428428
git_oid_cpy(out_oid, short_oid);
429429
} else {
430430
struct git_pack_entry e;
431-
git_rawobj raw;
431+
git_rawobj raw = {NULL};
432432

433433
if ((error = pack_entry_find_prefix(
434434
&e, (struct pack_backend *)backend, short_oid, len)) == 0 &&

src/openssl_stream.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ static void shutdown_ssl_locking(void)
6666
CRYPTO_set_locking_callback(NULL);
6767

6868
for (i = 0; i < num_locks; ++i)
69-
git_mutex_free(openssl_locks);
69+
git_mutex_free(&openssl_locks[i]);
7070
git__free(openssl_locks);
7171
}
7272

src/patch_parse.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -444,9 +444,9 @@ static int parse_header_git(
444444
goto done;
445445

446446
parse_advance_ws(ctx);
447-
parse_advance_expected_str(ctx, "\n");
448447

449-
if (ctx->line_len > 0) {
448+
if (parse_advance_expected_str(ctx, "\n") < 0 ||
449+
ctx->line_len > 0) {
450450
error = parse_err("trailing data at line %"PRIuZ, ctx->line_num);
451451
goto done;
452452
}

0 commit comments

Comments
 (0)