Strings are compound objects, so allocation failures can occur during allocation.
This gets us closer to passing 061 again, but the ClassLoader changes seem to
have made life a bit more recursive. (That is: this is not a complete fix.)
Change-Id: Ibd7e7a54a6cbfb17020295e034053e136777e891
diff --git a/src/object.cc b/src/object.cc
index 506c2c8..aeaa19b 100644
--- a/src/object.cc
+++ b/src/object.cc
@@ -1226,8 +1226,14 @@
const uint16_t* utf16_data_in,
int32_t hash_code) {
String* string = Alloc(GetJavaLangString(), utf16_length);
+ if (string == NULL) {
+ return NULL;
+ }
// TODO: use 16-bit wide memset variant
CharArray* array = const_cast<CharArray*>(string->GetCharArray());
+ if (array == NULL) {
+ return NULL;
+ }
for (int i = 0; i < utf16_length; i++) {
array->Set(i, utf16_data_in[i]);
}
@@ -1247,6 +1253,9 @@
String* String::AllocFromModifiedUtf8(int32_t utf16_length,
const char* utf8_data_in) {
String* string = Alloc(GetJavaLangString(), utf16_length);
+ if (string == NULL) {
+ return NULL;
+ }
uint16_t* utf16_data_out =
const_cast<uint16_t*>(string->GetCharArray()->GetData());
ConvertModifiedUtf8ToUtf16(utf16_data_out, utf8_data_in);
@@ -1255,11 +1264,18 @@
}
String* String::Alloc(Class* java_lang_String, int32_t utf16_length) {
- return Alloc(java_lang_String, CharArray::Alloc(utf16_length));
+ CharArray* array = CharArray::Alloc(utf16_length);
+ if (array == NULL) {
+ return NULL;
+ }
+ return Alloc(java_lang_String, array);
}
String* String::Alloc(Class* java_lang_String, CharArray* array) {
String* string = down_cast<String*>(java_lang_String->AllocObject());
+ if (string == NULL) {
+ return NULL;
+ }
string->SetArray(array);
string->SetCount(array->GetLength());
return string;