about summary refs log tree commit diff
diff options
context:
space:
mode:
authorEelco Dolstra <eelco.dolstra@logicblox.com>2017-07-10T09·45+0200
committerGitHub <noreply@github.com>2017-07-10T09·45+0200
commit1762b9616cf8786270b2efb55800a8036574ed21 (patch)
tree244a686d68695c6aee879fa18407b5a3dcdd5aa7
parentd3713716b6b057852bca4fe6bcba21c946228a42 (diff)
parent17bb00d378aea9ea7f7f27618bd736f2c47e3de2 (diff)
Merge pull request #1428 from rimmington/clearer-regex-space-error
Clearer error message when regex exceeds space limit
-rw-r--r--src/libexpr/primops.cc9
1 files changed, 7 insertions, 2 deletions
diff --git a/src/libexpr/primops.cc b/src/libexpr/primops.cc
index b753d84e2e69..78d73e1f5572 100644
--- a/src/libexpr/primops.cc
+++ b/src/libexpr/primops.cc
@@ -1734,8 +1734,13 @@ static void prim_match(EvalState & state, const Pos & pos, Value * * args, Value
                 mkString(*(v.listElems()[i] = state.allocValue()), match[i + 1].str().c_str());
         }
 
-    } catch (std::regex_error &) {
-        throw EvalError("invalid regular expression ‘%s’, at %s", re, pos);
+    } catch (std::regex_error &e) {
+        if (e.code() == std::regex_constants::error_space) {
+          // limit is _GLIBCXX_REGEX_STATE_LIMIT for libstdc++
+          throw EvalError("memory limit exceeded by regular expression ‘%s’, at %s", re, pos);
+        } else {
+          throw EvalError("invalid regular expression ‘%s’, at %s", re, pos);
+        }
     }
 }