mirror of
https://github.com/nlohmann/json.git
synced 2026-10-01 04:00:31 +00:00
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 <mail@nlohmann.me>
This commit is contained in:
@@ -10,7 +10,7 @@
|
|||||||
|
|
||||||
#include <array> // array
|
#include <array> // array
|
||||||
#include <cstddef> // size_t
|
#include <cstddef> // size_t
|
||||||
#include <cstdint> // uint8_t, uint16_t, uint32_t, uint64_t
|
#include <cstdint> // int64_t, uint8_t, uint16_t, uint32_t, uint64_t
|
||||||
#include <cstring> // memcmp, memcpy
|
#include <cstring> // memcmp, memcpy
|
||||||
#include <limits> // numeric_limits
|
#include <limits> // numeric_limits
|
||||||
#include <string> // string
|
#include <string> // string
|
||||||
@@ -299,7 +299,7 @@ inline bool check_number(const node& n, const unsigned char* text)
|
|||||||
frac_digits = static_cast<std::size_t>(p - f0);
|
frac_digits = static_cast<std::size_t>(p - f0);
|
||||||
is_float = true;
|
is_float = true;
|
||||||
}
|
}
|
||||||
long exponent = 0;
|
std::int64_t exponent = 0;
|
||||||
if (p != e && (*p | 0x20u) == 'e')
|
if (p != e && (*p | 0x20u) == 'e')
|
||||||
{
|
{
|
||||||
++p;
|
++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
|
// parse() rejects floats that overflow; as there, only a number whose
|
||||||
// magnitude could reach 1e308 needs the conversion
|
// magnitude could reach 1e308 needs the conversion
|
||||||
if (static_cast<long>(int_digits) + exponent > 300)
|
if (static_cast<std::int64_t>(int_digits) + exponent > 300)
|
||||||
{
|
{
|
||||||
const auto v = float_value<double>(reinterpret_cast<const char*>(s), n); // NOLINT(cppcoreguidelines-pro-type-reinterpret-cast)
|
const auto v = float_value<double>(reinterpret_cast<const char*>(s), n); // NOLINT(cppcoreguidelines-pro-type-reinterpret-cast)
|
||||||
return v <= (std::numeric_limits<double>::max)() && v >= -(std::numeric_limits<double>::max)();
|
return v <= (std::numeric_limits<double>::max)() && v >= -(std::numeric_limits<double>::max)();
|
||||||
|
|||||||
@@ -3786,7 +3786,7 @@ NLOHMANN_JSON_NAMESPACE_END
|
|||||||
|
|
||||||
#include <array> // array
|
#include <array> // array
|
||||||
#include <cstddef> // size_t
|
#include <cstddef> // size_t
|
||||||
#include <cstdint> // uint8_t, uint16_t, uint32_t, uint64_t
|
#include <cstdint> // int64_t, uint8_t, uint16_t, uint32_t, uint64_t
|
||||||
#include <cstring> // memcmp, memcpy
|
#include <cstring> // memcmp, memcpy
|
||||||
#include <limits> // numeric_limits
|
#include <limits> // numeric_limits
|
||||||
#include <string> // string
|
#include <string> // string
|
||||||
@@ -4305,7 +4305,7 @@ inline bool check_number(const node& n, const unsigned char* text)
|
|||||||
frac_digits = static_cast<std::size_t>(p - f0);
|
frac_digits = static_cast<std::size_t>(p - f0);
|
||||||
is_float = true;
|
is_float = true;
|
||||||
}
|
}
|
||||||
long exponent = 0;
|
std::int64_t exponent = 0;
|
||||||
if (p != e && (*p | 0x20u) == 'e')
|
if (p != e && (*p | 0x20u) == 'e')
|
||||||
{
|
{
|
||||||
++p;
|
++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
|
// parse() rejects floats that overflow; as there, only a number whose
|
||||||
// magnitude could reach 1e308 needs the conversion
|
// magnitude could reach 1e308 needs the conversion
|
||||||
if (static_cast<long>(int_digits) + exponent > 300)
|
if (static_cast<std::int64_t>(int_digits) + exponent > 300)
|
||||||
{
|
{
|
||||||
const auto v = float_value<double>(reinterpret_cast<const char*>(s), n); // NOLINT(cppcoreguidelines-pro-type-reinterpret-cast)
|
const auto v = float_value<double>(reinterpret_cast<const char*>(s), n); // NOLINT(cppcoreguidelines-pro-type-reinterpret-cast)
|
||||||
return v <= (std::numeric_limits<double>::max)() && v >= -(std::numeric_limits<double>::max)();
|
return v <= (std::numeric_limits<double>::max)() && v >= -(std::numeric_limits<double>::max)();
|
||||||
|
|||||||
Reference in New Issue
Block a user