]> rtime.felk.cvut.cz Git - git.git/commitdiff
grep: continue case insensitive fixed string search after NUL chars
authorRené Scharfe <rene.scharfe@lsrfire.ath.cx>
Sat, 22 May 2010 21:34:06 +0000 (23:34 +0200)
committerJunio C Hamano <gitster@pobox.com>
Mon, 24 May 2010 18:22:07 +0000 (11:22 -0700)
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>
grep.c
t/t7008-grep-binary.sh

diff --git a/grep.c b/grep.c
index c3affb6caa45d1fe037a4ddfa0456cdd991e5859..b95803bbb19a9094dae1d84b214ed04005ab9019 100644 (file)
--- a/grep.c
+++ b/grep.c
@@ -334,9 +334,15 @@ static int fixmatch(const char *pattern, char *line, char *eol,
 {
        char *hit;
 
-       if (ignore_case)
-               hit = strcasestr(line, pattern);
-       else
+       if (ignore_case) {
+               char *s = line;
+               do {
+                       hit = strcasestr(s, pattern);
+                       if (hit)
+                               break;
+                       s += strlen(s) + 1;
+               } while (s < eol);
+       } else
                hit = memmem(line, eol - line, pattern, strlen(pattern));
 
        if (!hit) {
index 9adc9ed6fea197883442fa191a7dd6d42d1f785e..9660842c446f78b4b35fa9162235753a85eeee9f 100755 (executable)
@@ -55,4 +55,8 @@ test_expect_success 'git grep -F ile a' '
        git grep -F ile a
 '
 
+test_expect_success 'git grep -Fi iLE a' '
+       git grep -Fi iLE a
+'
+
 test_done