Skip to content

Commit 18003a8

Browse files
committed
Merge branch 'coverity-fixes-null-safety' into HEAD
2 parents b82656d + 38466f1 commit 18003a8

11 files changed

Lines changed: 43 additions & 14 deletions

File tree

builtin/bisect.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -660,6 +660,11 @@ static int bisect_successful(struct bisect_terms *terms)
660660

661661
refs_read_ref(get_main_ref_store(the_repository), bad_ref, &oid);
662662
commit = lookup_commit_reference_by_name(bad_ref);
663+
if (!commit) {
664+
res = error(_("could not find commit for '%s'"), bad_ref);
665+
free(bad_ref);
666+
return res;
667+
}
663668
repo_format_commit_message(the_repository, commit, "%s", &commit_name,
664669
&pp);
665670

@@ -803,9 +808,11 @@ static enum bisect_error bisect_start(struct bisect_terms *terms, int argc,
803808
*/
804809
head = refs_resolve_ref_unsafe(get_main_ref_store(the_repository),
805810
"HEAD", 0, &head_oid, &flags);
806-
if (!head)
811+
if (!head) {
807812
if (repo_get_oid(the_repository, "HEAD", &head_oid))
808813
return error(_("bad HEAD - I need a HEAD"));
814+
head = "HEAD";
815+
}
809816

810817
/*
811818
* Check if we are bisecting

builtin/diff.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -579,9 +579,13 @@ int cmd_diff(int argc,
579579
obj = deref_tag(the_repository, obj, NULL, 0);
580580
if (!obj)
581581
die(_("invalid object '%s' given."), name);
582-
if (obj->type == OBJ_COMMIT)
583-
obj = &repo_get_commit_tree(the_repository,
584-
((struct commit *)obj))->object;
582+
if (obj->type == OBJ_COMMIT) {
583+
struct tree *tree = repo_get_commit_tree(
584+
the_repository, (struct commit *)obj);
585+
if (!tree)
586+
die(_("unable to read tree object for commit '%s'"), name);
587+
obj = &tree->object;
588+
}
585589

586590
if (obj->type == OBJ_TREE) {
587591
if (sdiff.skip && bitmap_get(sdiff.skip, i))

builtin/mailsplit.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -225,14 +225,14 @@ static int split_mbox(const char *file, const char *dir, int allow_bare,
225225
FILE *f = !strcmp(file, "-") ? stdin : fopen(file, "r");
226226
int file_done = 0;
227227

228-
if (isatty(fileno(f)))
229-
warning(_("reading patches from stdin/tty..."));
230-
231228
if (!f) {
232229
error_errno("cannot open mbox %s", file);
233230
goto out;
234231
}
235232

233+
if (isatty(fileno(f)))
234+
warning(_("reading patches from stdin/tty..."));
235+
236236
do {
237237
peek = fgetc(f);
238238
if (peek == EOF) {

diffcore-break.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,8 @@ void diffcore_merge_broken(void)
289289
*/
290290
for (j = i + 1; j < q->nr; j++) {
291291
struct diff_filepair *pp = q->queue[j];
292+
if (!pp)
293+
continue;
292294
if (pp->broken_pair &&
293295
!strcmp(pp->one->path, pp->two->path) &&
294296
!strcmp(p->one->path, pp->two->path)) {

http-push.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1829,7 +1829,7 @@ int cmd_main(int argc, const char **argv)
18291829

18301830
/* Remove a remote branch if -d or -D was specified */
18311831
if (delete_branch) {
1832-
const char *branch = rs.items[i].src;
1832+
const char *branch = rs.items[0].src;
18331833
if (delete_remote_branch(branch, force_delete) == -1) {
18341834
fprintf(stderr, "Unable to delete remote branch %s\n",
18351835
branch);

pack-bitmap.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,10 @@ static int open_midx_bitmap_1(struct bitmap_index *bitmap_git,
523523

524524
if (midx->base_midx) {
525525
bitmap_git->base = prepare_midx_bitmap_git(midx->base_midx);
526+
if (!bitmap_git->base) {
527+
warning(_("could not open bitmap for base MIDX"));
528+
goto cleanup;
529+
}
526530
bitmap_git->base_nr = bitmap_git->base->base_nr + 1;
527531
} else {
528532
bitmap_git->base_nr = 0;

reftable/stack.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,8 @@ void reftable_stack_destroy(struct reftable_stack *st)
171171
st->merged = NULL;
172172
}
173173

174-
err = read_lines(st->list_file, &names);
174+
if (st->list_file)
175+
err = read_lines(st->list_file, &names);
175176
if (err < 0) {
176177
REFTABLE_FREE_AND_NULL(names);
177178
}

remote.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2633,6 +2633,8 @@ static int remote_tracking(struct remote *remote, const char *refname,
26332633
{
26342634
char *dst;
26352635

2636+
if (!remote)
2637+
return -1; /* no remote to look up tracking ref */
26362638
dst = apply_refspecs(&remote->fetch, refname);
26372639
if (!dst)
26382640
return -1; /* no tracking ref for refname at remote */

replay.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,16 @@ static struct commit *peel_committish(struct repository *repo,
3636
{
3737
struct object *obj;
3838
struct object_id oid;
39+
struct commit *commit;
3940

4041
if (repo_get_oid(repo, name, &oid))
4142
die(_("'%s' is not a valid commit-ish for %s"), name, mode);
4243
obj = parse_object_or_die(repo, &oid, name);
43-
return (struct commit *)repo_peel_to_type(repo, name, 0, obj,
44-
OBJ_COMMIT);
44+
commit = (struct commit *)repo_peel_to_type(repo, name, 0, obj,
45+
OBJ_COMMIT);
46+
if (!commit)
47+
die(_("'%s' does not point to a commit for %s"), name, mode);
48+
return commit;
4549
}
4650

4751
static char *get_author(const char *message)

revision.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1903,8 +1903,13 @@ static int add_parents_only(struct rev_info *revs, const char *arg_, int flags,
19031903
return 0;
19041904
while (1) {
19051905
it = get_reference(revs, arg, &oid, 0);
1906-
if (!it && revs->ignore_missing)
1907-
return 0;
1906+
if (!it) {
1907+
if (revs->ignore_missing)
1908+
return 0;
1909+
if (revs->do_not_die_on_missing_objects)
1910+
return 0;
1911+
return -1;
1912+
}
19081913
if (it->type != OBJ_TAG)
19091914
break;
19101915
if (!((struct tag*)it)->tagged)

0 commit comments

Comments
 (0)