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

Unified Diff: runtime/lib/string.cc

Issue 209003009: Fix memory-issue String::fromCharCodes, where a GC could invalidate an address. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 9 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 | « no previous file | runtime/vm/object.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/lib/string.cc
diff --git a/runtime/lib/string.cc b/runtime/lib/string.cc
index 111b70c28035a39e50e6e3f6fa22c6cf475550e9..19222eb8c1d9db2bc6cc71d0c13fd35806462aa8 100644
--- a/runtime/lib/string.cc
+++ b/runtime/lib/string.cc
@@ -157,29 +157,25 @@ DEFINE_NATIVE_ENTRY(OneByteString_allocate, 1) {
DEFINE_NATIVE_ENTRY(OneByteString_allocateFromOneByteList, 1) {
Instance& list = Instance::CheckedHandle(arguments->NativeArgAt(0));
- uint8_t* data = NULL;
- intptr_t length = 0;
if (list.IsTypedData()) {
const TypedData& array = TypedData::Cast(list);
- length = array.LengthInBytes();
- data = reinterpret_cast<uint8_t*>(array.DataAddr(0));
+ intptr_t length = array.LengthInBytes();
+ return OneByteString::New(array, 0, length);
} else if (list.IsExternalTypedData()) {
const ExternalTypedData& array = ExternalTypedData::Cast(list);
- length = array.LengthInBytes();
- data = reinterpret_cast<uint8_t*>(array.DataAddr(0));
+ intptr_t length = array.LengthInBytes();
+ return OneByteString::New(array, 0, length);
} else if (RawObject::IsTypedDataViewClassId(list.GetClassId())) {
const Instance& view = Instance::Cast(list);
- length = Smi::Value(TypedDataView::Length(view));
+ intptr_t length = Smi::Value(TypedDataView::Length(view));
const Instance& data_obj = Instance::Handle(TypedDataView::Data(view));
intptr_t data_offset = Smi::Value(TypedDataView::OffsetInBytes(view));
if (data_obj.IsTypedData()) {
const TypedData& array = TypedData::Cast(data_obj);
- data = reinterpret_cast<uint8_t*>(array.DataAddr(data_offset));
+ return OneByteString::New(array, data_offset, length);
} else if (data_obj.IsExternalTypedData()) {
const ExternalTypedData& array = ExternalTypedData::Cast(data_obj);
- data = reinterpret_cast<uint8_t*>(array.DataAddr(data_offset));
- } else {
- UNREACHABLE();
+ return OneByteString::New(array, data_offset, length);
}
} else if (list.IsArray()) {
const Array& array = Array::Cast(list);
@@ -199,10 +195,9 @@ DEFINE_NATIVE_ENTRY(OneByteString_allocateFromOneByteList, 1) {
OneByteString::SetCharAt(string, i, value);
}
return string.raw();
- } else {
- UNREACHABLE();
}
- return OneByteString::New(data, length, Heap::kNew);
+ UNREACHABLE();
+ return Object::null();
}
« no previous file with comments | « no previous file | runtime/vm/object.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698