Saturated arithmetics: Incorrect float/double clamping.
authorzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 1 Jan 2015 08:32:27 +0000 (08:32 +0000)
committerzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 1 Jan 2015 08:32:27 +0000 (08:32 +0000)
https://bugs.webkit.org/show_bug.cgi?id=139888
rdar://problem/19330885

Reviewed by Simon Fraser.

Clamp float and double values correctly when applying saturated arithmetics.

Source/WebCore:

Test: LayoutUnit test for float overflow.

* platform/LayoutUnit.h:
(WebCore::LayoutUnit::LayoutUnit):

Tools:

* TestWebKitAPI/Tests/WebCore/LayoutUnit.cpp:
(TestWebKitAPI::TEST):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@177845 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/platform/LayoutUnit.h
Tools/ChangeLog
Tools/TestWebKitAPI/Tests/WebCore/LayoutUnit.cpp

index 7587ef1..6189736 100644 (file)
@@ -1,3 +1,18 @@
+2015-01-01  Zalan Bujtas  <zalan@apple.com>
+
+        Saturated arithmetics: Incorrect float/double clamping.
+        https://bugs.webkit.org/show_bug.cgi?id=139888
+        rdar://problem/19330885
+
+        Reviewed by Simon Fraser.
+
+        Clamp float and double values correctly when applying saturated arithmetics.
+
+        Test: LayoutUnit test for float overflow.
+
+        * platform/LayoutUnit.h:
+        (WebCore::LayoutUnit::LayoutUnit):
+
 2014-12-31  Dan Bernstein  <mitz@apple.com>
 
         Fixed the iOS build.
index 5970de9..31955f2 100644 (file)
@@ -86,7 +86,7 @@ public:
     LayoutUnit(float value)
     {
 #if ENABLE(SATURATED_LAYOUT_ARITHMETIC)
-        m_value = clampTo<float>(value * kFixedPointDenominator, static_cast<float>(INT_MIN), static_cast<float>(INT_MAX));
+        m_value = clampToInteger(value * kFixedPointDenominator);
 #else
         REPORT_OVERFLOW(isInBounds(value));
         m_value = value * kFixedPointDenominator;
@@ -95,7 +95,7 @@ public:
     LayoutUnit(double value)
     {
 #if ENABLE(SATURATED_LAYOUT_ARITHMETIC)
-        m_value = clampTo<double>(value * kFixedPointDenominator, static_cast<double>(INT_MIN), static_cast<double>(INT_MAX));
+        m_value = clampToInteger(value * kFixedPointDenominator);
 #else
         REPORT_OVERFLOW(isInBounds(value));
         m_value = value * kFixedPointDenominator;
index d6ac4cd..599480a 100644 (file)
@@ -1,3 +1,16 @@
+2015-01-01  Zalan Bujtas  <zalan@apple.com>
+
+        Saturated arithmetics: Incorrect float/double clamping.
+        https://bugs.webkit.org/show_bug.cgi?id=139888
+        rdar://problem/19330885
+
+        Reviewed by Simon Fraser.
+
+        Clamp float and double values correctly when applying saturated arithmetics.
+
+        * TestWebKitAPI/Tests/WebCore/LayoutUnit.cpp:
+        (TestWebKitAPI::TEST):
+
 2014-12-30  Krzysztof Czech  <k.czech@samsung.com>
 
         [EFL] Bump version of ATK used by jhbuild to 2.15.2
index 16372c6..fe880ef 100644 (file)
@@ -76,6 +76,10 @@ TEST(WebCoreLayoutUnit, LayoutUnitFloat)
     ASSERT_NEAR(LayoutUnit(345634.12335f).toFloat(), 345634.12335f, tolerance);
     ASSERT_NEAR(LayoutUnit(-345634.12335f).toFloat(), -345634.12335f, tolerance);
     ASSERT_NEAR(LayoutUnit(-345634).toFloat(), -345634.0f, tolerance);    
+    ASSERT_NEAR(LayoutUnit(33554432.f).toFloat(), 33554432.f, tolerance);
+    ASSERT_NEAR(LayoutUnit(-33554432.f).toFloat(), -33554432.f, tolerance);
+    ASSERT_NEAR(LayoutUnit(33554432.f).toDouble(), 33554432.f, tolerance);
+    ASSERT_NEAR(LayoutUnit(-33554432.f).toDouble(), -33554432.f, tolerance);
 }
 
 TEST(WebCoreLayoutUnit, LayoutUnitRounding)