math: Fix UB on llroundl

Building with --enable-ubasn triggers:

UBSAN: Undefined behaviour in ../sysdeps/ieee754/ldbl-96/s_llroundl.c:70:25 left shift of 4294967296 by 31 cannot be represented in type 'long long int'

The right shift is undefined if value overflow, but code is assuming
an arithmetic shift.
This commit is contained in:
Adhemerval Zanella 2025-05-02 14:46:40 -03:00
parent b7c497474b
commit 51a2a92502
1 changed files with 2 additions and 1 deletions

View File

@ -67,7 +67,8 @@ __llroundl (long double x)
if (j0 > 31)
{
result = (result << (j0 - 31)) | (j >> (63 - j0));
result = ((unsigned long long int)result << (j0 - 31))
| (j >> (63 - j0));
#ifdef FE_INVALID
if (sign == 1 && result == LLONG_MIN)
/* Rounding brought the value out of range. */