Fix -Wimplicit-const-int-float-conversion warnings

Compare against 0x1p63 instead of INT64_MAX. Converting INT64_MAX to
double rounds it up to INT64_MAX+1.

It made code like `if (d <= INT64_MAX) v = (int64_t)d;` behave subtly
wrong when `d >= 0x1p63` because then `v = (int64_t)d` wraps around to
a negative value.
This commit is contained in:
Ben Noordhuis 2023-11-01 03:42:42 +01:00
parent 62f67892ad
commit 67585d0421

View file

@ -10738,7 +10738,7 @@ static int JS_ToInt64SatFree(JSContext *ctx, int64_t *pres, JSValue val)
} else {
if (d < INT64_MIN)
*pres = INT64_MIN;
else if (d > INT64_MAX)
else if (d >= 0x1p63)
*pres = INT64_MAX;
else
*pres = (int64_t)d;
@ -53844,7 +53844,7 @@ static JSValue js_atomics_wait(JSContext *ctx,
}
if (JS_ToFloat64(ctx, &d, argv[3]))
return JS_EXCEPTION;
if (isnan(d) || d > INT64_MAX)
if (isnan(d) || d >= 0x1p63)
timeout = INT64_MAX;
else if (d < 0)
timeout = 0;