Code

grep: fix colouring of matches with zero length
authorRené Scharfe <rene.scharfe@lsrfire.ath.cx>
Mon, 1 Jun 2009 21:53:05 +0000 (23:53 +0200)
committerJunio C Hamano <gitster@pobox.com>
Tue, 2 Jun 2009 05:30:39 +0000 (22:30 -0700)
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>
grep.c

diff --git a/grep.c b/grep.c
index cc6d5b04c15b670c55bdb9e2089e0b71f72453cc..7bf4a60ac7704e16abe9054296c1e0e77c984344 100644 (file)
--- a/grep.c
+++ b/grep.c
@@ -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,