🚑 fix to address #389
This commit is contained in:
parent
447e01427d
commit
79fa8b2f41
3 changed files with 49 additions and 2 deletions
17
src/json.hpp
17
src/json.hpp
|
|
@ -10643,7 +10643,22 @@ basic_json_parser_66:
|
|||
}
|
||||
else if (type == value_t::number_integer)
|
||||
{
|
||||
result.m_value.number_integer = -static_cast<number_integer_t>(value);
|
||||
// invariant: if we parsed a '-', the absolute value is between
|
||||
// 0 (we allow -0) and max == -INT64_MIN
|
||||
assert(value >= 0);
|
||||
assert(value <= max);
|
||||
|
||||
if (value == max)
|
||||
{
|
||||
// we cannot simply negate value (== max == -INT64_MIN),
|
||||
// see https://github.com/nlohmann/json/issues/389
|
||||
result.m_value.number_integer = INT64_MIN;
|
||||
}
|
||||
else
|
||||
{
|
||||
// all other values can be negated safely
|
||||
result.m_value.number_integer = -static_cast<number_integer_t>(value);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
|||
|
|
@ -9793,7 +9793,22 @@ class basic_json
|
|||
}
|
||||
else if (type == value_t::number_integer)
|
||||
{
|
||||
result.m_value.number_integer = -static_cast<number_integer_t>(value);
|
||||
// invariant: if we parsed a '-', the absolute value is between
|
||||
// 0 (we allow -0) and max == -INT64_MIN
|
||||
assert(value >= 0);
|
||||
assert(value <= max);
|
||||
|
||||
if (value == max)
|
||||
{
|
||||
// we cannot simply negate value (== max == -INT64_MIN),
|
||||
// see https://github.com/nlohmann/json/issues/389
|
||||
result.m_value.number_integer = INT64_MIN;
|
||||
}
|
||||
else
|
||||
{
|
||||
// all other values can be negated safely
|
||||
result.m_value.number_integer = -static_cast<number_integer_t>(value);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue