diff options
author | Marcin KoĆcielnicki <mwk@0x04.net> | 2020-02-01 17:23:05 +0100 |
---|---|---|
committer | Marcin KoĆcielnicki <mwk@0x04.net> | 2020-02-01 17:23:05 +0100 |
commit | 24e3f8417e861321d1f934d52fd33535e08d9817 (patch) | |
tree | 8f7fee3c63dd8054deb2ee68d1968b581a43099f /3rdparty/json11 | |
parent | 85f4452b0a3bd47ccb25be023859542ffef888f7 (diff) | |
download | nextpnr-24e3f8417e861321d1f934d52fd33535e08d9817.tar.gz nextpnr-24e3f8417e861321d1f934d52fd33535e08d9817.tar.bz2 nextpnr-24e3f8417e861321d1f934d52fd33535e08d9817.zip |
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.
Diffstat (limited to '3rdparty/json11')
-rw-r--r-- | 3rdparty/json11/json11.cpp | 11 |
1 files changed, 7 insertions, 4 deletions
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 <cmath> #include <cstdlib> #include <cstdio> -#include <limits> +#include <climits> +#include <cerrno> 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<size_t>(std::numeric_limits<int>::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 |