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

Side by Side Diff: runtime/lib/byte_array.cc

Issue 10869063: Add attributions so printf like functions can have their arguments checked. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: rebased Created 8 years, 3 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
« no previous file with comments | « runtime/lib/array.cc ('k') | runtime/platform/assert.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "vm/bootstrap_natives.h" 5 #include "vm/bootstrap_natives.h"
6 6
7 #include "vm/bigint_operations.h" 7 #include "vm/bigint_operations.h"
8 #include "vm/exceptions.h" 8 #include "vm/exceptions.h"
9 #include "vm/native_entry.h" 9 #include "vm/native_entry.h"
10 #include "vm/object.h" 10 #include "vm/object.h"
11 11
12 namespace dart { 12 namespace dart {
13 13
14 // ByteArray 14 // ByteArray
15 15
16 // Checks to see if (index * num_bytes) is in the range 16 // Checks to see if (index * num_bytes) is in the range
17 // [0..array.ByteLength()). without the risk of integer overflow. If 17 // [0..array.ByteLength()). without the risk of integer overflow. If
18 // the index is out of range, then an IndexOutOfRangeException is thrown. 18 // the index is out of range, then an IndexOutOfRangeException is thrown.
19 static void RangeCheck(const ByteArray& array, 19 static void RangeCheck(const ByteArray& array,
20 intptr_t index, 20 intptr_t index,
21 intptr_t num_bytes) { 21 intptr_t num_bytes) {
22 if (!Utils::RangeCheck(index, num_bytes, array.ByteLength())) { 22 if (!Utils::RangeCheck(index, num_bytes, array.ByteLength())) {
23 const String& error = String::Handle(String::NewFormatted( 23 const String& error = String::Handle(String::NewFormatted(
24 "index (%ld) must be in the range [0..%ld)", 24 "index (%"Pd") must be in the range [0..%"Pd")",
25 index, (array.ByteLength() / num_bytes))); 25 index, (array.ByteLength() / num_bytes)));
26 GrowableArray<const Object*> args; 26 GrowableArray<const Object*> args;
27 args.Add(&error); 27 args.Add(&error);
28 Exceptions::ThrowByType(Exceptions::kIndexOutOfRange, args); 28 Exceptions::ThrowByType(Exceptions::kIndexOutOfRange, args);
29 } 29 }
30 } 30 }
31 31
32 32
33 // Checks to see if a length is in the range [0..max]. If the length 33 // Checks to see if a length is in the range [0..max]. If the length
34 // is out of range, then an IllegalArgumentException is thrown. 34 // is out of range, then an IllegalArgumentException is thrown.
35 static void LengthCheck(intptr_t len, intptr_t max) { 35 static void LengthCheck(intptr_t len, intptr_t max) {
36 if (len < 0 || len > max) { 36 if (len < 0 || len > max) {
37 const String& error = String::Handle(String::NewFormatted( 37 const String& error = String::Handle(String::NewFormatted(
38 "length (%ld) must be in the range [0..%ld]", len, max)); 38 "length (%"Pd") must be in the range [0..%"Pd"]", len, max));
39 GrowableArray<const Object*> args; 39 GrowableArray<const Object*> args;
40 args.Add(&error); 40 args.Add(&error);
41 Exceptions::ThrowByType(Exceptions::kIllegalArgument, args); 41 Exceptions::ThrowByType(Exceptions::kIllegalArgument, args);
42 } 42 }
43 } 43 }
44 44
45 45
46 #define GETTER_ARGUMENTS(ArrayT, ValueT) \ 46 #define GETTER_ARGUMENTS(ArrayT, ValueT) \
47 GET_NATIVE_ARGUMENT(ArrayT, array, arguments->At(0)); \ 47 GET_NATIVE_ARGUMENT(ArrayT, array, arguments->At(0)); \
48 GET_NATIVE_ARGUMENT(Smi, index, arguments->At(1)); 48 GET_NATIVE_ARGUMENT(Smi, index, arguments->At(1));
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 ByteArray& dst = ByteArray::CheckedHandle(arguments->At(0)); 256 ByteArray& dst = ByteArray::CheckedHandle(arguments->At(0));
257 GET_NATIVE_ARGUMENT(Smi, dst_start, arguments->At(1)); 257 GET_NATIVE_ARGUMENT(Smi, dst_start, arguments->At(1));
258 GET_NATIVE_ARGUMENT(Smi, length, arguments->At(2)); 258 GET_NATIVE_ARGUMENT(Smi, length, arguments->At(2));
259 GET_NATIVE_ARGUMENT(ByteArray, src, arguments->At(3)); 259 GET_NATIVE_ARGUMENT(ByteArray, src, arguments->At(3));
260 GET_NATIVE_ARGUMENT(Smi, src_start, arguments->At(4)); 260 GET_NATIVE_ARGUMENT(Smi, src_start, arguments->At(4));
261 intptr_t length_value = length.Value(); 261 intptr_t length_value = length.Value();
262 intptr_t src_start_value = src_start.Value(); 262 intptr_t src_start_value = src_start.Value();
263 intptr_t dst_start_value = dst_start.Value(); 263 intptr_t dst_start_value = dst_start.Value();
264 if (length_value < 0) { 264 if (length_value < 0) {
265 const String& error = String::Handle(String::NewFormatted( 265 const String& error = String::Handle(String::NewFormatted(
266 "length (%ld) must be non-negative", length_value)); 266 "length (%"Pd") must be non-negative", length_value));
267 GrowableArray<const Object*> args; 267 GrowableArray<const Object*> args;
268 args.Add(&error); 268 args.Add(&error);
269 Exceptions::ThrowByType(Exceptions::kIllegalArgument, args); 269 Exceptions::ThrowByType(Exceptions::kIllegalArgument, args);
270 } 270 }
271 RangeCheck(src, src_start_value, length_value); 271 RangeCheck(src, src_start_value, length_value);
272 RangeCheck(dst, dst_start_value, length_value); 272 RangeCheck(dst, dst_start_value, length_value);
273 ByteArray::Copy(dst, dst_start_value, src, src_start_value, length_value); 273 ByteArray::Copy(dst, dst_start_value, src, src_start_value, length_value);
274 return Object::null(); 274 return Object::null();
275 } 275 }
276 276
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after
588 DEFINE_NATIVE_ENTRY(ExternalFloat64Array_getIndexed, 2) { 588 DEFINE_NATIVE_ENTRY(ExternalFloat64Array_getIndexed, 2) {
589 GETTER(ExternalFloat64Array, Double, double); 589 GETTER(ExternalFloat64Array, Double, double);
590 } 590 }
591 591
592 592
593 DEFINE_NATIVE_ENTRY(ExternalFloat64Array_setIndexed, 3) { 593 DEFINE_NATIVE_ENTRY(ExternalFloat64Array_setIndexed, 3) {
594 SETTER(ExternalFloat64Array, Double, value, double); 594 SETTER(ExternalFloat64Array, Double, value, double);
595 } 595 }
596 596
597 } // namespace dart 597 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/lib/array.cc ('k') | runtime/platform/assert.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698