提交 683ff884 编写于 作者: J Jeff King 提交者: Junio C Hamano

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: NJeff King <peff@peff.net>
Signed-off-by: NJunio C Hamano <gitster@pobox.com>
上级 5e7d4d3e
...@@ -796,7 +796,7 @@ static int switch_branches(const struct checkout_opts *opts, ...@@ -796,7 +796,7 @@ static int switch_branches(const struct checkout_opts *opts,
new->commit = old.commit; new->commit = old.commit;
if (!new->commit) if (!new->commit)
die(_("You are on a branch yet to be born")); die(_("You are on a branch yet to be born"));
parse_commit(new->commit); parse_commit_or_die(new->commit);
} }
ret = merge_working_tree(opts, &old, new, &writeout_error); ret = merge_working_tree(opts, &old, new, &writeout_error);
...@@ -959,7 +959,7 @@ static int parse_branchname_arg(int argc, const char **argv, ...@@ -959,7 +959,7 @@ static int parse_branchname_arg(int argc, const char **argv,
/* not a commit */ /* not a commit */
*source_tree = parse_tree_indirect(rev); *source_tree = parse_tree_indirect(rev);
} else { } else {
parse_commit(new->commit); parse_commit_or_die(new->commit);
*source_tree = new->commit->tree; *source_tree = new->commit->tree;
} }
......
...@@ -286,7 +286,7 @@ static void handle_commit(struct commit *commit, struct rev_info *rev) ...@@ -286,7 +286,7 @@ static void handle_commit(struct commit *commit, struct rev_info *rev)
rev->diffopt.output_format = DIFF_FORMAT_CALLBACK; rev->diffopt.output_format = DIFF_FORMAT_CALLBACK;
parse_commit(commit); parse_commit_or_die(commit);
author = strstr(commit->buffer, "\nauthor "); author = strstr(commit->buffer, "\nauthor ");
if (!author) if (!author)
die ("Could not find author in commit %s", die ("Could not find author in commit %s",
...@@ -307,7 +307,7 @@ static void handle_commit(struct commit *commit, struct rev_info *rev) ...@@ -307,7 +307,7 @@ static void handle_commit(struct commit *commit, struct rev_info *rev)
if (commit->parents && if (commit->parents &&
get_object_mark(&commit->parents->item->object) != 0 && get_object_mark(&commit->parents->item->object) != 0 &&
!full_tree) { !full_tree) {
parse_commit(commit->parents->item); parse_commit_or_die(commit->parents->item);
diff_tree_sha1(commit->parents->item->tree->object.sha1, diff_tree_sha1(commit->parents->item->tree->object.sha1,
commit->tree->object.sha1, "", &rev->diffopt); commit->tree->object.sha1, "", &rev->diffopt);
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册