diff options
author | Tim Shen <timshen@google.com> | 2014-07-01 03:05:45 +0000 |
---|---|---|
committer | Tim Shen <timshen@gcc.gnu.org> | 2014-07-01 03:05:45 +0000 |
commit | 5bcb66dffabd20f12fd8392820aa7dd00280091e (patch) | |
tree | b3f29a323adc663c3b20144ef5bf212c5599c09e /libstdc++-v3/include | |
parent | ad9ec7b3c5969c776bc28e18292be09981abaa6a (diff) | |
download | gcc-5bcb66dffabd20f12fd8392820aa7dd00280091e.zip gcc-5bcb66dffabd20f12fd8392820aa7dd00280091e.tar.gz gcc-5bcb66dffabd20f12fd8392820aa7dd00280091e.tar.bz2 |
re PR testsuite/61061 (FAIL: g++.dg/inherit/covariant7.C)
PR libstdc++/61061
PR libstdc++/61582
* include/bits/regex_automaton.h (_NFA<>::_M_insert_state): Add
a NFA state limit. If it's exceeded, regex_constants::error_space
will be throwed.
* include/bits/regex_automaton.tcc (_StateSeq<>::_M_clone): Use
map (which is sparse) instead of vector. This reduce n times clones'
cost from O(n^2) to O(n).
* include/std/regex: Add map dependency.
* testsuite/28_regex/algorithms/regex_match/ecma/char/61601.cc: New
testcase.
From-SVN: r212185
Diffstat (limited to 'libstdc++-v3/include')
-rw-r--r-- | libstdc++-v3/include/bits/regex_automaton.h | 7 | ||||
-rw-r--r-- | libstdc++-v3/include/bits/regex_automaton.tcc | 17 | ||||
-rw-r--r-- | libstdc++-v3/include/std/regex | 1 |
3 files changed, 17 insertions, 8 deletions
diff --git a/libstdc++-v3/include/bits/regex_automaton.h b/libstdc++-v3/include/bits/regex_automaton.h index 1b0da14..27ec671 100644 --- a/libstdc++-v3/include/bits/regex_automaton.h +++ b/libstdc++-v3/include/bits/regex_automaton.h @@ -28,6 +28,11 @@ * Do not attempt to use it directly. @headername{regex} */ +// This macro defines the maximal state number a NFA can have. +#ifndef _GLIBCXX_REGEX_STATE_LIMIT +#define _GLIBCXX_REGEX_STATE_LIMIT 100000 +#endif + namespace std _GLIBCXX_VISIBILITY(default) { namespace __detail @@ -254,6 +259,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION _M_insert_state(_StateT __s) { this->push_back(std::move(__s)); + if (this->size() > _GLIBCXX_REGEX_STATE_LIMIT) + __throw_regex_error(regex_constants::error_space); return this->size()-1; } diff --git a/libstdc++-v3/include/bits/regex_automaton.tcc b/libstdc++-v3/include/bits/regex_automaton.tcc index 1c6cfdd..08d271e 100644 --- a/libstdc++-v3/include/bits/regex_automaton.tcc +++ b/libstdc++-v3/include/bits/regex_automaton.tcc @@ -189,7 +189,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION _StateSeq<_TraitsT> _StateSeq<_TraitsT>::_M_clone() { - std::vector<_StateIdT> __m(_M_nfa.size(), -1); + std::map<_StateIdT, _StateIdT> __m; std::stack<_StateIdT> __stack; __stack.push(_M_start); while (!__stack.empty()) @@ -203,21 +203,22 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION if (__dup._M_opcode == _S_opcode_alternative || __dup._M_opcode == _S_opcode_repeat || __dup._M_opcode == _S_opcode_subexpr_lookahead) - if (__dup._M_alt != _S_invalid_state_id && __m[__dup._M_alt] == -1) + if (__dup._M_alt != _S_invalid_state_id + && __m.count(__dup._M_alt) == 0) __stack.push(__dup._M_alt); if (__u == _M_end) continue; - if (__dup._M_next != _S_invalid_state_id && __m[__dup._M_next] == -1) + if (__dup._M_next != _S_invalid_state_id + && __m.count(__dup._M_next) == 0) __stack.push(__dup._M_next); } - for (auto __v : __m) + for (auto __it : __m) { - if (__v == -1) - continue; + auto __v = __it.second; auto& __ref = _M_nfa[__v]; if (__ref._M_next != _S_invalid_state_id) { - _GLIBCXX_DEBUG_ASSERT(__m[__ref._M_next] != -1); + _GLIBCXX_DEBUG_ASSERT(__m.count(__ref._M_next) > 0); __ref._M_next = __m[__ref._M_next]; } if (__ref._M_opcode == _S_opcode_alternative @@ -225,7 +226,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION || __ref._M_opcode == _S_opcode_subexpr_lookahead) if (__ref._M_alt != _S_invalid_state_id) { - _GLIBCXX_DEBUG_ASSERT(__m[__ref._M_alt] != -1); + _GLIBCXX_DEBUG_ASSERT(__m.count(__ref._M_alt) > 0); __ref._M_alt = __m[__ref._M_alt]; } } diff --git a/libstdc++-v3/include/std/regex b/libstdc++-v3/include/std/regex index 9161f48..470772af 100644 --- a/libstdc++-v3/include/std/regex +++ b/libstdc++-v3/include/std/regex @@ -50,6 +50,7 @@ #include <string> #include <utility> #include <vector> +#include <map> #include <cstring> #include <bits/regex_constants.h> |