[FXCRT] Fix checks in FXSYS_round() for float precision
Resolve the floating precision error that happens at the edge of the
integer range.
Bug: chromium:611744
Change-Id: I01a0111740785fc68b59861b1c6ec07b6ccbef5d
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/60550
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
diff --git a/core/fxcrt/fx_system.cpp b/core/fxcrt/fx_system.cpp
index 4f95b6a..f8a48db 100644
--- a/core/fxcrt/fx_system.cpp
+++ b/core/fxcrt/fx_system.cpp
@@ -93,7 +93,7 @@
return 0;
if (f < static_cast<float>(std::numeric_limits<int>::min()))
return std::numeric_limits<int>::min();
- if (f > static_cast<float>(std::numeric_limits<int>::max()))
+ if (f >= static_cast<float>(std::numeric_limits<int>::max()))
return std::numeric_limits<int>::max();
return static_cast<int>(round(f));
}
diff --git a/core/fxcrt/fx_system_unittest.cpp b/core/fxcrt/fx_system_unittest.cpp
index 83ac625..b28f18e 100644
--- a/core/fxcrt/fx_system_unittest.cpp
+++ b/core/fxcrt/fx_system_unittest.cpp
@@ -102,8 +102,7 @@
EXPECT_EQ(2147483520, FXSYS_round(2.14748352e+9f));
// Using a slightly larger value, expect to see it be capped at MAX_INT.
- // Instead erroneously seeing a return of MIN_INT. crbug.com/611744
- EXPECT_EQ(-2147483648, FXSYS_round(2.14748365e+9f));
+ EXPECT_EQ(2147483647, FXSYS_round(2.14748365e+9f));
EXPECT_EQ(2147483647, FXSYS_round(2.14748365e+10f));
EXPECT_EQ(2147483647, FXSYS_round(std::numeric_limits<float>::max()));