[libstdc++/61601] Throws an exception on stack overflow?

Tim Shen timshen@google.com
Tue Feb 3 21:26:00 GMT 2015


Currently std::regex uses recursion for traversing its internal NFA.

When:
1) the user input string for being matched is too long;
2) there're too many NFA states,

stack overflow will happen. 2) can be avoided (as we already did) by
limiting total number of NFA states. For 1) however, I think throwing
std::regex_error::error_stack is appropriate, but I don't know if we
can do that without manually keeping track of the recursion depth.

I'm typically asking: is there a portable way to set a temporary
thread local stack overflow (SIGSEGV?) handler when matching starts,
and reset it back when matching ends/quits ?

Alternatively, I can rewrite it to non-recursive, but it will use a
stack container on the heap and I'm not sure if it will be slowed
down.


-- 
Regards,
Tim Shen



More information about the Libstdc++ mailing list