diff --git a/include/boost/regex/v4/basic_regex_parser.hpp b/include/boost/regex/v4/basic_regex_parser.hpp index 6fc25dc2..b5cd2794 100644 --- a/include/boost/regex/v4/basic_regex_parser.hpp +++ b/include/boost/regex/v4/basic_regex_parser.hpp @@ -1220,6 +1220,17 @@ void basic_regex_parser::parse_set_literal(basic_char_setm_traits.syntax_type(*m_position) == regex_constants::syntax_dash) { + if(m_end == ++m_position) + { + fail(regex_constants::error_brack, m_position - m_base); + return; + } + if(this->m_traits.syntax_type(*m_position) == regex_constants::syntax_close_set) + { + // trailing - : + --m_position; + return; + } fail(regex_constants::error_range, m_position - m_base); return; } diff --git a/include/boost/regex/v4/perl_matcher_common.hpp b/include/boost/regex/v4/perl_matcher_common.hpp index f19b6c23..57a94fdd 100644 --- a/include/boost/regex/v4/perl_matcher_common.hpp +++ b/include/boost/regex/v4/perl_matcher_common.hpp @@ -658,12 +658,32 @@ bool perl_matcher::match_restart_continue() template bool perl_matcher::match_backstep() { - std::ptrdiff_t maxlen = ::boost::re_detail::distance(backstop, position); - if(maxlen < static_cast(pstate)->index) - return false; - std::advance(position, -static_cast(pstate)->index); +#ifdef BOOST_MSVC +#pragma warning(push) +#pragma warning(disable:4127) +#endif + if( ::boost::is_random_access_iterator::value) + { + std::ptrdiff_t maxlen = ::boost::re_detail::distance(backstop, position); + if(maxlen < static_cast(pstate)->index) + return false; + std::advance(position, -static_cast(pstate)->index); + } + else + { + int c = static_cast(pstate)->index; + while(c--) + { + if(position == backstop) + return false; + --position; + } + } pstate = pstate->next.p; return true; +#ifdef BOOST_MSVC +#pragma warning(pop) +#endif } template