summaryrefslogtreecommitdiffstats
path: root/usr.bin/grep/grep.c
diff options
context:
space:
mode:
authorjaredy <jaredy@openbsd.org>2006-09-26 15:55:17 +0000
committerjaredy <jaredy@openbsd.org>2006-09-26 15:55:17 +0000
commit3d12d7ee890de65984fe29b0a8c48d12c910941b (patch)
tree986a76b1e8d402b27e59144e106499d80a5cb0d9 /usr.bin/grep/grep.c
parentstyle(9) extra space (diff)
downloadwireguard-openbsd-3d12d7ee890de65984fe29b0a8c48d12c910941b.tar.xz
wireguard-openbsd-3d12d7ee890de65984fe29b0a8c48d12c910941b.zip
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.c6
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);