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

Unified Diff: runtime/vm/object_test.cc

Issue 1096063002: Fix array allocation overflow check on arm/arm64/mips. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 5 years, 8 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 | « runtime/vm/intrinsifier_mips.cc ('k') | runtime/vm/stub_code_arm.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/object_test.cc
===================================================================
--- runtime/vm/object_test.cc (revision 45353)
+++ runtime/vm/object_test.cc (working copy)
@@ -2000,6 +2000,60 @@
}
+static void TestIllegalTypedDataLength(const char* class_name,
+ intptr_t length) {
+ char buffer[1024];
+ OS::SNPrint(buffer, sizeof(buffer),
+ "import 'dart:typed_data';\n"
+ "main() {\n"
+ " new %s(%" Pd ");\n"
+ "}\n",
+ class_name, length);
+ Dart_Handle lib = TestCase::LoadTestScript(buffer, NULL);
+ EXPECT_VALID(lib);
+ Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL);
+ OS::SNPrint(buffer, sizeof(buffer), "%" Pd, length);
+ EXPECT_ERROR(result, "Invalid argument(s)");
+ EXPECT_ERROR(result, buffer);
+}
+
+
+TEST_CASE(Int8ListLengthNegativeOne) {
+ TestIllegalTypedDataLength("Int8List", -1);
+}
+TEST_CASE(Int8ListLengthSmiMin) {
+ TestIllegalTypedDataLength("Int8List", kSmiMin);
+}
+TEST_CASE(Int8ListLengthOneTooMany) {
+ const intptr_t kOneTooMany =
+ TypedData::MaxElements(kTypedDataInt8ArrayCid) + 1;
+ ASSERT(kOneTooMany >= 0);
+ TestIllegalTypedDataLength("Int8List", kOneTooMany);
+}
+
+
+TEST_CASE(Int8ListLengthMaxElements) {
+ const intptr_t max_elements = TypedData::MaxElements(kTypedDataInt8ArrayCid);
+ char buffer[1024];
+ OS::SNPrint(buffer, sizeof(buffer),
+ "import 'dart:typed_data';\n"
+ "main() {\n"
+ " return new Int8List(%" Pd ");\n"
+ "}\n",
+ max_elements);
+ Dart_Handle lib = TestCase::LoadTestScript(buffer, NULL);
+ EXPECT_VALID(lib);
+ Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL);
+ if (Dart_IsError(result)) {
+ EXPECT_ERROR(result, "Out of Memory");
+ } else {
+ intptr_t actual = 0;
+ EXPECT_VALID(Dart_ListLength(result, &actual));
+ EXPECT_EQ(max_elements, actual);
+ }
+}
+
+
TEST_CASE(StringCodePointIterator) {
const String& str0 = String::Handle(String::New(""));
String::CodePointIterator it0(str0);
« no previous file with comments | « runtime/vm/intrinsifier_mips.cc ('k') | runtime/vm/stub_code_arm.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698