X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=grep.c;h=92a47c71e7d93eef7dc8d6967cd071aa061218ce;hb=e064c170b4abe21f50658f2ec3b07e4ec7520767;hp=a649f063cf28baa5b0ddce72d7d6e4d9fca6f360;hpb=e05aae684d453695bc5bd1e66aa96bc7d42e186a;p=git.git diff --git a/grep.c b/grep.c index a649f063c..92a47c71e 100644 --- a/grep.c +++ b/grep.c @@ -331,7 +331,7 @@ static int match_one_pattern(struct grep_pat *p, char *bol, char *eol, if (hit && p->word_regexp) { if ((pmatch[0].rm_so < 0) || - (eol - bol) <= pmatch[0].rm_so || + (eol - bol) < pmatch[0].rm_so || (pmatch[0].rm_eo < 0) || (eol - bol) < pmatch[0].rm_eo) die("regexp returned nonsense"); @@ -350,6 +350,10 @@ static int match_one_pattern(struct grep_pat *p, char *bol, char *eol, else hit = 0; + /* Words consist of at least one character. */ + if (pmatch->rm_so == pmatch->rm_eo) + hit = 0; + if (!hit && pmatch[0].rm_so + bol + 1 < eol) { /* There could be more than one match on the * line, and the first match might not be @@ -360,6 +364,7 @@ static int match_one_pattern(struct grep_pat *p, char *bol, char *eol, bol = pmatch[0].rm_so + bol + 1; while (word_char(bol[-1]) && bol < eol) bol++; + eflags |= REG_NOTBOL; if (bol < eol) goto again; } @@ -499,6 +504,8 @@ static void show_line(struct grep_opt *opt, char *bol, char *eol, *eol = '\0'; while (next_match(opt, bol, eol, ctx, &match, eflags)) { + if (match.rm_so == match.rm_eo) + break; printf("%.*s%s%.*s%s", (int)match.rm_so, bol, opt->color_match,