]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
x86: Fix UB in isinfl
authorAdhemerval Zanella <adhemerval.zanella@linaro.org>
Thu, 1 May 2025 21:14:37 +0000 (18:14 -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-isinf
UBSAN: Undefined behaviour in ../sysdeps/x86/fpu/s_isinfl.c:25:8 negation of 2147483648 cannot be represented in type 'int'

Also move the isinfl implementation to sysdeps/x86 and remove the
sysdeps/x86_64 version.

sysdeps/x86/fpu/s_isinfl.c [moved from sysdeps/i386/fpu/s_isinfl.c with 88% similarity]
sysdeps/x86_64/fpu/s_isinfl.c [deleted file]

similarity index 88%
rename from sysdeps/i386/fpu/s_isinfl.c
rename to sysdeps/x86/fpu/s_isinfl.c
index ff6048e3f5762ab94a1abc0dd9ae264e50b690c5..66543e2e2cec687f5f4c6c75a7d34236fd7410fc 100644 (file)
@@ -17,14 +17,15 @@ static char rcsid[] = "$NetBSD: $";
 
 int __isinfl(long double x)
 {
-       int32_t se,hx,lx;
+       int se;
+       unsigned int hx, lx;
        GET_LDOUBLE_WORDS(se,hx,lx,x);
        /* This additional ^ 0x80000000 is necessary because in Intel's
           internal representation of the implicit one is explicit.  */
        lx |= (hx ^ 0x80000000) | ((se & 0x7fff) ^ 0x7fff);
        lx |= -lx;
        se &= 0x8000;
-       return ~(lx >> 31) & (1 - (se >> 14));
+       return ~((int)lx >> 31) & (1 - (se >> 14));
 }
 hidden_def (__isinfl)
 weak_alias (__isinfl, isinfl)
diff --git a/sysdeps/x86_64/fpu/s_isinfl.c b/sysdeps/x86_64/fpu/s_isinfl.c
deleted file mode 100644 (file)
index ca818b5..0000000
+++ /dev/null
@@ -1 +0,0 @@
-#include <sysdeps/i386/fpu/s_isinfl.c>