C ++ 11正则表达式堆栈溢出/ VS2012 [英] C++ 11 regex stack overflow / VS2012

查看:470
本文介绍了C ++ 11正则表达式堆栈溢出/ VS2012的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将一些旧的Boost正则表达式代码转换为C ++ 11,我偶然发现了一个我的测试用例的问题。这里是一个场景,导致堆栈溢出异常使用std :: regex,但工作正常与boost :: regex。我没有改变正则表达式模式,并验证了模式是我想要的。看来这个特定的字符串输入片段导致堆栈溢出。使用VS2012,x64调试版本:

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 );  

看看异常后的调用堆栈,似乎有一些类型的无限递归正则表达式实现。我目前没有GCC测试这个。我做错了什么?

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?

更新:
在下面的建议之后,我将这个代码粘贴到控制台应用程序,VS 2012 x64调试,我得到堆栈溢出。如果我把它改为x64版本,或者Win32调试或发布它运行正常。 h?我需要重新安装VS和/或平台SDK吗?我在Win7 x64。

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.

更新#2:
一些相关的帖子:为什么std :: regex_iterator导致堆栈溢出这个数据?
我想如果我重写我的正则表达式,它可能会有帮助。我仍然不知道为什么bitness重要。为什么它适用于其他人,但不适合我的系统。 Sigh。

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.

推荐答案

我已经用x64调试生成了这个,我相信这是一个真正的

I've been reproduced this with x64 debug build, and I belive this is a real stack overflow.

当您将堆栈大小更改为10MB左右时(链接器命令行选项 / STACK:10000000),
它会正常工作。

When you change your stack size to 10MB or so (linker command line option /STACK:"10000000"), it will work fine.

这篇关于C ++ 11正则表达式堆栈溢出/ VS2012的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆