From: Adhemerval Zanella Date: Thu, 1 May 2025 21:14:37 +0000 (-0300) Subject: x86: Fix UB in isinfl X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=258ea844481e987583dc27435960abd44d3cc889;p=thirdparty%2Fglibc.git x86: Fix UB in isinfl 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. --- diff --git a/sysdeps/i386/fpu/s_isinfl.c b/sysdeps/x86/fpu/s_isinfl.c similarity index 88% rename from sysdeps/i386/fpu/s_isinfl.c rename to sysdeps/x86/fpu/s_isinfl.c index ff6048e3f57..66543e2e2ce 100644 --- a/sysdeps/i386/fpu/s_isinfl.c +++ b/sysdeps/x86/fpu/s_isinfl.c @@ -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 index ca818b5e906..00000000000 --- a/sysdeps/x86_64/fpu/s_isinfl.c +++ /dev/null @@ -1 +0,0 @@ -#include