diff --git a/include/boost/regex/v4/perl_matcher_common.hpp b/include/boost/regex/v4/perl_matcher_common.hpp index 7974e748..f08e9d43 100644 --- a/include/boost/regex/v4/perl_matcher_common.hpp +++ b/include/boost/regex/v4/perl_matcher_common.hpp @@ -113,6 +113,11 @@ void perl_matcher::estimate_max_state_count(std std::ptrdiff_t states = re.size(); if(states == 0) states = 1; + if ((std::numeric_limits::max)() / states < states) + { + max_state_count = (std::min)((std::ptrdiff_t)BOOST_REGEX_MAX_STATE_COUNT, (std::numeric_limits::max)() - 2); + return; + } states *= states; if((std::numeric_limits::max)() / dist < states) {