summaryrefslogtreecommitdiff
path: root/src/searchutils.c
diff options
context:
space:
mode:
authorNorihiro Tanaka <noritnk@kcn.ne.jp>2014-04-30 11:22:27 +0900
committerPaul Eggert <eggert@cs.ucla.edu>2014-05-04 19:35:48 -0700
commitfb7d53887851476c84f38ecc9a63901d5d620806 (patch)
treeabdaed7e10c720b67c29bcaaaab9b1396cb06624 /src/searchutils.c
parenta159d14c79c86c441e834a513e7b27ea735c26ff (diff)
downloadgrep-fb7d53887851476c84f38ecc9a63901d5d620806.tar.gz
grep: make KWset and DFA agree about invalid sequences in patterns
See: http://bugs.gnu.org/17376 * src/dfa.c (dfambcache): Don't cache invalid sequences, because they can't be represented by wide characters. (dfambcache, mbs_to_wchar): Return WEOF for invalid sequences. (ctok): New global variable. (parse_bracket_exp, atom, match_anychar, match_mb_charset): Don't allow WEOF. (lex): Set 'ctok'. * src/kwsearch.c (Fexecute): * src/searchutils.c (is_mb_middle): Don't check here. * tests/invalid-multibyte-infloop: Adjust to fixed behavior. * tests/prefix-of-multibyte: Add test cases for this bug.
Diffstat (limited to 'src/searchutils.c')
-rw-r--r--src/searchutils.c9
1 files changed, 2 insertions, 7 deletions
diff --git a/src/searchutils.c b/src/searchutils.c
index 6440f073..3c78f31c 100644
--- a/src/searchutils.c
+++ b/src/searchutils.c
@@ -228,7 +228,6 @@ is_mb_middle (const char **good, const char *buf, const char *end,
size_t match_len)
{
const char *p = *good;
- const char *prev = p;
mbstate_t cur_state;
if (using_utf8 () && buf - p > MB_CUR_MAX)
@@ -250,10 +249,6 @@ is_mb_middle (const char **good, const char *buf, const char *end,
if (mbclen == (size_t) -2)
mbclen = mbrlen (p, end - p, &cur_state);
- /* Store the beginning of the previous complete multibyte character. */
- if (mbclen != (size_t) -2)
- prev = p;
-
if (mbclen == (size_t) -1 || mbclen == (size_t) -2 || mbclen == 0)
{
/* An invalid sequence, or a truncated multibyte character.
@@ -264,11 +259,11 @@ is_mb_middle (const char **good, const char *buf, const char *end,
p += mbclen;
}
- *good = prev;
+ *good = p;
if (p > buf)
return true;
/* P == BUF here. */
- return 0 < match_len && match_len < mbrlen (p, end - p, &cur_state);
+ return false;
}