From 952d608062eec2d7f47f9b45dba935ad8b4d23e5 Mon Sep 17 00:00:00 2001 From: Mathieu Chartier Date: Thu, 12 Nov 2015 16:53:41 -0800 Subject: Add missing null check to String::ToCharArray Added test. Bug: 25641543 Change-Id: Ic9a21ce8bc530dbedf14334ad47f5faa90ae4ddc --- runtime/mirror/string.cc | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'runtime/mirror/string.cc') diff --git a/runtime/mirror/string.cc b/runtime/mirror/string.cc index 45610dccc8..be869d4e6a 100644 --- a/runtime/mirror/string.cc +++ b/runtime/mirror/string.cc @@ -254,7 +254,11 @@ CharArray* String::ToCharArray(Thread* self) { StackHandleScope<1> hs(self); Handle string(hs.NewHandle(this)); CharArray* result = CharArray::Alloc(self, GetLength()); - memcpy(result->GetData(), string->GetValue(), string->GetLength() * sizeof(uint16_t)); + if (result != nullptr) { + memcpy(result->GetData(), string->GetValue(), string->GetLength() * sizeof(uint16_t)); + } else { + self->AssertPendingOOMException(); + } return result; } -- cgit v1.2.3-59-g8ed1b