From 86538bed1c377b4c2628be88228e1088d7d3f319 Mon Sep 17 00:00:00 2001 From: Houtan Bastani <houtan@dynare.org> Date: Tue, 6 Aug 2019 14:47:13 -0400 Subject: [PATCH] macro processor: only allow conversion to double from strings that precisely contain numeric values --- src/macro/Expressions.cc | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/macro/Expressions.cc b/src/macro/Expressions.cc index 859a6028..6c14152d 100644 --- a/src/macro/Expressions.cc +++ b/src/macro/Expressions.cc @@ -315,7 +315,11 @@ String::cast_double() const { try { - return make_shared<Double>(stod(value), env); + size_t pos = 0; + double value_d = stod(value, &pos); + if (pos != value.length()) + throw StackTrace("Entire string not converted"); + return make_shared<Double>(value_d, env); } catch (...) { -- GitLab