]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
math: Fix UB in expm1
authorAdhemerval Zanella <adhemerval.zanella@linaro.org>
Fri, 18 Apr 2025 14:47:42 +0000 (11:47 -0300)
committerAdhemerval Zanella <adhemerval.zanella@linaro.org>
Wed, 7 May 2025 17:21:21 +0000 (14:21 -0300)
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.

sysdeps/ieee754/dbl-64/s_expm1.c

index 1cafeca9c02381a1ef8bdce21b0f45dfe879ce9f..557178f33d1d98b11c8deb31ccae6f4c1a3da749 100644 (file)
@@ -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;