From: Sean Hunt Date: Fri, 3 Apr 2015 20:25:17 +0000 (-0400) Subject: Catch regex matching errors to avoid crashing. X-Git-Tag: NetHack-3.6.0_RC01~480^2~12 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=302ad5025fd2d0b4305002a7301769eeaf8838b5;p=nethack Catch regex matching errors to avoid crashing. --- diff --git a/sys/share/cppregex.cpp b/sys/share/cppregex.cpp index 8d0704fde..e775d7c6f 100644 --- a/sys/share/cppregex.cpp +++ b/sys/share/cppregex.cpp @@ -42,7 +42,11 @@ extern "C" { boolean regex_match(const char *s, struct nhregex *re) { if (!re->re) return false; - return regex_search(s, *re->re, std::regex_constants::match_any); + try { + return regex_search(s, *re->re, std::regex_constants::match_any); + } catch (const std::regex_error& err) { + return false; + } } void regex_free(struct nhregex *re) {