Commit 0391a8c5 authored by Yang Guo's avatar Yang Guo Committed by Commit Bot

Fix undefined behavior wrt float-cast-overflow in conversions-inl.h.

Patch by Rumeet Dhindsa <rdhindsa@google.com>.

R=jkummerow@chromium.org

Change-Id: Ibff1af58bbdae52c6fb24b3d98d25e52cee0b63c
Reviewed-on: https://chromium-review.googlesource.com/899006
Commit-Queue: Yang Guo <yangguo@chromium.org>
Reviewed-by: 's avatarJakob Kummerow <jkummerow@chromium.org>
Cr-Commit-Position: refs/heads/master@{#51096}
parent 59e87d64
......@@ -72,8 +72,10 @@ inline double DoubleToInteger(double x) {
int32_t DoubleToInt32(double x) {
int32_t i = FastD2I(x);
if (FastI2D(i) == x) return i;
if ((std::isfinite(x)) && (x <= INT_MAX) && (x >= INT_MIN)) {
int32_t i = static_cast<int32_t>(x);
if (FastI2D(i) == x) return i;
}
Double d(x);
int exponent = d.Exponent();
if (exponent < 0) {
......@@ -94,14 +96,15 @@ bool DoubleToSmiInteger(double value, int* smi_int_value) {
}
bool IsSmiDouble(double value) {
return !IsMinusZero(value) && value >= Smi::kMinValue &&
value <= Smi::kMaxValue && value == FastI2D(FastD2I(value));
return std::isfinite(value) && !IsMinusZero(value) &&
value >= Smi::kMinValue && value <= Smi::kMaxValue &&
value == FastI2D(FastD2I(value));
}
bool IsInt32Double(double value) {
return !IsMinusZero(value) && value >= kMinInt && value <= kMaxInt &&
value == FastI2D(FastD2I(value));
return std::isfinite(value) && !IsMinusZero(value) && value >= kMinInt &&
value <= kMaxInt && value == FastI2D(FastD2I(value));
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment