Boost C++ Libraries: Ticket #3936: [xpressive] stack overflow. https://svn.boost.org/trac10/ticket/3936 <p> The following simple program fires a stack overflow exception in xpressive. It's seems too simple to be causing such problems. </p> <p> {{{#include "stdafx.h" #include &lt;string&gt; #include &lt;boost/xpressive/xpressive.hpp&gt; using namespace boost::xpressive; </p> <p> int _tmain(int argc, _TCHAR* argv[]) { </p> <blockquote> <p> sregex rx = ~(set='{', '}', ','); sregex rx2 = +rx; </p> </blockquote> <blockquote> <p> std::string s(10000, 'a'); regex_search(s, rx2); </p> </blockquote> <blockquote> <p> return 0; </p> </blockquote> <p> }}}} </p> <p> I'm using MSVC 2005. The problem only occurs if the string is large. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/3936 Trac 1.4.3 Eric Niebler Wed, 17 Feb 2010 00:06:35 GMT status changed https://svn.boost.org/trac10/ticket/3936#comment:1 https://svn.boost.org/trac10/ticket/3936#comment:1 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">assigned</span> </li> </ul> <p> 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. </p> <p> 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: </p> <pre class="wiki"> // Doesn't blow the stack sregex rx2 = +~(set='{', '}', ','); </pre><p> You can also use the linker's /STACK switch to give threads in your process more stack space. The default is really quite low. </p> <p> Sorry I don't have a better answer for you. </p> Ticket