commit 264a19f4f5441b9e5e0d17999c7a5d8ecf358ae9
parent 044ffc2cc3e5fa67ad4ae6a14eb3790355b597bf
Author: Fabrice Bellard <fabrice@bellard.org>
Date: Sat, 3 Feb 2024 15:48:57 +0100
avoid using INT64_MAX in double comparisons because it cannot be exactly represented as a double (bnoordhuis)
Diffstat:
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/quickjs/quickjs.c b/quickjs/quickjs.c
@@ -10786,7 +10786,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) /* must use INT64_MAX + 1 because INT64_MAX cannot be exactly represented as a double */
*pres = INT64_MAX;
else
*pres = (int64_t)d;
@@ -55647,7 +55647,8 @@ static JSValue js_atomics_wait(JSContext *ctx,
}
if (JS_ToFloat64(ctx, &d, argv[3]))
return JS_EXCEPTION;
- if (isnan(d) || d > INT64_MAX)
+ /* must use INT64_MAX + 1 because INT64_MAX cannot be exactly represented as a double */
+ if (isnan(d) || d >= 0x1p63)
timeout = INT64_MAX;
else if (d < 0)
timeout = 0;