From 779ae7fffc4be1785c8f83076bc91cc016e3df8b Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Tue, 29 Sep 2026 09:37:56 +0200 Subject: [PATCH] Address the cpplint findings of json_document images The exponent of the overflow check is an std::int64_t instead of a long (runtime/int). Signed-off-by: Niels Lohmann --- include/nlohmann/detail/view/image.hpp | 6 +++--- single_include/nlohmann/json_view.hpp | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/include/nlohmann/detail/view/image.hpp b/include/nlohmann/detail/view/image.hpp index e7de241ef..c1776f699 100644 --- a/include/nlohmann/detail/view/image.hpp +++ b/include/nlohmann/detail/view/image.hpp @@ -10,7 +10,7 @@ #include // array #include // size_t -#include // uint8_t, uint16_t, uint32_t, uint64_t +#include // int64_t, uint8_t, uint16_t, uint32_t, uint64_t #include // memcmp, memcpy #include // numeric_limits #include // string @@ -299,7 +299,7 @@ inline bool check_number(const node& n, const unsigned char* text) frac_digits = static_cast(p - f0); is_float = true; } - long exponent = 0; + std::int64_t exponent = 0; if (p != e && (*p | 0x20u) == 'e') { ++p; @@ -332,7 +332,7 @@ inline bool check_number(const node& n, const unsigned char* text) } // parse() rejects floats that overflow; as there, only a number whose // magnitude could reach 1e308 needs the conversion - if (static_cast(int_digits) + exponent > 300) + if (static_cast(int_digits) + exponent > 300) { const auto v = float_value(reinterpret_cast(s), n); // NOLINT(cppcoreguidelines-pro-type-reinterpret-cast) return v <= (std::numeric_limits::max)() && v >= -(std::numeric_limits::max)(); diff --git a/single_include/nlohmann/json_view.hpp b/single_include/nlohmann/json_view.hpp index 1ca6e7adc..01bda3583 100644 --- a/single_include/nlohmann/json_view.hpp +++ b/single_include/nlohmann/json_view.hpp @@ -3786,7 +3786,7 @@ NLOHMANN_JSON_NAMESPACE_END #include // array #include // size_t -#include // uint8_t, uint16_t, uint32_t, uint64_t +#include // int64_t, uint8_t, uint16_t, uint32_t, uint64_t #include // memcmp, memcpy #include // numeric_limits #include // string @@ -4305,7 +4305,7 @@ inline bool check_number(const node& n, const unsigned char* text) frac_digits = static_cast(p - f0); is_float = true; } - long exponent = 0; + std::int64_t exponent = 0; if (p != e && (*p | 0x20u) == 'e') { ++p; @@ -4338,7 +4338,7 @@ inline bool check_number(const node& n, const unsigned char* text) } // parse() rejects floats that overflow; as there, only a number whose // magnitude could reach 1e308 needs the conversion - if (static_cast(int_digits) + exponent > 300) + if (static_cast(int_digits) + exponent > 300) { const auto v = float_value(reinterpret_cast(s), n); // NOLINT(cppcoreguidelines-pro-type-reinterpret-cast) return v <= (std::numeric_limits::max)() && v >= -(std::numeric_limits::max)();