Skip to content

Commit 1f5b9cc

Browse files
René Scharfegitster
authored andcommitted
grep: fix colouring of matches with zero length
If a zero-length match is encountered, break out of loop and show the rest of the line uncoloured. Otherwise we'd be looping forever, trying to make progress by advancing the pointer by zero characters. Signed-off-by: Rene Scharfe <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent dbb6a4a commit 1f5b9cc

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

grep.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,8 @@ static void show_line(struct grep_opt *opt, char *bol, char *eol,
500500

501501
*eol = '\0';
502502
while (next_match(opt, bol, eol, ctx, &match, eflags)) {
503+
if (match.rm_so == match.rm_eo)
504+
break;
503505
printf("%.*s%s%.*s%s",
504506
(int)match.rm_so, bol,
505507
opt->color_match,

0 commit comments

Comments
 (0)