1
0
mirror of https://github.com/git/git synced 2024-07-05 00:58:49 +00:00

line-log: fix "log -LN" crash when N is last line of file

range-set invariants are: ranges must be (1) non-empty, (2) disjoint,
(3) sorted in ascending order.

line_log_data_insert() breaks the non-empty invariant under the
following conditions: the incoming range is empty and the pathname
attached to the range has not yet been encountered. In this case,
line_log_data_insert() assigns the empty range to a new line_log_data
record without taking any action to ensure that the empty range is
eventually folded out.  Subsequent range-set functions crash or throw an
assertion failure upon encountering such an anomaly.  Fix this bug.

Signed-off-by: Eric Sunshine <sunshine@sunshineco.com>
Acked-by: Thomas Rast <trast@inf.ethz.ch>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Eric Sunshine 2013-07-23 10:28:08 -04:00 committed by Junio C Hamano
parent f8395edc6f
commit df6308eb82
2 changed files with 2 additions and 1 deletions

View File

@ -299,6 +299,7 @@ static void line_log_data_insert(struct line_log_data **list,
p = xcalloc(1, sizeof(struct line_log_data));
p->path = path;
range_set_append(&p->ranges, begin, end);
sort_and_merge_range_set(&p->ranges);
if (ip) {
p->next = ip->next;
ip->next = p;

View File

@ -73,7 +73,7 @@ test_expect_success '-L {empty-range} (any -L)' '
git log -L1,1:b.c -L$n:b.c
'
test_expect_failure '-L {empty-range} (first -L)' '
test_expect_success '-L {empty-range} (first -L)' '
n=$(expr $(wc -l <b.c) + 1) &&
git log -L$n:b.c
'