]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
math: Fix UB in ldbl-128 setpayload
authorAdhemerval Zanella <adhemerval.zanella@linaro.org>
Mon, 5 May 2025 15:28:25 +0000 (12:28 -0300)
committerAdhemerval Zanella <adhemerval.zanella@linaro.org>
Thu, 8 May 2025 12:25:49 +0000 (09:25 -0300)
UBSAN: Undefined behaviour in ../sysdeps/ieee754/float128/../ldbl-128/s_setpayloadl_main.c:47:34 shift exponent 16431 is too large for 64-bit type 'long long unsigned int'

sysdeps/ieee754/ldbl-128/s_setpayloadl_main.c

index f106ede9a4ea1acacc860ca643366749f03039db..377428d1aaf22410ab94e955779fef99f70cce93 100644 (file)
@@ -44,7 +44,8 @@ FUNC (_Float128 *x, _Float128 payload)
   int shift = BIAS + EXPLICIT_MANT_DIG - exponent;
   if (shift < 64
       ? (lx & ((1ULL << shift) - 1)) != 0
-      : (lx != 0 || (hx & ((1ULL << (shift - 64)) - 1)) != 0))
+      : (shift < 128
+        && (lx != 0 || (hx & ((1ULL << (shift - 64)) - 1)) != 0)))
     {
       SET_LDOUBLE_WORDS64 (*x, 0, 0);
       return 1;