@matheusbsbs / matheus-bagliano / commits / 52d799a79f
Fork 0

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 <rene.scharfe@lsrfire.ath.cx> Signed-off-by: Junio C Hamano <gitster@pobox.com>

René Scharfe committed May 22, 2010 at 23:34 UTC 52d799a79f921cc47823a0455b0e646636410b65
2 files changed +13 -3
grep.c
+9 -3
@@ -334,9 +334,15 @@ static int fixmatch(const char *pattern, char *line, char *eol,
334 {
335 char *hit;
336
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
346 hit = memmem(line, eol - line, pattern, strlen(pattern));
347
348 if (!hit) {
t/t7008-grep-binary.sh
+4
@@ -55,4 +55,8 @@ test_expect_success 'git grep -F ile a' '
55 git grep -F ile a
56 '
57
58 +test_expect_success 'git grep -Fi iLE a' '
59 + git grep -Fi iLE a
60 +'
61 +
62 test_done