From 6ee955be5f4ddcba735affb8c670da1ec53cb2e8 Mon Sep 17 00:00:00 2001 From: John Maddock Date: Tue, 17 Sep 2002 10:57:26 +0000 Subject: [PATCH] Tweeked number of states that cause a throw to occur during search. [SVN r15402] --- include/boost/regex/detail/regex_match.hpp | 25 +++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/include/boost/regex/detail/regex_match.hpp b/include/boost/regex/detail/regex_match.hpp index b84436e3..f634a72f 100644 --- a/include/boost/regex/detail/regex_match.hpp +++ b/include/boost/regex/detail/regex_match.hpp @@ -214,12 +214,12 @@ public: void estimate_max_state_count(iterator a, iterator b, unsigned states, std::random_access_iterator_tag*) { difference_type dist = std::distance(a,b); - if(dist > (std::numeric_limits::max() / (states * 3))) - max_state_count = std::numeric_limits::max(); + states *= states; + difference_type lim = std::numeric_limits::max() - 1000 - states; + if(dist > (difference_type)(lim / states)) + max_state_count = lim; else - max_state_count = states * 3 * dist; - if(max_state_count < 1000) - max_state_count = 1000; + max_state_count = 1000 + states * dist; } void estimate_max_state_count(iterator a, iterator b, unsigned states, void*) { @@ -964,7 +964,19 @@ bool query_match_aux(iterator first, // if(state_count >= pd.max_state_count) { +#ifndef BOOST_NO_EXCEPTIONS throw std::runtime_error("Max regex search depth exceeded."); +#else + while(matches.empty() == false) + matches.pop(); + while(prev_pos.empty() == false) + prev_pos.pop(); + while(prev_record.empty() == false) + prev_record.pop(); + while(prev_acc.empty() == false) + prev_acc.pop(); + return false; +#endif } // @@ -1075,7 +1087,10 @@ bool query_match_aux(iterator first, } if(match_found || have_partial_match) + { return true; + pd.state_count = 0; + } // if we get to here then everything has failed // and no match was found: