Chromium Code Reviews| Index: vm/dart_api_impl.cc |
| =================================================================== |
| --- vm/dart_api_impl.cc (revision 9641) |
| +++ vm/dart_api_impl.cc (working copy) |
| @@ -1579,6 +1579,14 @@ |
| intptr_t length) { |
| Isolate* isolate = Isolate::Current(); |
| DARTSCOPE(isolate); |
| + if (codepoints == NULL) { |
| + RETURN_NULL_ERROR(codepoints); |
| + } |
| + if (length < 0 || length > OneByteString::kMaxElements) { |
| + return Api::NewError( |
| + "%s expects argument 'length' to be in the range [0..%ld].", |
| + CURRENT_FUNC, OneByteString::kMaxElements); |
| + } |
| return Api::NewHandle(isolate, String::New(codepoints, length)); |
| } |
| @@ -1587,6 +1595,14 @@ |
| intptr_t length) { |
| Isolate* isolate = Isolate::Current(); |
| DARTSCOPE(isolate); |
| + if (codepoints == NULL) { |
| + RETURN_NULL_ERROR(codepoints); |
| + } |
| + if (length < 0 || length > TwoByteString::kMaxElements) { |
|
cshapiro
2012/07/19 05:49:01
I thought you were going to add a macro or somethi
turnidge
2012/07/31 23:21:45
Done.
|
| + return Api::NewError( |
| + "%s expects argument 'length' to be in the range [0..%ld].", |
| + CURRENT_FUNC, TwoByteString::kMaxElements); |
| + } |
| return Api::NewHandle(isolate, String::New(codepoints, length)); |
| } |
| @@ -1595,6 +1611,14 @@ |
| intptr_t length) { |
| Isolate* isolate = Isolate::Current(); |
| DARTSCOPE(isolate); |
| + if (codepoints == NULL) { |
| + RETURN_NULL_ERROR(codepoints); |
| + } |
| + if (length < 0 || length > FourByteString::kMaxElements) { |
| + return Api::NewError( |
| + "%s expects argument 'length' to be in the range [0..%ld].", |
| + CURRENT_FUNC, FourByteString::kMaxElements); |
| + } |
| return Api::NewHandle(isolate, String::New(codepoints, length)); |
| } |
| @@ -1652,9 +1676,10 @@ |
| if (codepoints == NULL && length != 0) { |
| RETURN_NULL_ERROR(codepoints); |
| } |
| - if (length < 0) { |
| - return Api::NewError("%s expects argument 'length' to be greater than 0.", |
| - CURRENT_FUNC); |
| + if (length < 0 || length > ExternalTwoByteString::kMaxElements) { |
| + return Api::NewError( |
| + "%s expects argument 'length' to be in the range [0..%ld].", |
| + CURRENT_FUNC, ExternalTwoByteString::kMaxElements); |
| } |
| return Api::NewHandle( |
| isolate, String::NewExternal(codepoints, length, peer, callback)); |
| @@ -1670,9 +1695,10 @@ |
| if (codepoints == NULL && length != 0) { |
| RETURN_NULL_ERROR(codepoints); |
| } |
| - if (length < 0) { |
| - return Api::NewError("%s expects argument 'length' to be greater than 0.", |
| - CURRENT_FUNC); |
| + if (length < 0 || length > ExternalFourByteString::kMaxElements) { |
| + return Api::NewError( |
| + "%s expects argument 'length' to be in the range [0..%ld].", |
| + CURRENT_FUNC, ExternalFourByteString::kMaxElements); |
| } |
| return Api::NewHandle( |
| isolate, String::NewExternal(codepoints, length, peer, callback)); |
| @@ -1823,6 +1849,11 @@ |
| DART_EXPORT Dart_Handle Dart_NewList(intptr_t length) { |
| Isolate* isolate = Isolate::Current(); |
| DARTSCOPE(isolate); |
| + if (length < 0 || length > Array::kMaxElements) { |
| + return Api::NewError( |
| + "%s expects argument 'length' to be in the range [0..%ld].", |
| + CURRENT_FUNC, Array::kMaxElements); |
| + } |
| return Api::NewHandle(isolate, Array::New(length)); |
| } |
| @@ -2163,6 +2194,11 @@ |
| DART_EXPORT Dart_Handle Dart_NewByteArray(intptr_t length) { |
| Isolate* isolate = Isolate::Current(); |
| DARTSCOPE(isolate); |
| + if (length < 0 || length > Uint8Array::kMaxElements) { |
| + return Api::NewError( |
| + "%s expects argument 'length' to be in the range [0..%ld] but saw %ld", |
| + CURRENT_FUNC, Uint8Array::kMaxElements, length); |
| + } |
| return Api::NewHandle(isolate, Uint8Array::New(length)); |
| } |
| @@ -2176,9 +2212,10 @@ |
| if (data == NULL && length != 0) { |
| RETURN_NULL_ERROR(data); |
| } |
| - if (length < 0) { |
| - return Api::NewError("%s expects argument 'length' to be greater than 0.", |
| - CURRENT_FUNC); |
| + if (length < 0 || length > ExternalUint8Array::kMaxElements) { |
| + return Api::NewError( |
| + "%s expects argument 'length' to be in the range [0..%ld] but saw %ld", |
| + CURRENT_FUNC, ExternalUint8Array::kMaxElements, length); |
| } |
| return Api::NewHandle( |
| isolate, ExternalUint8Array::New(data, length, peer, callback)); |