Skip to content

Commit

Permalink
line-log: fix crash when --first-parent is used
Browse files Browse the repository at this point in the history
line-log tries to access all parents of a commit, but only the first
parent has been loaded if "--first-parent" is specified, resulting
in a crash.

Limit the number of parents to one if "--first-parent" is specified.

Reported-by: Eric N. Vander Weele <ericvw@gmail.com>
Signed-off-by: Tzvetan Mikov <tmikov@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Tzvetan Mikov authored and Junio C Hamano committed Nov 4, 2014
1 parent 1762224 commit a8787c5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
3 changes: 3 additions & 0 deletions line-log.c
Original file line number Diff line number Diff line change
Expand Up @@ -1164,6 +1164,9 @@ static int process_ranges_merge_commit(struct rev_info *rev, struct commit *comm
int i;
int nparents = count_parents(commit);

if (nparents > 1 && rev->first_parent_only)
nparents = 1;

diffqueues = xmalloc(nparents * sizeof(*diffqueues));
cand = xmalloc(nparents * sizeof(*cand));
parents = xmalloc(nparents * sizeof(*parents));
Expand Down
5 changes: 5 additions & 0 deletions t/t4211-line-log.sh
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,9 @@ test_expect_success '-L {empty-range} (first -L)' '
git log -L$n:b.c
'

test_expect_success '-L with --first-parent and a merge' '
git checkout parallel-change &&
git log --first-parent -L 1,1:b.c
'

test_done

0 comments on commit a8787c5

Please sign in to comment.