Skip to content

Commit 683ff88

Browse files
peffgitster
authored andcommitted
use parse_commit_or_die instead of segfaulting
Some unchecked calls to parse_commit should obviously die on error, because their next step is to start looking at the parsed fields, which will cause a segfault. These are obvious candidates for parse_commit_or_die, which will be a strict improvement in behavior. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 5e7d4d3 commit 683ff88

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

builtin/checkout.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -796,7 +796,7 @@ static int switch_branches(const struct checkout_opts *opts,
796796
new->commit = old.commit;
797797
if (!new->commit)
798798
die(_("You are on a branch yet to be born"));
799-
parse_commit(new->commit);
799+
parse_commit_or_die(new->commit);
800800
}
801801

802802
ret = merge_working_tree(opts, &old, new, &writeout_error);
@@ -959,7 +959,7 @@ static int parse_branchname_arg(int argc, const char **argv,
959959
/* not a commit */
960960
*source_tree = parse_tree_indirect(rev);
961961
} else {
962-
parse_commit(new->commit);
962+
parse_commit_or_die(new->commit);
963963
*source_tree = new->commit->tree;
964964
}
965965

builtin/fast-export.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ static void handle_commit(struct commit *commit, struct rev_info *rev)
286286

287287
rev->diffopt.output_format = DIFF_FORMAT_CALLBACK;
288288

289-
parse_commit(commit);
289+
parse_commit_or_die(commit);
290290
author = strstr(commit->buffer, "\nauthor ");
291291
if (!author)
292292
die ("Could not find author in commit %s",
@@ -307,7 +307,7 @@ static void handle_commit(struct commit *commit, struct rev_info *rev)
307307
if (commit->parents &&
308308
get_object_mark(&commit->parents->item->object) != 0 &&
309309
!full_tree) {
310-
parse_commit(commit->parents->item);
310+
parse_commit_or_die(commit->parents->item);
311311
diff_tree_sha1(commit->parents->item->tree->object.sha1,
312312
commit->tree->object.sha1, "", &rev->diffopt);
313313
}

0 commit comments

Comments
 (0)