From 712ff06cd6ef45aba23900cf552fc00a5ba78788 Mon Sep 17 00:00:00 2001 From: Adhemerval Zanella Date: Mon, 5 May 2025 09:39:07 -0300 Subject: [PATCH] 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 --- sysdeps/ieee754/ldbl-128/s_lrintl.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 -- 2.47.2