aboutsummaryrefslogtreecommitdiffstats
path: root/3rdparty/json11/json11.cpp
diff options
context:
space:
mode:
authorDavid Shah <dave@ds0.me>2020-02-01 16:26:58 +0000
committerGitHub <noreply@github.com>2020-02-01 16:26:58 +0000
commita0091eb44b3b1248409038b43143b049b43d0233 (patch)
tree8f7fee3c63dd8054deb2ee68d1968b581a43099f /3rdparty/json11/json11.cpp
parent85f4452b0a3bd47ccb25be023859542ffef888f7 (diff)
parent24e3f8417e861321d1f934d52fd33535e08d9817 (diff)
downloadnextpnr-a0091eb44b3b1248409038b43143b049b43d0233.tar.gz
nextpnr-a0091eb44b3b1248409038b43143b049b43d0233.tar.bz2
nextpnr-a0091eb44b3b1248409038b43143b049b43d0233.zip
Merge pull request #388 from YosysHQ/mwk/json-fixes
json: fix handling of 32-bit parameters
Diffstat (limited to '3rdparty/json11/json11.cpp')
-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