From 51a2a92502d07926d2d79779bf95e2474d7cec6c Mon Sep 17 00:00:00 2001 From: Adhemerval Zanella Date: Fri, 2 May 2025 14:46:40 -0300 Subject: [PATCH] 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. --- sysdeps/ieee754/ldbl-96/s_llroundl.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sysdeps/ieee754/ldbl-96/s_llroundl.c b/sysdeps/ieee754/ldbl-96/s_llroundl.c index d4babe4418..ad2b3c56c7 100644 --- a/sysdeps/ieee754/ldbl-96/s_llroundl.c +++ b/sysdeps/ieee754/ldbl-96/s_llroundl.c @@ -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. */ -- 2.47.2