From d112ebcbbbe5c9124c28d2ec996399d67ed77c59 Mon Sep 17 00:00:00 2001 From: Pierre Blanchard Date: Tue, 15 Oct 2024 12:55:37 +0000 Subject: [PATCH] Fix errors reported by cppcheck in src/libm/sleefsp.c Error: integer overflow Fix: Use appropriate intermediate type. UL should be big enough on all platforms. --- src/libm/sleefsp.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/libm/sleefsp.c b/src/libm/sleefsp.c index 7d53b573..1f80522e 100644 --- a/src/libm/sleefsp.c +++ b/src/libm/sleefsp.c @@ -53,11 +53,11 @@ static INLINE CONST float fabsfk(float x) { } static INLINE CONST float mulsignf(float x, float y) { - return intBitsToFloat(floatToRawIntBits(x) ^ (floatToRawIntBits(y) & (1 << 31))); + return intBitsToFloat(floatToRawIntBits(x) ^ (floatToRawIntBits(y) & 0x80000000U)); } static INLINE CONST float copysignfk(float x, float y) { - return intBitsToFloat((floatToRawIntBits(x) & ~(1 << 31)) ^ (floatToRawIntBits(y) & (1 << 31))); + return intBitsToFloat((floatToRawIntBits(x) & ~0x80000000U) ^ (floatToRawIntBits(y) & 0x80000000U)); } static INLINE CONST float signf(float d) { return mulsignf(1, d); } @@ -1920,11 +1920,11 @@ EXPORT CONST float xnextafterf(float x, float y) { cxf = x == 0 ? mulsignf(0, y) : x; memcpy(&cxi, &cxf, sizeof(cxi)); int c = (cxi < 0) == (y < x); - if (c) cxi = -(cxi ^ (1 << 31)); + if (c) cxi = -(cxi ^ 0x80000000U); if (x != y) cxi--; - if (c) cxi = -(cxi ^ (1 << 31)); + if (c) cxi = -(cxi ^ 0x80000000U); memcpy(&cxf, &cxi, sizeof(cxf)); if (cxf == 0 && x != 0) cxf = mulsignf(0, x);