Skip to content

Commit

Permalink
grep: fix word-regexp colouring
Browse files Browse the repository at this point in the history
As noticed by Dmitry Gryazin: When a pattern is found but it doesn't
start and end at word boundaries, bol is forwarded to after the match and
the pattern is searched again.  When a pattern is finally found between
word boundaries, the match offsets are off by the number of characters
that have been skipped.

This patch corrects the offsets to be relative to the value of bol as
passed to match_one_pattern() by its caller.

Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
René Scharfe authored and Junio C Hamano committed May 21, 2009
1 parent 8dfb17e commit e701fad
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions grep.c
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,7 @@ static int match_one_pattern(struct grep_pat *p, char *bol, char *eol,
{
int hit = 0;
int saved_ch = 0;
const char *start = bol;

if ((p->token != GREP_PATTERN) &&
((p->token == GREP_PATTERN_HEAD) != (ctx == GREP_CONTEXT_HEAD)))
Expand Down Expand Up @@ -365,6 +366,10 @@ static int match_one_pattern(struct grep_pat *p, char *bol, char *eol,
}
if (p->token == GREP_PATTERN_HEAD && saved_ch)
*eol = saved_ch;
if (hit) {
pmatch[0].rm_so += bol - start;
pmatch[0].rm_eo += bol - start;
}
return hit;
}

Expand Down

0 comments on commit e701fad

Please sign in to comment.