Skip to content

Commit e701fad

Browse files
René Scharfegitster
authored andcommitted
grep: fix word-regexp colouring
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 8dfb17e commit e701fad

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

grep.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,7 @@ static int match_one_pattern(struct grep_pat *p, char *bol, char *eol,
305305
{
306306
int hit = 0;
307307
int saved_ch = 0;
308+
const char *start = bol;
308309

309310
if ((p->token != GREP_PATTERN) &&
310311
((p->token == GREP_PATTERN_HEAD) != (ctx == GREP_CONTEXT_HEAD)))
@@ -365,6 +366,10 @@ static int match_one_pattern(struct grep_pat *p, char *bol, char *eol,
365366
}
366367
if (p->token == GREP_PATTERN_HEAD && saved_ch)
367368
*eol = saved_ch;
369+
if (hit) {
370+
pmatch[0].rm_so += bol - start;
371+
pmatch[0].rm_eo += bol - start;
372+
}
368373
return hit;
369374
}
370375

0 commit comments

Comments
 (0)