Skip to content

Commit

Permalink
log: fix -L bounds checking bug
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Eric Sunshine authored and Junio C Hamano committed Aug 5, 2013
1 parent 449f5c7 commit 63828b8
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions line-log.c
Original file line number Diff line number Diff line change
Expand Up @@ -594,13 +594,13 @@ parse_lines(struct commit *commit, const char *prefix, struct string_list *args)
lines, &begin, &end,
full_name))
die("malformed -L argument '%s'", range_part);
if (lines < end || ((lines || begin) && lines < begin))
die("file %s has only %lu lines", name_part, lines);
if (begin < 1)
begin = 1;
if (end < 1)
end = lines;
begin--;
if (lines < end || lines < begin)
die("file %s has only %ld lines", name_part, lines);
line_log_data_insert(&ranges, full_name, begin, end);

free_filespec(spec);
Expand Down
2 changes: 1 addition & 1 deletion t/t4211-line-log.sh
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ test_expect_success '-L X (X == nlines)' '
git log -L $n:b.c
'

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

0 comments on commit 63828b8

Please sign in to comment.