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:
Niels Lohmann committed 2026-11-17 17:19:50 +01:00
1 parent b73b7c72db
commit 877aea39b0
2 files changed
+4 -4

No files matched your search

+2 -2
View File
@@ -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: