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

Unified Diff: test/cctest/test-utils.cc

Issue 335063005: Re-land "Clusterfuzz identified overflow check needed in dehoisting." (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Use safe numerics library for overflow checks. Created 6 years, 6 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
Index: test/cctest/test-utils.cc
diff --git a/test/cctest/test-utils.cc b/test/cctest/test-utils.cc
index 09206387ac7ceed3ef3b2dd0efa0f2b7a3fecbaf..3b866065efbc7f0fb4c8bcb085472956d6577ee7 100644
--- a/test/cctest/test-utils.cc
+++ b/test/cctest/test-utils.cc
@@ -218,3 +218,33 @@ TEST(SequenceCollectorRegression) {
CHECK_EQ(0, strncmp("0123456789012345678901234567890123",
seq.start(), seq.length()));
}
+
+
+#define MAX_VALUE(type) std::numeric_limits<type>::max()
+
+TEST(OverflowChecks) {
+ // int32_t
+ CHECK(!MultiplyOverflows<int32_t>(50, 50));
+ CHECK(MultiplyOverflows<int32_t>(MAX_VALUE(int32_t), 4));
+
+ CHECK(!AdditionOverflows<int32_t>(50, 50));
+ CHECK(!AdditionOverflows<int32_t>(MAX_VALUE(int32_t) - 1, 1));
+ CHECK(AdditionOverflows<int32_t>(MAX_VALUE(int32_t), 1));
+
+ // uint32_t
+ CHECK(!MultiplyOverflows<uint32_t>(MAX_VALUE(int32_t), 2));
+ CHECK(MultiplyOverflows<uint32_t>(MAX_VALUE(int32_t), 4));
+
+ CHECK(!AdditionOverflows<uint32_t>(MAX_VALUE(int32_t), 1));
+ CHECK(AdditionOverflows<uint32_t>(MAX_VALUE(uint32_t), 1));
+
+ // signed char
+ CHECK(AdditionOverflows<int8_t>(MAX_VALUE(int8_t), 1));
+ CHECK(MultiplyOverflows<int8_t>(64, 4));
+
+ // unsigned char
+ CHECK(!AdditionOverflows<uint8_t>(MAX_VALUE(int8_t), 1));
+ CHECK(AdditionOverflows<uint8_t>(MAX_VALUE(uint8_t), 1));
+ CHECK(!MultiplyOverflows<uint8_t>(64, 3));
+ CHECK(MultiplyOverflows<uint8_t>(64, 4));
+}
« src/utils.h ('K') | « src/utils.h ('k') | test/mjsunit/regress/regress-380092.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698