Prevent shift overflow in FloatTo7e3/FloatTo6e4 (#129)

This commit is contained in:
Triang3l 2019-04-17 02:17:56 +03:00 committed by Chuck Walbourn
parent 00b785eea1
commit c7261a0951

View File

@ -37,7 +37,7 @@ namespace
{ {
// The number is too small to be represented as a normalized 7e3. // The number is too small to be represented as a normalized 7e3.
// Convert it to a denormalized value. // Convert it to a denormalized value.
uint32_t Shift = 125U - (IValue >> 23U); uint32_t Shift = std::min<uint32_t>(125U - (IValue >> 23U), 24U);
IValue = (0x800000U | (IValue & 0x7FFFFFU)) >> Shift; IValue = (0x800000U | (IValue & 0x7FFFFFU)) >> Shift;
} }
else else
@ -103,7 +103,7 @@ namespace
{ {
// The number is too small to be represented as a normalized 6e4. // The number is too small to be represented as a normalized 6e4.
// Convert it to a denormalized value. // Convert it to a denormalized value.
uint32_t Shift = 121U - (IValue >> 23U); uint32_t Shift = std::min<uint32_t>(121U - (IValue >> 23U), 24U);
IValue = (0x800000U | (IValue & 0x7FFFFFU)) >> Shift; IValue = (0x800000U | (IValue & 0x7FFFFFU)) >> Shift;
} }
else else