Skip to content

Commit

Permalink
Fix -Wimplicit-const-int-float-conversion warnings
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bnoordhuis committed Nov 1, 2023
1 parent 62f6789 commit 67585d0
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions quickjs.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 67585d0

Please sign in to comment.