diff --git a/grep.c b/grep.c index c7e1dc1e0e..a54e5d86a9 100644 --- a/grep.c +++ b/grep.c @@ -1267,6 +1267,7 @@ static void show_line(struct grep_opt *opt, regmatch_t match; enum grep_context ctx = GREP_CONTEXT_BODY; int eflags = 0; + const char *start = bol; if (want_color(opt->color)) { if (sign == ':') @@ -1285,6 +1286,7 @@ static void show_line(struct grep_opt *opt, if (match.rm_so == match.rm_eo) break; + cno = bol - start + match.rm_so + 1; if (opt->only_matching) show_line_header(opt, name, lno, cno, sign); else @@ -1294,7 +1296,6 @@ static void show_line(struct grep_opt *opt, if (opt->only_matching) opt->output(opt, "\n", 1); bol += match.rm_eo; - cno += match.rm_eo; rest -= match.rm_eo; eflags = REG_NOTBOL; } diff --git a/t/t7810-grep.sh b/t/t7810-grep.sh index 64ac4f04ee..bd439563d6 100755 --- a/t/t7810-grep.sh +++ b/t/t7810-grep.sh @@ -322,11 +322,11 @@ do ${HC}file:1:5:mmap ${HC}file:2:5:mmap ${HC}file:3:5:mmap - ${HC}file:3:13:mmap + ${HC}file:3:14:mmap ${HC}file:4:5:mmap - ${HC}file:4:13:mmap + ${HC}file:4:14:mmap ${HC}file:5:5:mmap - ${HC}file:5:13:mmap + ${HC}file:5:14:mmap EOF git grep --column -n -o -e mmap $H >actual && test_cmp expected actual