Reputation: 2036
I'm in the process of converting some older Boost regex code to C++11, and I stumbled upon an issue with one of my test cases. Here is a scenario which causes a stack overflow exception using std::regex, but worked fine with boost::regex. I have not changed the regular expression pattern, and have verified the pattern is what I want. It seems this particular string input fragment is causing the stack overflow. Using VS2012, x64 debug build:
std::regex regx( "(^|\\})(([^\\{:])+:)+([^\\{]*\\{)" );
const std::string testinput = " COLOR: #000; BACKGROUND-COLOR: #FFF; FONT-FAMILY: VERDANA, ARIAL, HELVETICA, SANS-SERIF; BACKGROUND:URL(URL(___FOO___)); BACKGROUND-2:URL(URL(___FOO___)); BORDER: 0 0 0 0; BORDER-2: 0 0 0; BORDER-3: 0 0; BORDER-4: 0PX; BORDER-5: 0.6; FILTER:PROGID:DXIMAGETRANSFORM.MICROSOFT.ALPHA(OPACITY=100); } ";
std::smatch what;
// this next line causes a stack overflow
std::regex_search( testinput.cbegin(), testinput.cend(), what, regx );
Looking at the call stack after the exception, there seems to be some type of infinite recursion going on in the regex implementation. I don't currently have GCC to test this with. What am I doing wrong?
Update: After the suggestions below, I pasted this code into a console app, VS 2012 x64 debug and I get the stack overflow. If I change it to x64 release, or Win32 debug or release it runs fine. Huh??? Do i need to reinstall VS and/or the platform SDK? I'm on Win7 x64.
Update #2: Somewhat related post: Why does std::regex_iterator cause a stack overflow with this data? I suppose if I rewrite my regex, it might help. I'm still not sure why the bitness matters though. And why it works for others, but not for me on my system. Sigh.
Upvotes: 10
Views: 1805
Reputation: 73
I've been reproduced this with x64 debug build, and I belive this is a real stack overflow.
When you change your stack size to 10MB or so (linker command line option /STACK:"10000000"
),
it will work fine.
Upvotes: 2