FreeBSD Bugzilla – Attachment 179126 Details for
Bug 195763
bsdgrep, empty matches and -o
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Proposed patch to address zero length match issues with bsdgrep
grep-zerolen.patch (text/plain), 2.56 KB, created by
Kyle Evans
on 2017-01-20 06:27:46 UTC
(
hide
)
Description:
Proposed patch to address zero length match issues with bsdgrep
Filename:
MIME Type:
Creator:
Kyle Evans
Created:
2017-01-20 06:27:46 UTC
Size:
2.56 KB
patch
obsolete
>diff --git a/usr.bin/grep/grep.c b/usr.bin/grep/grep.c >index b744b8aab8a..81b0ffae67a 100644 >--- a/usr.bin/grep/grep.c >+++ b/usr.bin/grep/grep.c >@@ -339,7 +339,7 @@ main(int argc, char *argv[]) > const char *pn; > unsigned long long l; > unsigned int aargc, eargc, i; >- int c, lastc, needpattern, newarg, prevoptind; >+ int c, lastc, needpattern, newarg, prevoptind, pofs; > > setlocale(LC_ALL, ""); > >@@ -704,18 +704,23 @@ main(int argc, char *argv[]) > > fg_pattern = grep_calloc(patterns, sizeof(*fg_pattern)); > r_pattern = grep_calloc(patterns, sizeof(*r_pattern)); >+ pofs = 0; > > /* Check if cheating is allowed (always is for fgrep). */ > for (i = 0; i < patterns; ++i) { >- if (fastncomp(&fg_pattern[i], pattern[i].pat, >+ if (fastncomp(&fg_pattern[i - pofs], pattern[i].pat, > pattern[i].len, cflags) != 0) { > /* Fall back to full regex library */ >- c = regcomp(&r_pattern[i], pattern[i].pat, cflags); >+ c = regcomp(&r_pattern[i - pofs], pattern[i].pat, cflags); > if (c != 0) { >- regerror(c, &r_pattern[i], re_error, >+ regerror(c, &r_pattern[i - pofs], re_error, > RE_ERROR_BUF); > errx(2, "%s", re_error); > } >+ } else { >+ /* Deduct one for invalid pattern */ >+ patterns --; >+ pofs ++; > } > } > >diff --git a/usr.bin/grep/util.c b/usr.bin/grep/util.c >index fa1a967463f..24453d7c1b4 100644 >--- a/usr.bin/grep/util.c >+++ b/usr.bin/grep/util.c >@@ -294,13 +294,13 @@ procline(struct str *l, int nottext) > regmatch_t pmatch; > size_t st = 0; > unsigned int i; >- int c = 0, m = 0, r = 0; >+ int c = 0, m = 0, r = 0, lastmatches = 0; > > /* Loop to process the whole line */ > while (st <= l->len) { > pmatch.rm_so = st; > pmatch.rm_eo = l->len; >- >+ lastmatches = 0; > /* Loop to compare with all the patterns */ > for (i = 0; i < patterns; i++) { > if (fg_pattern[i].pattern) >@@ -339,10 +339,16 @@ procline(struct str *l, int nottext) > r = REG_NOMATCH; > } > if (r == 0) { >+ lastmatches ++; >+ /* Skip over zero-length matches */ >+ if (pmatch.rm_so == pmatch.rm_eo) >+ continue; > if (m == 0) > c++; >- if (m < MAX_LINE_MATCHES) >+ if (m < MAX_LINE_MATCHES) { > matches[m++] = pmatch; >+ } >+ > /* matches - skip further patterns */ > if ((color == NULL && !oflag) || > qflag || lflag) >@@ -359,8 +365,10 @@ procline(struct str *l, int nottext) > if (!wflag && ((color == NULL && !oflag) || qflag || lflag || Lflag)) > break; > >- if (st == (size_t)pmatch.rm_so) >+ if (lastmatches == 0) > break; /* No matches */ >+ else if (st == (size_t)pmatch.rm_so) >+ st ++; /* Zero-length match -- advance one more */ > } > >
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 195763
:
179126
|
179171
|
179173
|
179175
|
179227