简体   繁体   English

处理正则表达式字符串时,wsregex :: compile崩溃(内存泄漏)?

[英]wsregex::compile crashes (memory leak) when handling regex string?

I would like to understand why my program crashes when I try to use the wsregex::compile of BOOST with the following string: 我想了解为什么在尝试使用带有以下字符串的BOOST的wsregex :: compile时我的程序崩溃:

(?P<path>\b[a-z]:\\(?:[^\\/:*?"<>|\r\n]+\\)*[^\\/:*?"<>|\r\n]*)?
(:)?
(?P<ip>(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b)
(;(?P<port>\d*))?
(:(?P<port>\b\d+\b):(?P<password>[\w]*))?
(:(?P<password>\b\d+\b))?

In regex buddy everything appears to be fine. 在正则表达式伙伴中,一切似乎都很好。 I used the JGSoft flavor option on RegexBuddy. 我在RegexBuddy上使用了JGSoft风味选项。

I am validating the following: 我正在验证以下内容:

c:\My Documents\Test\test.csv:1.12.12.13:111:admin
c:\My Documents\Test\test.csv:1.12.12.13:111
c:\My Documents\Test\test.csv:1.12.12.13;111
1.12.12.13:111
1.12.12.13;111

Can you guys help me. 你们能帮我吗? Thanks a lot. 非常感谢。

This is neither a memory leak nor a crash as far as I can tell. 据我所知,这既不是内存泄漏也不是崩溃。 Xpressive is throwing an exception because this is an invalid pattern. Xpressive引发异常,因为这是无效模式。 The following program: 以下程序:

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

namespace xpr = boost::xpressive;

int main()
{
    const char pattern[] =
        "(?P<path>\\b[a-z]:\\\\(?:[^\\\\/:*?\"<>|\\r\\n]+\\\\)*[^\\\\/:*?\"<>|\\r\\n]*)?"
        "(:)?"
        "(?P<ip>(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\b)"
        "(;(?P<port>\\d*))?"
        "(:(?P<port>\\b\\d+\\b):(?P<password>[\\w]*))?"
        "(:(?P<password>\\b\\d+\\b))?";
    try
    {
        xpr::sregex rx = xpr::sregex::compile(pattern);
    }
    catch(xpr::regex_error const & e)
    {
        std::cout << e.what() << std::endl;
    }
}

Outputs: 输出:

named mark already exists

Indeed, it does. 确实如此。 This pattern uses "port" and "password" twice as the name of a capturing group. 此模式两次使用“端口”和“密码”作为捕获组的名称。 Xpressive doesn't like that. Xpressive不喜欢那样。 Just pick unique names for your captures and you should be fine. 只需为您的捕获选择唯一的名称,就可以了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM