diff options
author | 2004-01-25 21:36:00 +0000 | |
---|---|---|
committer | 2004-01-25 21:36:00 +0000 | |
commit | 0c9d1b5f7d625cd82117dd9adcd42fe2abea4efa (patch) | |
tree | 610e0bb58683bde3166f0ee05581cea9cd74c0cb /usr.bin/grep/grep.c | |
parent | Add missing REGRESS_TARGETS for t15 and t16 (diff) | |
download | wireguard-openbsd-0c9d1b5f7d625cd82117dd9adcd42fe2abea4efa.tar.xz wireguard-openbsd-0c9d1b5f7d625cd82117dd9adcd42fe2abea4efa.zip |
Previously, in -w mode, for each match on a line grep would check
to see if the match was on a word boundary. However, this missed
lines where the first match was not on a word boundary but a
subsequent match was. Problem originally spotted by miod@
We fix this by using the [[:<:]] and [[:>:]] character classes for
the slow path and by checking the word boundaries in grep_search()
for the fast path instead of doing the checks after running
regexec() or grep_search().
With this change, grep passes the new regress tests 15 and 16.
problem originally spotted by espie@.
Diffstat (limited to 'usr.bin/grep/grep.c')
-rw-r--r-- | usr.bin/grep/grep.c | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/usr.bin/grep/grep.c b/usr.bin/grep/grep.c index 111545df623..6e6a8cf6126 100644 --- a/usr.bin/grep/grep.c +++ b/usr.bin/grep/grep.c @@ -1,4 +1,4 @@ -/* $OpenBSD: grep.c,v 1.24 2003/12/11 20:49:20 mcbride Exp $ */ +/* $OpenBSD: grep.c,v 1.25 2004/01/25 21:36:00 millert Exp $ */ /*- * Copyright (c) 1999 James Howard and Dag-Erling Coïdan Smørgrav @@ -172,10 +172,16 @@ add_pattern(char *pat, size_t len) } if (pat[len - 1] == '\n') --len; - pattern[patterns] = grep_malloc(len + 1); /* pat may not be NUL-terminated */ - memcpy(pattern[patterns], pat, len); - pattern[patterns][len] = '\0'; + if (wflag) { + pattern[patterns] = grep_malloc(len + 15); + snprintf(pattern[patterns], len + 15, "[[:<:]]%.*s[[:>:]]", + (int)len, pat); + } else { + pattern[patterns] = grep_malloc(len + 1); + memcpy(pattern[patterns], pat, len); + pattern[patterns][len] = '\0'; + } ++patterns; if (len > maxPatternLen) |