math: Fix UB in setayload

The code can shift the 1ULL for value larger than 63 depending of
the exponent value.  Add a check prior the shift.
This commit is contained in:
Adhemerval Zanella 2025-04-21 15:12:21 -03:00
parent b26c1af4bd
commit beb6d2de65
1 changed files with 3 additions and 1 deletions

View File

@ -37,7 +37,9 @@ FUNC (double *x, double payload)
except for 0 when allowed; (c) not an integer. */
if (exponent >= BIAS + PAYLOAD_DIG
|| (exponent < BIAS && !(SET_HIGH_BIT && ix == 0))
|| (ix & ((1ULL << (BIAS + EXPLICIT_MANT_DIG - exponent)) - 1)) != 0)
|| ((BIAS + EXPLICIT_MANT_DIG - exponent) < 64
&& (ix & ((1ULL << (BIAS + EXPLICIT_MANT_DIG - exponent)) - 1))
!= 0))
{
INSERT_WORDS64 (*x, 0);
return 1;