path: root/builtin/branch.c
diff options
authorCarlos Martín Nieto <>2012-02-27 15:11:53 (GMT)
committerJunio C Hamano <>2012-02-27 19:35:33 (GMT)
commit6c41e97557d94df7085e3c0cff247305c9401968 (patch)
tree409b6b72b2a54f7d944bf573a29fef08356f2038 /builtin/branch.c
parentc524ceb12f65e2ad4fc68c9d5b39f6e4b6b5c17b (diff)
branch: don't assume the merge filter ref exists
print_ref_list looks up the merge_filter_ref and assumes that a valid pointer is returned. When the object doesn't exist, it tries to dereference a NULL pointer. This can be the case when git branch --merged is given an argument that isn't a valid commit name. Check whether the lookup returns a NULL pointer and die with an error if it does. Add a test, while we're at it. Signed-off-by: Carlos Martín Nieto <> Signed-off-by: Junio C Hamano <>
Diffstat (limited to 'builtin/branch.c')
1 files changed, 4 insertions, 0 deletions
diff --git a/builtin/branch.c b/builtin/branch.c
index df908ed..d6691af 100644
--- a/builtin/branch.c
+++ b/builtin/branch.c
@@ -528,6 +528,10 @@ static int print_ref_list(int kinds, int detached, int verbose, int abbrev, stru
if (merge_filter != NO_FILTER) {
struct commit *filter;
filter = lookup_commit_reference_gently(merge_filter_ref, 0);
+ if (!filter)
+ die("object '%s' does not point to a commit",
+ sha1_to_hex(merge_filter_ref));
filter->object.flags |= UNINTERESTING;
(struct object *) filter, "");