From 1f5b9cc40e80a8a7902236a26844be138887b1d9 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Ren=C3=A9=20Scharfe?= Date: Mon, 1 Jun 2009 23:53:05 +0200 Subject: [PATCH] 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 Signed-off-by: Junio C Hamano --- grep.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/grep.c b/grep.c index cc6d5b04c..7bf4a60ac 100644 --- 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, -- 2.30.2