diff options
author | Ed Maste <emaste@FreeBSD.org> | 2017-04-17 14:59:55 +0000 |
---|---|---|
committer | Ed Maste <emaste@FreeBSD.org> | 2017-04-17 14:59:55 +0000 |
commit | e06ffa3230233063a08f8647c5f03642d367c65b (patch) | |
tree | acbe52a668b20ab2c771047fa068ee69f4b8bbf1 /usr.bin/grep | |
parent | 22130a21baef0618a624393f5b792d0867210348 (diff) | |
download | src-e06ffa3230233063a08f8647c5f03642d367c65b.tar.gz src-e06ffa3230233063a08f8647c5f03642d367c65b.zip |
bsdgrep: fix zero-length matches without the -o flag
r316477 broke zero-length matches when not using the -o flag, by
skipping over them entirely.
Add a regression test so that it doesn't break again in the future.
Submitted by: Kyle Evans <kevans91 at ksu.edu>
Reviewed by: cem emaste ngie
Differential Revision: https://reviews.freebsd.org/D10333
Notes
Notes:
svn path=/head/; revision=317052
Diffstat (limited to 'usr.bin/grep')
-rw-r--r-- | usr.bin/grep/util.c | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/usr.bin/grep/util.c b/usr.bin/grep/util.c index 19e0ac8351ec..285f88364d3f 100644 --- a/usr.bin/grep/util.c +++ b/usr.bin/grep/util.c @@ -352,9 +352,6 @@ procline(struct str *l, int nottext) if (r == 0) { lastmatches++; lastmatch = pmatch; - /* Skip over zero-length matches */ - if (pmatch.rm_so == pmatch.rm_eo) - continue; if (m == 0) c++; @@ -532,6 +529,9 @@ printline(struct str *line, int sep, regmatch_t *matches, int m) /* --color and -o */ if ((oflag || color) && m > 0) { for (i = 0; i < m; i++) { + /* Don't output zero length matches */ + if (matches[i].rm_so == matches[i].rm_eo) + continue; if (!oflag) fwrite(line->dat + a, matches[i].rm_so - a, 1, stdout); |