From 24e3f8417e861321d1f934d52fd33535e08d9817 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcin=20Ko=C5=9Bcielnicki?= Date: Sat, 1 Feb 2020 17:23:05 +0100 Subject: json: fix handling of 32-bit parameters See YosysHQ/yosys#1671 for rationale. Also, added some validation to our parser, so that out-of-range values are reported and the user knows they should update yosys. --- 3rdparty/json11/json11.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to '3rdparty/json11') diff --git a/3rdparty/json11/json11.cpp b/3rdparty/json11/json11.cpp index 88024e92..faa6cf64 100644 --- a/3rdparty/json11/json11.cpp +++ b/3rdparty/json11/json11.cpp @@ -24,7 +24,8 @@ #include #include #include -#include +#include +#include namespace json11 { @@ -589,9 +590,11 @@ struct JsonParser final { return fail("invalid " + esc(str[i]) + " in number"); } - if (str[i] != '.' && str[i] != 'e' && str[i] != 'E' - && (i - start_pos) <= static_cast(std::numeric_limits::digits10)) { - return std::atoi(str.c_str() + start_pos); + if (str[i] != '.' && str[i] != 'e' && str[i] != 'E') { + errno = 0; + long val = std::strtol(str.c_str() + start_pos, nullptr, 0); + if (!errno && val >= INT_MIN && val <= INT_MAX) + return int(val); } // Decimal part -- cgit v1.2.3