Skip to content

Commit

Permalink
grep: fix colouring of matches with zero length
Browse files Browse the repository at this point in the history
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 <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 Jun 2, 2009
1 parent dbb6a4a commit 1f5b9cc
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions grep.c
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,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,
Expand Down

0 comments on commit 1f5b9cc

Please sign in to comment.