diff --git a/grep.c b/grep.c index 940e200..d34247f 100644 --- a/grep.c +++ b/grep.c @@ -264,13 +264,14 @@ static void show_name(struct grep_opt *opt, const char *name) } -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; @@ -333,7 +334,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); @@ -646,7 +647,7 @@ static int look_ahead(struct grep_opt *opt, regmatch_t m; if (p->fixed) - hit = !fixmatch(p->pattern, bol, p->ignore_case, &m); + hit = !fixmatch(p->pattern, bol, bol + *left_p, p->ignore_case, &m); else hit = !regexec(&p->regexp, bol, 1, &m, 0); if (!hit || m.rm_so < 0 || m.rm_eo < 0)