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 /usr.bin/grep/grep.c | |
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
Diffstat (limited to 'usr.bin/grep/grep.c')
-rw-r--r-- | usr.bin/grep/grep.c | 6 |
1 files changed, 3 insertions, 3 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); |