Browse Source

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>
maint
Johannes Schindelin 16 years ago committed by Junio C Hamano
parent
commit
45e2b61401
  1. 2
      builtin-branch.c

2
builtin-branch.c

@ -432,7 +432,9 @@ static void print_ref_list(int kinds, int detached, int verbose, int abbrev, str @@ -432,7 +432,9 @@ static void print_ref_list(int kinds, int detached, int verbose, int abbrev, str
is_descendant_of(head_commit, with_commit)) {
struct ref_item item;
item.name = xstrdup("(no branch)");
item.len = strlen(item.name);
item.kind = REF_LOCAL_BRANCH;
item.dest = NULL;
item.commit = head_commit;
if (strlen(item.name) > ref_list.maxwidth)
ref_list.maxwidth = strlen(item.name);

Loading…
Cancel
Save