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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "platform/globals.h" 5 #include "platform/globals.h"
6 6
7 #include "vm/assembler.h" 7 #include "vm/assembler.h"
8 #include "vm/class_finalizer.h" 8 #include "vm/class_finalizer.h"
9 #include "vm/dart_api_impl.h" 9 #include "vm/dart_api_impl.h"
10 #include "vm/dart_entry.h" 10 #include "vm/dart_entry.h"
(...skipping 1982 matching lines...) Expand 10 before | Expand all | Expand 10 after
1993 EXPECT_ERROR(result, "Out of Memory"); 1993 EXPECT_ERROR(result, "Out of Memory");
1994 } else { 1994 } else {
1995 const intptr_t kExpected = Array::kMaxElements; 1995 const intptr_t kExpected = Array::kMaxElements;
1996 intptr_t actual = 0; 1996 intptr_t actual = 0;
1997 EXPECT_VALID(Dart_ListLength(result, &actual)); 1997 EXPECT_VALID(Dart_ListLength(result, &actual));
1998 EXPECT_EQ(kExpected, actual); 1998 EXPECT_EQ(kExpected, actual);
1999 } 1999 }
2000 } 2000 }
2001 2001
2002 2002
2003 static void TestIllegalTypedDataLength(const char* class_name,
2004 intptr_t length) {
2005 char buffer[1024];
2006 OS::SNPrint(buffer, sizeof(buffer),
2007 "import 'dart:typed_data';\n"
2008 "main() {\n"
2009 " new %s(%" Pd ");\n"
2010 "}\n",
2011 class_name, length);
2012 Dart_Handle lib = TestCase::LoadTestScript(buffer, NULL);
2013 EXPECT_VALID(lib);
2014 Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL);
2015 OS::SNPrint(buffer, sizeof(buffer), "%" Pd, length);
2016 EXPECT_ERROR(result, "Invalid argument(s)");
2017 EXPECT_ERROR(result, buffer);
2018 }
2019
2020
2021 TEST_CASE(Int8ListLengthNegativeOne) {
2022 TestIllegalTypedDataLength("Int8List", -1);
2023 }
2024 TEST_CASE(Int8ListLengthSmiMin) {
2025 TestIllegalTypedDataLength("Int8List", kSmiMin);
2026 }
2027 TEST_CASE(Int8ListLengthOneTooMany) {
2028 const intptr_t kOneTooMany =
2029 TypedData::MaxElements(kTypedDataInt8ArrayCid) + 1;
2030 ASSERT(kOneTooMany >= 0);
2031 TestIllegalTypedDataLength("Int8List", kOneTooMany);
2032 }
2033
2034
2035 TEST_CASE(Int8ListLengthMaxElements) {
2036 const intptr_t max_elements = TypedData::MaxElements(kTypedDataInt8ArrayCid);
2037 char buffer[1024];
2038 OS::SNPrint(buffer, sizeof(buffer),
2039 "import 'dart:typed_data';\n"
2040 "main() {\n"
2041 " return new Int8List(%" Pd ");\n"
2042 "}\n",
2043 max_elements);
2044 Dart_Handle lib = TestCase::LoadTestScript(buffer, NULL);
2045 EXPECT_VALID(lib);
2046 Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL);
2047 if (Dart_IsError(result)) {
2048 EXPECT_ERROR(result, "Out of Memory");
2049 } else {
2050 intptr_t actual = 0;
2051 EXPECT_VALID(Dart_ListLength(result, &actual));
2052 EXPECT_EQ(max_elements, actual);
2053 }
2054 }
2055
2056
2003 TEST_CASE(StringCodePointIterator) { 2057 TEST_CASE(StringCodePointIterator) {
2004 const String& str0 = String::Handle(String::New("")); 2058 const String& str0 = String::Handle(String::New(""));
2005 String::CodePointIterator it0(str0); 2059 String::CodePointIterator it0(str0);
2006 EXPECT(!it0.Next()); 2060 EXPECT(!it0.Next());
2007 2061
2008 const String& str1 = String::Handle(String::New(" \xc3\xa7 ")); 2062 const String& str1 = String::Handle(String::New(" \xc3\xa7 "));
2009 String::CodePointIterator it1(str1); 2063 String::CodePointIterator it1(str1);
2010 EXPECT(it1.Next()); 2064 EXPECT(it1.Next());
2011 EXPECT_EQ(' ', it1.Current()); 2065 EXPECT_EQ(' ', it1.Current());
2012 EXPECT(it1.Next()); 2066 EXPECT(it1.Next());
(...skipping 2511 matching lines...) Expand 10 before | Expand all | Expand 10 after
4524 EXPECT_VALID(h_result); 4578 EXPECT_VALID(h_result);
4525 Integer& result = Integer::Handle(); 4579 Integer& result = Integer::Handle();
4526 result ^= Api::UnwrapHandle(h_result); 4580 result ^= Api::UnwrapHandle(h_result);
4527 String& foo = String::Handle(String::New("foo")); 4581 String& foo = String::Handle(String::New("foo"));
4528 Integer& expected = Integer::Handle(); 4582 Integer& expected = Integer::Handle();
4529 expected ^= foo.HashCode(); 4583 expected ^= foo.HashCode();
4530 EXPECT(result.IsIdenticalTo(expected)); 4584 EXPECT(result.IsIdenticalTo(expected));
4531 } 4585 }
4532 4586
4533 } // namespace dart 4587 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698