aboutsummaryrefslogtreecommitdiffstats
path: root/3rdparty
diff options
context:
space:
mode:
authorMarcin Koƛcielnicki <mwk@0x04.net>2020-02-01 17:23:05 +0100
committerMarcin Koƛcielnicki <mwk@0x04.net>2020-02-01 17:23:05 +0100
commit24e3f8417e861321d1f934d52fd33535e08d9817 (patch)
tree8f7fee3c63dd8054deb2ee68d1968b581a43099f /3rdparty
parent85f4452b0a3bd47ccb25be023859542ffef888f7 (diff)
downloadnextpnr-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')
-rw-r--r--3rdparty/json11/json11.cpp11
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