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 diff --git a/frontend/json_frontend.cc b/frontend/json_frontend.cc index f1310e71..136786fc 100644 --- a/frontend/json_frontend.cc +++ b/frontend/json_frontend.cc @@ -105,10 +105,14 @@ struct JsonFrontendImpl Property parse_property(const Json &val) const { - if (val.is_number()) + if (val.is_number()) { + if (val.int_value() != val.number_value()) + log_error("Found an out-of-range integer parameter in the JSON file.\n" + "Please regenerate the input file with an up-to-date version of yosys.\n"); return Property(val.int_value(), 32); - else + } else { return Property::from_string(val.string_value()); + } } template void foreach_attr(const Json &obj, TFunc Func) const diff --git a/json/jsonwrite.cc b/json/jsonwrite.cc index 477bfca5..d4a62a5a 100644 --- a/json/jsonwrite.cc +++ b/json/jsonwrite.cc @@ -45,15 +45,6 @@ std::string get_string(std::string str) std::string get_name(IdString name, Context *ctx) { return get_string(name.c_str(ctx)); } -void write_parameter_value(std::ostream &f, const Property &value) -{ - if (value.size() == 32 && value.is_fully_def()) { - f << stringf("%d", value.as_int64()); - } else { - f << get_string(value.to_string()); - } -} - void write_parameters(std::ostream &f, Context *ctx, const std::unordered_map ¶meters, bool for_module = false) { @@ -61,7 +52,7 @@ void write_parameters(std::ostream &f, Context *ctx, const std::unordered_map