summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 321ffcc)
raw | patch | inline | side by side (parent: 321ffcc)
author | René Scharfe <rene.scharfe@lsrfire.ath.cx> | |
Sat, 22 May 2010 21:32:43 +0000 (23:32 +0200) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Mon, 24 May 2010 18:22:06 +0000 (11:22 -0700) |
Allow searching beyond NUL characters by using memmem() instead of
strstr().
Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
strstr().
Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
grep.c | patch | blob | history | |
t/t7008-grep-binary.sh | patch | blob | history |
index 22639cde2c2ffeb4fc60a1585b88f3524dcf1c7b..c3affb6caa45d1fe037a4ddfa0456cdd991e5859 100644 (file)
--- a/grep.c
+++ b/grep.c
opt->output(opt, opt->null_following_name ? "\0" : "\n", 1);
}
-
-static int fixmatch(const char *pattern, char *line, int ignore_case, regmatch_t *match)
+static int fixmatch(const char *pattern, char *line, char *eol,
+ int ignore_case, regmatch_t *match)
{
char *hit;
+
if (ignore_case)
hit = strcasestr(line, pattern);
else
- hit = strstr(line, pattern);
+ hit = memmem(line, eol - line, pattern, strlen(pattern));
if (!hit) {
match->rm_so = match->rm_eo = -1;
again:
if (p->fixed)
- hit = !fixmatch(p->pattern, bol, p->ignore_case, pmatch);
+ hit = !fixmatch(p->pattern, bol, eol, p->ignore_case, pmatch);
else
hit = !regexec(&p->regexp, bol, 1, pmatch, eflags);
int hit;
regmatch_t m;
- if (p->fixed)
- hit = !fixmatch(p->pattern, bol, p->ignore_case, &m);
- else {
+ if (p->fixed) {
+ hit = !fixmatch(p->pattern, bol, bol + *left_p,
+ p->ignore_case, &m);
+ } else {
#ifdef REG_STARTEND
m.rm_so = 0;
m.rm_eo = *left_p;
diff --git a/t/t7008-grep-binary.sh b/t/t7008-grep-binary.sh
index 4a12d97922b34e95c1d42319361e8c02f2246a62..9adc9ed6fea197883442fa191a7dd6d42d1f785e 100755 (executable)
--- a/t/t7008-grep-binary.sh
+++ b/t/t7008-grep-binary.sh
test_cmp expect actual
'
+test_expect_success 'git grep -F ile a' '
+ git grep -F ile a
+'
+
test_done