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;
|
return n_digits + 3;
|
||||||
}
|
}
|
||||||
x = x / 10000u;
|
x = static_cast<number_magnitude_t>(x / 10000u);
|
||||||
n_digits += 4;
|
n_digits += 4;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2200,7 +2200,7 @@ class serializer
|
|||||||
number_magnitude_t remove_sign(number_integer_t x) noexcept
|
number_magnitude_t remove_sign(number_integer_t x) noexcept
|
||||||
{
|
{
|
||||||
JSON_ASSERT(x < 0);
|
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:
|
private:
|
||||||
|
|||||||
Generated
+2
-2
@@ -39057,7 +39057,7 @@ class serializer
|
|||||||
{
|
{
|
||||||
return n_digits + 3;
|
return n_digits + 3;
|
||||||
}
|
}
|
||||||
x = x / 10000u;
|
x = static_cast<number_magnitude_t>(x / 10000u);
|
||||||
n_digits += 4;
|
n_digits += 4;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -39686,7 +39686,7 @@ class serializer
|
|||||||
number_magnitude_t remove_sign(number_integer_t x) noexcept
|
number_magnitude_t remove_sign(number_integer_t x) noexcept
|
||||||
{
|
{
|
||||||
JSON_ASSERT(x < 0);
|
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:
|
private:
|
||||||
|
|||||||
Reference in new issue
Block a user