mirror of
https://github.com/nlohmann/json.git
synced 2026-11-17 17:01:30 +00:00
Fix narrowing conversions in serializer for small number_magnitude_t
Cast the results of the integer promotions in count_digits() and remove_sign() back to number_magnitude_t, which is unsigned char or unsigned short for custom number types. Signed-off-by: Niels Lohmann <mail@nlohmann.me>
This commit is contained in:
2 files changed
+4
-4
No files matched your search
@@ -1571,7 +1571,7 @@ class serializer
|
||||
{
|
||||
return n_digits + 3;
|
||||
}
|
||||
x = x / 10000u;
|
||||
x = static_cast<number_magnitude_t>(x / 10000u);
|
||||
n_digits += 4;
|
||||
}
|
||||
}
|
||||
@@ -2200,7 +2200,7 @@ class serializer
|
||||
number_magnitude_t remove_sign(number_integer_t x) noexcept
|
||||
{
|
||||
JSON_ASSERT(x < 0);
|
||||
return static_cast<number_magnitude_t>(-(x + 1)) + 1;
|
||||
return static_cast<number_magnitude_t>(static_cast<number_magnitude_t>(-(x + 1)) + 1);
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
Generated
+2
-2
@@ -39057,7 +39057,7 @@ class serializer
|
||||
{
|
||||
return n_digits + 3;
|
||||
}
|
||||
x = x / 10000u;
|
||||
x = static_cast<number_magnitude_t>(x / 10000u);
|
||||
n_digits += 4;
|
||||
}
|
||||
}
|
||||
@@ -39686,7 +39686,7 @@ class serializer
|
||||
number_magnitude_t remove_sign(number_integer_t x) noexcept
|
||||
{
|
||||
JSON_ASSERT(x < 0);
|
||||
return static_cast<number_magnitude_t>(-(x + 1)) + 1;
|
||||
return static_cast<number_magnitude_t>(static_cast<number_magnitude_t>(-(x + 1)) + 1);
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
Reference in new issue
Block a user