diff options
author | Jared Yanovich <jaredy@cvs.openbsd.org> | 2006-09-26 15:55:18 +0000 |
---|---|---|
committer | Jared Yanovich <jaredy@cvs.openbsd.org> | 2006-09-26 15:55:18 +0000 |
commit | 65d77f4204970b76f2166e2b009f3647f6bbd63f (patch) | |
tree | abe443ba6ec812c874f04d8348cbdcaf44f4b1aa | |
parent | 6b8d69da391cf0615787c1e5f9ed7cf7ef305a78 (diff) |
Allow zero-length patterns with -x so
$ grep -x ""
matches empty lines as reported on misc@ by
Martin Marusak <marusak@fhpv.unipo.sk>.
Initial diff by otto@ with tweaks by me.
ok otto
-rw-r--r-- | usr.bin/grep/grep.c | 6 | ||||
-rw-r--r-- | usr.bin/grep/util.c | 7 |
2 files changed, 7 insertions, 6 deletions
diff --git a/usr.bin/grep/grep.c b/usr.bin/grep/grep.c index 70d8dff38e7..6b84eae8518 100644 --- a/usr.bin/grep/grep.c +++ b/usr.bin/grep/grep.c @@ -1,4 +1,4 @@ -/* $OpenBSD: grep.c,v 1.35 2006/03/07 20:59:56 otto Exp $ */ +/* $OpenBSD: grep.c,v 1.36 2006/09/26 15:55:17 jaredy Exp $ */ /*- * Copyright (c) 1999 James Howard and Dag-Erling Coïdan Smørgrav @@ -168,7 +168,7 @@ struct option long_options[] = static void add_pattern(char *pat, size_t len) { - if (len == 0 || matchall) { + if (!xflag && (len == 0 || matchall)) { matchall = 1; return; } @@ -183,7 +183,7 @@ add_pattern(char *pat, size_t len) int bol = 0, eol = 0, extra; if (pat[0] == '^') bol = 1; - if (pat[len - 1] == '$') + if (len > 0 && pat[len - 1] == '$') eol = 1; extra = Eflag ? 2 : 4; pattern[patterns] = grep_malloc(len + 15 + extra); diff --git a/usr.bin/grep/util.c b/usr.bin/grep/util.c index 6c6d5d25063..8a08e15926d 100644 --- a/usr.bin/grep/util.c +++ b/usr.bin/grep/util.c @@ -1,4 +1,4 @@ -/* $OpenBSD: util.c,v 1.31 2006/02/09 09:54:47 otto Exp $ */ +/* $OpenBSD: util.c,v 1.32 2006/09/26 15:55:17 jaredy Exp $ */ /*- * Copyright (c) 1999 James Howard and Dag-Erling Coïdan Smørgrav @@ -479,8 +479,9 @@ grep_search(fastgrep_t *fg, unsigned char *data, size_t dataLen, regmatch_t *pma if (grep_cmp(fg->pattern, data + j, fg->patternLen) == -1) { pmatch->rm_so = j; pmatch->rm_eo = j + fg->patternLen; - if (!fg->wmatch || wmatch(data, dataLen, - pmatch->rm_so, pmatch->rm_eo)) { + if (fg->patternLen == 0 || !fg->wmatch || + wmatch(data, dataLen, pmatch->rm_so, + pmatch->rm_eo)) { rtrnVal = 0; break; } |