Skip to content

Commit

Permalink
Merge branch 'jc/maint-1.6.4-show-branch-default' into maint
Browse files Browse the repository at this point in the history
* jc/maint-1.6.4-show-branch-default:
  show-branch: fix segfault when showbranch.default exists
  • Loading branch information
Junio C Hamano committed Oct 4, 2009
2 parents bb8cccd + 3af1cae commit 04ce83e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
14 changes: 11 additions & 3 deletions builtin-show-branch.c
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,15 @@ static int git_show_branch_config(const char *var, const char *value, void *cb)
if (!strcmp(var, "showbranch.default")) {
if (!value)
return config_error_nonbool(var);
if (default_alloc <= default_num + 1) {
/*
* default_arg is now passed to parse_options(), so we need to
* mimick the real argv a bit better.
*/
if (!default_num) {
default_alloc = 20;
default_arg = xcalloc(default_alloc, sizeof(*default_arg));
default_arg[default_num++] = "show-branch";
} else if (default_alloc <= default_num + 1) {
default_alloc = default_alloc * 3 / 2 + 20;
default_arg = xrealloc(default_arg, sizeof *default_arg * default_alloc);
}
Expand Down Expand Up @@ -692,8 +700,8 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)

/* If nothing is specified, try the default first */
if (ac == 1 && default_num) {
ac = default_num + 1;
av = default_arg - 1; /* ick; we would not address av[0] */
ac = default_num;
av = default_arg;
}

ac = parse_options(ac, av, prefix, builtin_show_branch_options,
Expand Down
8 changes: 8 additions & 0 deletions t/t3202-show-branch-octopus.sh
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,12 @@ test_expect_success 'show-branch with more than 8 branches' '
'

test_expect_success 'show-branch with showbranch.default' '
for i in $numbers; do
git config --add showbranch.default branch$i
done &&
git show-branch >out &&
test_cmp expect out
'

test_done

0 comments on commit 04ce83e

Please sign in to comment.