Skip to content

Commit 63828b8

Browse files
sunshinecogitster
authored andcommitted
log: fix -L bounds checking bug
When 12da1d1 added -L support to git-log, a broken bounds check was copied from git-blame -L which incorrectly allows -LX to extend one line past end of file without reporting an error. Instead, it generates an empty range. Fix this bug. Signed-off-by: Eric Sunshine <sunshine@sunshineco.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 449f5c7 commit 63828b8

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

line-log.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -594,13 +594,13 @@ parse_lines(struct commit *commit, const char *prefix, struct string_list *args)
594594
lines, &begin, &end,
595595
full_name))
596596
die("malformed -L argument '%s'", range_part);
597+
if (lines < end || ((lines || begin) && lines < begin))
598+
die("file %s has only %lu lines", name_part, lines);
597599
if (begin < 1)
598600
begin = 1;
599601
if (end < 1)
600602
end = lines;
601603
begin--;
602-
if (lines < end || lines < begin)
603-
die("file %s has only %ld lines", name_part, lines);
604604
line_log_data_insert(&ranges, full_name, begin, end);
605605

606606
free_filespec(spec);

t/t4211-line-log.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ test_expect_success '-L X (X == nlines)' '
6969
git log -L $n:b.c
7070
'
7171

72-
test_expect_failure '-L X (X == nlines + 1)' '
72+
test_expect_success '-L X (X == nlines + 1)' '
7373
n=$(expr $(wc -l <b.c) + 1) &&
7474
test_must_fail git log -L $n:b.c
7575
'

0 commit comments

Comments
 (0)