lundi 27 mai 2019

Regex segmentation fault

I have a regex that fires segmentation fault error. After some tests I noticed that [\s\S]*\s+ part of regex is making problems if string is larger than 15 KB, so sometimes it works but sometimes it crashes.

Here is the C++ code compiled with g++ (gcc v. 6.3.0)

#include <regex>
#include <fstream>
#include <string>
#include <iostream>

int main (int argc, char *argv[]) {

    std::regex regex(
            R"([\s\S]*\s+)",
            std::regex_constants::icase
    );

    std::ifstream ifs("/home/input.txt");
    const std::string input(
            (std::istreambuf_iterator<char>(ifs)),
            (std::istreambuf_iterator<char>())
            );

    std::cout << "input size: " << input.size() << std::endl;

    bool reg_match = std::regex_match(input, regex);

    std::cout << "matched: " << reg_match << std::endl;

}

Aucun commentaire:

Enregistrer un commentaire