Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(73)

Unified Diff: third_party/WebKit/Source/platform/LayoutUnitTest.cpp

Issue 2160983007: Avoid integer overflow in LayoutUnit's unary minus operator (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Full UnaryMinus test case Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/WebKit/Source/platform/LayoutUnit.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/platform/LayoutUnitTest.cpp
diff --git a/third_party/WebKit/Source/platform/LayoutUnitTest.cpp b/third_party/WebKit/Source/platform/LayoutUnitTest.cpp
index 61818cb504c516d24e11d6582b1c949bdfca04f9..4b27c33b7daa8fc4362ceee89d177120cfc002b7 100644
--- a/third_party/WebKit/Source/platform/LayoutUnitTest.cpp
+++ b/third_party/WebKit/Source/platform/LayoutUnitTest.cpp
@@ -256,4 +256,19 @@ TEST(LayoutUnitTest, LayoutUnitFloatOverflow)
EXPECT_EQ(intMinForLayoutUnit, LayoutUnit(-176972000.0).toInt());
}
+TEST(LayoutUnitTest, UnaryMinus)
+{
+ EXPECT_EQ(LayoutUnit(), -LayoutUnit());
+ EXPECT_EQ(LayoutUnit(999), -LayoutUnit(-999));
+ EXPECT_EQ(LayoutUnit(-999), -LayoutUnit(999));
+
+ LayoutUnit negativeMax;
+ negativeMax.setRawValue(LayoutUnit::min().rawValue() + 1);
+ EXPECT_EQ(negativeMax, -LayoutUnit::max());
+ EXPECT_EQ(LayoutUnit::max(), -negativeMax);
+
+ // -LayoutUnit::min() is saturated to LayoutUnit::max()
+ EXPECT_EQ(LayoutUnit::max(), -LayoutUnit::min());
+}
+
} // namespace blink
« no previous file with comments | « third_party/WebKit/Source/platform/LayoutUnit.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698