@matheusbsbs / matheus-bagliano / commits / 45e2b61401
Fork 0

Avoid segfault with 'git branch' when the HEAD is detached

A recent addition to the ref_item struct was not taken care of, leading to a segmentation fault when accessing the (uninitialized) "dest" member. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Johannes Schindelin committed Feb 18, 2009 at 19:14 UTC 45e2b6140147d7a8b2cd68399e4d52d5d8d7b5be
1 file changed +2
builtin-branch.c
+2
@@ -432,7 +432,9 @@ static void print_ref_list(int kinds, int detached, int verbose, int abbrev, str
432 is_descendant_of(head_commit, with_commit)) {
433 struct ref_item item;
434 item.name = xstrdup("(no branch)");
435 + item.len = strlen(item.name);
436 item.kind = REF_LOCAL_BRANCH;
437 + item.dest = NULL;
438 item.commit = head_commit;
439 if (strlen(item.name) > ref_list.maxwidth)
440 ref_list.maxwidth = strlen(item.name);