Skip to content

Commit 52d799a

Browse files
René Scharfegitster
René Scharfe
authored andcommitted
grep: continue case insensitive fixed string search after NUL chars
Functions for C strings, like strcasestr(), can't see beyond NUL characters. Check if there is such an obstacle on the line and try again behind it. Signed-off-by: Rene Scharfe <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 1baddf4 commit 52d799a

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

grep.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -334,9 +334,15 @@ static int fixmatch(const char *pattern, char *line, char *eol,
334334
{
335335
char *hit;
336336

337-
if (ignore_case)
338-
hit = strcasestr(line, pattern);
339-
else
337+
if (ignore_case) {
338+
char *s = line;
339+
do {
340+
hit = strcasestr(s, pattern);
341+
if (hit)
342+
break;
343+
s += strlen(s) + 1;
344+
} while (s < eol);
345+
} else
340346
hit = memmem(line, eol - line, pattern, strlen(pattern));
341347

342348
if (!hit) {

t/t7008-grep-binary.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,8 @@ test_expect_success 'git grep -F ile a' '
5555
git grep -F ile a
5656
'
5757

58+
test_expect_success 'git grep -Fi iLE a' '
59+
git grep -Fi iLE a
60+
'
61+
5862
test_done

0 commit comments

Comments
 (0)