]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
math: Fix UB in __ieee754_rem_pio2l
authorAdhemerval Zanella <adhemerval.zanella@linaro.org>
Mon, 5 May 2025 13:37:57 +0000 (10:37 -0300)
committerAdhemerval Zanella <adhemerval.zanella@linaro.org>
Thu, 8 May 2025 12:25:49 +0000 (09:25 -0300)
sysdeps/ieee754/ldbl-128/e_rem_pio2l.c

index 5a438a5efa0f99035a047d7cb4d1dcbfc28de519..ad3f13ba2eb045816d59c18fa75111a356617c58 100644 (file)
@@ -243,11 +243,11 @@ int32_t __ieee754_rem_pio2l(_Float128 x, _Float128 *y)
   /* This is faster than doing this in floating point, because we
      have to convert it to integers anyway and like this we can keep
      both integer and floating point units busy.  */
-  tx [0] = (double)(((ix >> 25) & 0x7fffff) | 0x800000);
-  tx [1] = (double)((ix >> 1) & 0xffffff);
-  tx [2] = (double)(((ix << 23) | (lx >> 41)) & 0xffffff);
-  tx [3] = (double)((lx >> 17) & 0xffffff);
-  tx [4] = (double)((lx << 7) & 0xffffff);
+  tx [0] = (double)((((uint64_t)ix >> 25) & 0x7fffff) | 0x800000);
+  tx [1] = (double)(((uint64_t)ix >> 1) & 0xffffff);
+  tx [2] = (double)((((uint64_t)ix << 23) | (lx >> 41)) & 0xffffff);
+  tx [3] = (double)(((uint64_t)lx >> 17) & 0xffffff);
+  tx [4] = (double)(((uint64_t)lx << 7) & 0xffffff);
 
   n = __kernel_rem_pio2 (tx, tx + 5, exp, ((lx << 7) & 0xffffff) ? 5 : 4,
                         3, two_over_pi);