Opened 13 years ago

Closed 13 years ago

#3586 closed Bugs (fixed)

Use of Greedy quantifiers in Quoted Expressions locks up at regex compile

Reported by: nmaximillian@… Owned by: Eric Niebler
Milestone: To Be Determined Component: xpressive
Version: Boost 1.38.0 Severity: Problem
Keywords: Cc:

Description

The following will not compile: \Q.*\E and causes the program to lockup at the compile step. I have attempted other usages: '\Qh*\E', '\Q.+\E', '\Q+\E', '\Q*\E' etc. and they all lock-up on compile. Note that escaping the quantifier will allow it to compile (but it is a different expression): '\Q.\*\E' -- compiles but will only match '.\*' not '.*'

#include <iostream>
#include <boost/xpressive/xpressive.hpp>

using namespace boost::xpressive;

int main()
{
    std::string hello( "hello .* world!" );

    std::cout << "compile regex" << std::endl;
    sregex rex = sregex::compile( "\\Q.*\\E" );
    smatch what;
    
    std::cout << "Get Iterator" << std::endl;
    sregex_iterator cur( hello.begin(), hello.end(), rex );
    sregex_iterator end;

    std::cout << "begin search" << std::endl;
    while( cur != end ) {
        smatch const &what = *cur;
        std::cout << "found: " << what[0] << '\n'; 
        cur++;
    }

    return 0;
}

Change History (1)

comment:1 by Eric Niebler, 13 years ago

Resolution: fixed
Status: newclosed

(In [57346]) fix infinite loop with some uses of \Q...\E quotemeta, fixes #3586

Note: See TracTickets for help on using tickets.