Skip to content

Commit

Permalink
Fix errors reported by cppcheck in src/libm/sleefsp.c
Browse files Browse the repository at this point in the history
Error: integer overflow
Fix: Use appropriate intermediate type. UL should be big enough
     on all platforms.
  • Loading branch information
blapie committed Oct 18, 2024
1 parent 42ba65e commit d112ebc
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/libm/sleefsp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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); }
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit d112ebc

Please sign in to comment.