From: Adhemerval Zanella Date: Fri, 18 Apr 2025 14:47:42 +0000 (-0300) Subject: math: Fix UB in expm1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b59c34e8f93a7f2ebf2a3eb5ebb2ed6a0dc6e980;p=thirdparty%2Fglibc.git math: Fix UB in expm1 Building with ubsan triggers: UBSAN: Undefined behaviour in ../sysdeps/ieee754/dbl-64/s_expm1.c:242:4 left shift of 4294967271 by 20 cannot be represented in type 'int' Since at the time k is always positive, just cast to uint32_t. --- diff --git a/sysdeps/ieee754/dbl-64/s_expm1.c b/sysdeps/ieee754/dbl-64/s_expm1.c index 1cafeca9c0..557178f33d 100644 --- a/sysdeps/ieee754/dbl-64/s_expm1.c +++ b/sysdeps/ieee754/dbl-64/s_expm1.c @@ -239,7 +239,7 @@ __expm1 (double x) uint32_t high; y = one - (e - x); GET_HIGH_WORD (high, y); - SET_HIGH_WORD (y, high + (k << 20)); /* add k to y's exponent */ + SET_HIGH_WORD (y, high + ((uint32_t)k << 20)); /* add k to y's exponent */ return y - one; } t = one;