aboutsummaryrefslogtreecommitdiff
path: root/posix/regexec.c
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2003-12-17 22:58:24 +0000
committerUlrich Drepper <drepper@redhat.com>2003-12-17 22:58:24 +0000
commitc70f81dd2ce638c807bb633acc551a68c02c99cb (patch)
tree86f5e9d1d23e0d546448529b8bebc763588085df /posix/regexec.c
parent219ebb6d8d379a9a4f09dd24cefb43b0651d3eab (diff)
downloadglibc-c70f81dd2ce638c807bb633acc551a68c02c99cb.zip
glibc-c70f81dd2ce638c807bb633acc551a68c02c99cb.tar.gz
glibc-c70f81dd2ce638c807bb633acc551a68c02c99cb.tar.bz2
(re_search_internal): Limit search to the beginning of the buffer if the initial states are empty for contexts that do not include CONTEXT_BEGBUF or, if !preg->newline_anchor, that do not include any one of CONTEXT_BEGBUF and CONTEXT_NEWLINE.
Diffstat (limited to 'posix/regexec.c')
-rw-r--r--posix/regexec.c23
1 files changed, 18 insertions, 5 deletions
diff --git a/posix/regexec.c b/posix/regexec.c
index 0c2f7bf..72b26f1 100644
--- a/posix/regexec.c
+++ b/posix/regexec.c
@@ -597,6 +597,24 @@ re_search_internal (preg, string, length, start, range, stop, nmatch, pmatch,
|| dfa->init_state_begbuf == NULL, 0))
return REG_NOMATCH;
+#ifdef DEBUG
+ /* We assume front-end functions already check them. */
+ assert (start + range >= 0 && start + range <= length);
+#endif
+
+ /* If initial states with non-begbuf contexts have no elements,
+ the regex must be anchored. If preg->newline_anchor is set,
+ we'll never use init_state_nl, so do not check it. */
+ if (dfa->init_state->nodes.nelem == 0
+ && dfa->init_state_word->nodes.nelem == 0
+ && (dfa->init_state_nl->nodes.nelem == 0
+ || !preg->newline_anchor))
+ {
+ if (start != 0 && start + range != 0)
+ return REG_NOMATCH;
+ start = range = 0;
+ }
+
re_node_set_init_empty (&empty_set);
memset (&mctx, '\0', sizeof (re_match_context_t));
@@ -630,11 +648,6 @@ re_search_internal (preg, string, length, start, range, stop, nmatch, pmatch,
else
mctx.state_log = NULL;
-#ifdef DEBUG
- /* We assume front-end functions already check them. */
- assert (start + range >= 0 && start + range <= length);
-#endif
-
match_first = start;
input.tip_context = ((eflags & REG_NOTBOL) ? CONTEXT_BEGBUF
: CONTEXT_NEWLINE | CONTEXT_BEGBUF);