]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
math: Fix UB on lroundl
authorAdhemerval Zanella <adhemerval.zanella@linaro.org>
Fri, 2 May 2025 17:59:13 +0000 (14:59 -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'
Aborted

sysdeps/ieee754/ldbl-96/s_roundl.c

index 91d0c445d89fc181f3279076664f06aa20b75266..8ec77218fb6b5fdc80e60b72eea953a3da172cae 100644 (file)
@@ -72,7 +72,7 @@ __roundl (long double x)
        /* X is integral.  */
        return x;
 
-      uint32_t j = i1 + (1 << (62 - j0));
+      uint32_t j = i1 + (1U << (62 - j0));
       if (j < i1)
        {
          uint32_t k = i0 + 1;