summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
author Elliott Hughes <enh@google.com> 2011-10-12 23:49:11 -0700
committer Elliott Hughes <enh@google.com> 2011-10-12 23:49:11 -0700
commitb51036c4647fe4440994d4e06cbb021bc38f7a78 (patch)
tree811c51c8ea8631d2f041b985ead00cc685586a3c /src
parent47a0d5a6f221066c3daf7f67f2122ed9c9cd217c (diff)
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
Diffstat (limited to 'src')
-rw-r--r--src/object.cc18
1 files changed, 17 insertions, 1 deletions
diff --git a/src/object.cc b/src/object.cc
index 506c2c8e3b..aeaa19b24d 100644
--- a/src/object.cc
+++ b/src/object.cc
@@ -1226,8 +1226,14 @@ String* String::AllocFromUtf16(int32_t utf16_length,
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(const char* utf) {
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::AllocFromModifiedUtf8(int32_t utf16_length,
}
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;