Commit 11e70024 authored by Zhi An Ng's avatar Zhi An Ng Committed by Commit Bot

Use safe conversion helper to check conversion limits

We fixed float->uint conversion checks in https://crrev.com/c/2491382,
and so we can use those checks here.

Bug: v8:10933
Change-Id: Ie2697aaf8fb7761541aca60d5d0a8812a8f39e41
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2497383Reviewed-by: 's avatarJakob Kummerow <jkummerow@chromium.org>
Commit-Queue: Zhi An Ng <zhin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#70776}
parent e363ee3c
......@@ -190,11 +190,7 @@ int32_t float32_to_int64_wrapper(Address data) {
int32_t float32_to_uint64_wrapper(Address data) {
float input = ReadUnalignedValue<float>(data);
// We use "<" here to check the upper bound because of rounding problems: With
// "<=" some inputs would be considered within uint64 range which are actually
// not within uint64 range.
if (input > -1.0 &&
input < static_cast<float>(std::numeric_limits<uint64_t>::max())) {
if (base::IsValueInRangeForNumericType<uint64_t>(input)) {
WriteUnalignedValue<uint64_t>(data, static_cast<uint64_t>(input));
return 1;
}
......@@ -211,12 +207,8 @@ int32_t float64_to_int64_wrapper(Address data) {
}
int32_t float64_to_uint64_wrapper(Address data) {
// We use "<" here to check the upper bound because of rounding problems: With
// "<=" some inputs would be considered within uint64 range which are actually
// not within uint64 range.
double input = ReadUnalignedValue<double>(data);
if (input > -1.0 &&
input < static_cast<double>(std::numeric_limits<uint64_t>::max())) {
if (base::IsValueInRangeForNumericType<uint64_t>(input)) {
WriteUnalignedValue<uint64_t>(data, static_cast<uint64_t>(input));
return 1;
}
......@@ -242,11 +234,7 @@ void float32_to_int64_sat_wrapper(Address data) {
void float32_to_uint64_sat_wrapper(Address data) {
float input = ReadUnalignedValue<float>(data);
// We use "<" here to check the upper bound because of rounding problems: With
// "<=" some inputs would be considered within uint64 range which are actually
// not within uint64 range.
if (input < static_cast<float>(std::numeric_limits<uint64_t>::max()) &&
input >= 0.0) {
if (base::IsValueInRangeForNumericType<uint64_t>(input)) {
WriteUnalignedValue<uint64_t>(data, static_cast<uint64_t>(input));
return;
}
......@@ -276,11 +264,7 @@ void float64_to_int64_sat_wrapper(Address data) {
void float64_to_uint64_sat_wrapper(Address data) {
double input = ReadUnalignedValue<double>(data);
// We use "<" here to check the upper bound because of rounding problems: With
// "<=" some inputs would be considered within int64 range which are actually
// not within int64 range.
if (input < static_cast<double>(std::numeric_limits<uint64_t>::max()) &&
input >= 0.0) {
if (base::IsValueInRangeForNumericType<uint64_t>(input)) {
WriteUnalignedValue<uint64_t>(data, static_cast<uint64_t>(input));
return;
}
......
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