boost::algorithm::split_regex hangs and consumes CPU on dangling alternatives
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdlib.h> | |
#include <iostream> | |
#include <boost/regex.hpp> | |
#include <boost/algorithm/string/regex.hpp> | |
int main() { | |
// Works | |
{ | |
std::cout << "Using ;|," << std::endl; | |
const char *input = "foo;bar,qux"; | |
std::vector<std::string> result; | |
boost::regex pattern(";|,", boost::regbase::normal); | |
boost::algorithm::split_regex(result, input, pattern); | |
for( int i = 0; i < result.size(); i = i + 1) { | |
std::cout << "value at " << i << ": " << result[i] << std::endl; | |
} | |
std::cout << std::endl; | |
} | |
// Consumes CPU due to unbounded | | |
{ | |
std::cout << "Using ;|" << std::endl; | |
const char *input = "foo;bar,qux"; | |
std::vector<std::string> result; | |
boost::regex pattern(";|", boost::regbase::normal); | |
boost::algorithm::split_regex(result, input, pattern); | |
for( int i = 0; i < result.size(); i = i + 1) { | |
std::cout << "value at " << i << ": " << result[i] << std::endl; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment