From: Adhemerval Zanella Date: Fri, 2 May 2025 18:41:00 +0000 (-0300) Subject: math: Fix UB in ldbl-128 llroundl X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e5387c94938f81882bc82c73348a14b77d8f5f8a;p=thirdparty%2Fglibc.git math: Fix UB in ldbl-128 llroundl Building with --enable-ubasn triggers: $ math/test-float128-llround testing _Float128 (without inline functions) UBSAN: Undefined behaviour in ../sysdeps/ieee754/float128/../ldbl-128/s_llroundl.c:65:37 left shift of 562949953421312 by 14 cannot be represented in type 'long long int' Aborted --- diff --git a/sysdeps/ieee754/ldbl-128/s_llroundl.c b/sysdeps/ieee754/ldbl-128/s_llroundl.c index 752b097944..aef602e2f5 100644 --- a/sysdeps/ieee754/ldbl-128/s_llroundl.c +++ b/sysdeps/ieee754/ldbl-128/s_llroundl.c @@ -62,7 +62,7 @@ __llroundl (_Float128 x) result = (long long int) i0; else { - result = ((long long int) i0 << (j0 - 48)) | (j >> (112 - j0)); + result = (i0 << (j0 - 48)) | (j >> (112 - j0)); #ifdef FE_INVALID if (sign == 1 && result == LLONG_MIN) /* Rounding brought the value out of range. */