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

Unified Diff: vm/dart_api_impl.cc

Issue 11275107: Fix length computation in Dart_StringToUTF8. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/runtime/
Patch Set: Created 8 years, 1 month 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
« bin/builtin_natives.cc ('K') | « include/dart_api.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: vm/dart_api_impl.cc
===================================================================
--- vm/dart_api_impl.cc (revision 14418)
+++ vm/dart_api_impl.cc (working copy)
@@ -1643,6 +1643,9 @@
const char** cstr) {
Isolate* isolate = Isolate::Current();
DARTSCOPE(isolate);
+ if (cstr == NULL) {
+ RETURN_NULL_ERROR(cstr);
+ }
const String& str_obj = Api::UnwrapStringHandle(isolate, object);
if (str_obj.IsNull()) {
RETURN_TYPE_ERROR(isolate, object, String);
@@ -1661,20 +1664,27 @@
DART_EXPORT Dart_Handle Dart_StringToUTF8(Dart_Handle str,
- uint8_t* utf8_array,
+ uint8_t** utf8_array,
intptr_t* length) {
Isolate* isolate = Isolate::Current();
DARTSCOPE(isolate);
+ if (utf8_array == NULL) {
+ RETURN_NULL_ERROR(utf8_array);
+ }
+ if (length == NULL) {
+ RETURN_NULL_ERROR(length);
+ }
const String& str_obj = Api::UnwrapStringHandle(isolate, str);
if (str_obj.IsNull()) {
RETURN_TYPE_ERROR(isolate, str, String);
}
- intptr_t str_len = str_obj.Length();
- if (str_len > *length) {
- return Api::NewError("Input array is not large enough to hold the result");
+ intptr_t str_len = Utf8::Length(str_obj);
+ *utf8_array = Api::TopScope(isolate)->zone()->Alloc<uint8_t>(str_len);
+ if (*utf8_array == NULL) {
+ return Api::NewError("Unable to allocate memory");
}
- str_obj.ToUTF8(utf8_array, str_len);
- *length= str_len;
+ str_obj.ToUTF8(*utf8_array, str_len);
+ *length = str_len;
return Api::Success(isolate);
}
« bin/builtin_natives.cc ('K') | « include/dart_api.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698