]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
math: Fix UB in ldbl-128 llroundl
authorAdhemerval Zanella <adhemerval.zanella@linaro.org>
Fri, 2 May 2025 18:41:00 +0000 (15:41 -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-float128-llround
testing _Float128 (without inline functions)
UBSAN: Undefined behaviour in ../sysdeps/ieee754/float128/../ldbl-128/s_llroundl.c:65:37 left shift of 562949953421312 by 14 cannot be represented in type 'long long int'
Aborted

sysdeps/ieee754/ldbl-128/s_llroundl.c

index 752b097944b38ce09b2c01b9bc19b0177c496b02..aef602e2f51822f86729de13b4ab9e9f4b5dfe2d 100644 (file)
@@ -62,7 +62,7 @@ __llroundl (_Float128 x)
            result = (long long int) i0;
          else
            {
-             result = ((long long int) i0 << (j0 - 48)) | (j >> (112 - j0));
+             result = (i0 << (j0 - 48)) | (j >> (112 - j0));
 #ifdef FE_INVALID
              if (sign == 1 && result == LLONG_MIN)
                /* Rounding brought the value out of range.  */