summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRené Scharfe <rene.scharfe@lsrfire.ath.cx>2010-05-22 21:32:43 (GMT)
committerJunio C Hamano <gitster@pobox.com>2010-05-24 18:22:06 (GMT)
commit1baddf4b3781c0c714442adfda496d667e1850cd (patch)
tree988c2512300d4a574365695f5e7c54b3322c10d9
parent321ffcc0556a94c461ac84667b35494c193804ec (diff)
downloadgit-1baddf4b3781c0c714442adfda496d667e1850cd.zip
git-1baddf4b3781c0c714442adfda496d667e1850cd.tar.gz
git-1baddf4b3781c0c714442adfda496d667e1850cd.tar.bz2
grep: use memmem() for fixed string search
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>
-rw-r--r--grep.c16
-rwxr-xr-xt/t7008-grep-binary.sh4
2 files changed, 13 insertions, 7 deletions
diff --git a/grep.c b/grep.c
index 22639cd..c3affb6 100644
--- a/grep.c
+++ b/grep.c
@@ -329,14 +329,15 @@ static void show_name(struct grep_opt *opt, const char *name)
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;
@@ -399,7 +400,7 @@ static int match_one_pattern(struct grep_pat *p, char *bol, char *eol,
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);
@@ -725,9 +726,10 @@ static int look_ahead(struct grep_opt *opt,
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 4a12d97..9adc9ed 100755
--- a/t/t7008-grep-binary.sh
+++ b/t/t7008-grep-binary.sh
@@ -51,4 +51,8 @@ test_expect_success 'git grep -q ina a' '
test_cmp expect actual
'
+test_expect_success 'git grep -F ile a' '
+ git grep -F ile a
+'
+
test_done