Bug 86165 - std::regex crashes when matching long lines.
Summary: std::regex crashes when matching long lines.
Status: RESOLVED DUPLICATE of bug 86164
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 7.1.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
Depends on:
Reported: 2018-06-15 10:49 UTC by Holger Seelig
Modified: 2018-06-15 11:13 UTC (History)
0 users

See Also:
Known to work:
Known to fail:
Last reconfirmed:


Note You need to log in before you can comment on or make changes to this bug.
Description Holger Seelig 2018-06-15 10:49:34 UTC
std::regex crashes when matching long lines.

Here is an example:

#include <regex>
#include <iostream>
int main()
    std::string s (100'000, '*');
    std::smatch m;
    std::regex r ("^(.*?)$");

    std::regex_search (s, m, r);

    std::cout << s .substr (0, 10) << std::endl;
    std::cout << m  .str (1) .substr (0, 10) << std::endl;

It turns out that std::regex_search operator .* is implemented recursively which result in this example in a stack overflow.
Comment 1 ktkachov 2018-06-15 11:13:53 UTC

*** This bug has been marked as a duplicate of bug 86164 ***