From: Adhemerval Zanella Date: Mon, 5 May 2025 12:39:07 +0000 (-0300) Subject: math: Fix UB in ldbl-128 lrintl X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=712ff06cd6ef45aba23900cf552fc00a5ba78788;p=thirdparty%2Fglibc.git math: Fix UB in ldbl-128 lrintl $ math/test-float128-llrint UBSAN: Undefined behaviour in ../sysdeps/ieee754/float128/../ldbl-128/s_llrintl.c:83:31 left shift of 281474976710656 by 15 cannot be represented in type 'long long int' Aborted UBSAN: Undefined behaviour in ../sysdeps/ieee754/float128/../ldbl-128/s_lrintl.c:111:30 left shift of 281474976710656 by 15 cannot be represented in type 'long int' Aborted --- diff --git a/sysdeps/ieee754/ldbl-128/s_lrintl.c b/sysdeps/ieee754/ldbl-128/s_lrintl.c index e5c0d5adb8..210c47fb3b 100644 --- a/sysdeps/ieee754/ldbl-128/s_lrintl.c +++ b/sysdeps/ieee754/ldbl-128/s_lrintl.c @@ -81,7 +81,7 @@ __lrintl (_Float128 x) result = (j0 < 0 ? 0 : i0 >> (48 - j0)); } else if (j0 >= 112) - result = ((long int) i0 << (j0 - 48)) | (i1 << (j0 - 112)); + result = (i0 << (j0 - 48)) | (i1 << (j0 - 112)); else { #if defined FE_INVALID || defined FE_INEXACT @@ -108,7 +108,7 @@ __lrintl (_Float128 x) if (j0 == 48) result = (long int) i0; else - result = ((long int) i0 << (j0 - 48)) | (i1 >> (112 - j0)); + result = (i0 << (j0 - 48)) | (i1 >> (112 - j0)); } } else