Opened 13 years ago

Last modified 13 years ago

#3936 assigned Bugs

[xpressive] stack overflow.

Reported by: shewitt.au@… Owned by: Eric Niebler
Milestone: Boost 1.43.0 Component: xpressive
Version: Boost 1.42.0 Severity: Problem
Keywords: Cc:

Description

The following simple program fires a stack overflow exception in xpressive. It's seems too simple to be causing such problems.

{{{#include "stdafx.h" #include <string> #include <boost/xpressive/xpressive.hpp> using namespace boost::xpressive;

int _tmain(int argc, _TCHAR* argv[]) {

sregex rx = ~(set='{', '}', ','); sregex rx2 = +rx;

std::string s(10000, 'a'); regex_search(s, rx2);

return 0;

}}}}

I'm using MSVC 2005. The problem only occurs if the string is large.

Change History (1)

comment:1 by Eric Niebler, 13 years ago

Status: newassigned

This is a known problem with xpressive's implementation. All I can say is: don't do that. I'll leave the bug open, but I'm sorry to say that it's unlikely to ever be fixed. Due to the nested regex, there are simply too many states in this regular expression and the algorithm runs out of stack space. As a small consolation, on MSVC, xpressive traps the stack overflow, resets the stack guard page, and throws an exception which you can handle. I understand this is not ideal.

There are other things you can do to avoid the trouble. Don't use nested regexes needlessly. In your case, you can simply rewrite the regex as:

    // Doesn't blow the stack
    sregex rx2 = +~(set='{', '}', ',');

You can also use the linker's /STACK switch to give threads in your process more stack space. The default is really quite low.

Sorry I don't have a better answer for you.

Note: See TracTickets for help on using tickets.