summaryrefslogtreecommitdiff
path: root/quickjs.c
diff options
context:
space:
mode:
authorFabrice Bellard <fabrice@bellard.org>2024-02-03 15:48:57 +0100
committerFabrice Bellard <fabrice@bellard.org>2024-02-03 15:48:57 +0100
commit6f480abbc8b2abe91fcc0fa58aa07c367e1dcb36 (patch)
tree8d3cb61fd096dd5da838efde4a610ade07a8061a /quickjs.c
parent1ed38eef33b7c38024215b2d4177beb4f68e989f (diff)
downloadquickjs-6f480abbc8b2abe91fcc0fa58aa07c367e1dcb36.tar.gz
quickjs-6f480abbc8b2abe91fcc0fa58aa07c367e1dcb36.zip
avoid using INT64_MAX in double comparisons because it cannot be exactly represented as a double (bnoordhuis)
Diffstat (limited to 'quickjs.c')
-rw-r--r--quickjs.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/quickjs.c b/quickjs.c
index 5923a87..7958f81 100644
--- a/quickjs.c
+++ b/quickjs.c
@@ -10771,7 +10771,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;
@@ -55350,7 +55350,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;