]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
math: Fix UB on ldbl-96 remquol
authorAdhemerval Zanella <adhemerval.zanella@linaro.org>
Fri, 2 May 2025 18:15:45 +0000 (15:15 -0300)
committerAdhemerval Zanella <adhemerval.zanella@linaro.org>
Thu, 8 May 2025 12:25:49 +0000 (09:25 -0300)
Building with --enable-ubasn triggers:

$ math/test-ldouble-pow
testing long double (without inline functions)
UBSAN: Undefined behaviour in ../sysdeps/ieee754/ldbl-96/s_roundl.c:75:28 left shift of 1 by 31 cannot be represented in type 'int'

sysdeps/ieee754/ldbl-96/s_remquol.c

index 65a22bb5e48f3051cc07fd2a207782f826ab634b..27c6fbaa2d4af20d83dd38e371a899c701960df4 100644 (file)
@@ -50,7 +50,7 @@ __remquol (long double x, long double p, int *quo)
   if (ep <= 0x7ffb)
     x = __ieee754_fmodl (x, 8 * p);            /* now x < 8p */
 
-  if (((ex - ep) | (hx - hp) | (lx - lp)) == 0)
+  if ((ex == ep) && (hx == hp) && (lx == lp))
     {
       *quo = qs ? -1 : 1;
       return zero * x;