aboutsummaryrefslogtreecommitdiff
path: root/sequencer.c
diff options
context:
space:
mode:
authorNeil Horman <nhorman@tuxdriver.com>2012-05-03 08:10:22 -0400
committerJunio C Hamano <gitster@pobox.com>2012-05-03 15:41:35 -0700
commit4b580061b350ae9d27ab7c3936a45828a33624c6 (patch)
tree2a1bf8aca353514402c77d72f61047562a90e34c /sequencer.c
parent90e1818f9a06015159712e204dd90868e0a6c421 (diff)
downloadgit-4b580061b350ae9d27ab7c3936a45828a33624c6.tar.gz
git-4b580061b350ae9d27ab7c3936a45828a33624c6.tar.xz
git cherry-pick: do not dereference a potential NULL pointer
In the case the pointer could be NULL, the function that gave the caller the NULL pointer would already have issued an error message, so simply returning early with an error status without issuing a new message is sufficient. The same for parse_commit() that will show necessary error message when the argument is not NULL, and will return error silently when the argument is NULL. Noticed-by: Michael Mueller Signed-off-by: Neil Horman <nhorman@tuxdriver.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'sequencer.c')
-rw-r--r--sequencer.c14
1 files changed, 11 insertions, 3 deletions
diff --git a/sequencer.c b/sequencer.c
index 4e3af8244..72cb4ff82 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -261,9 +261,17 @@ static int is_index_unchanged(void)
return error(_("Could not resolve HEAD commit\n"));
head_commit = lookup_commit(head_sha1);
- if (!head_commit || parse_commit(head_commit))
- return error(_("could not parse commit %s\n"),
- sha1_to_hex(head_commit->object.sha1));
+
+ /*
+ * If head_commit is NULL, check_commit, called from
+ * lookup_commit, would have indicated that head_commit is not
+ * a commit object already. parse_commit() will return failure
+ * without further complaints in such a case. Otherwise, if
+ * the commit is invalid, parse_commit() will complain. So
+ * there is nothing for us to say here. Just return failure.
+ */
+ if (parse_commit(head_commit))
+ return -1;
if (!active_cache_tree)
active_cache_tree = cache_tree();