summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--runtime/mirror/string.cc6
-rw-r--r--test/061-out-of-memory/expected.txt1
-rw-r--r--test/061-out-of-memory/src/Main.java19
3 files changed, 25 insertions, 1 deletions
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> 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;
}
diff --git a/test/061-out-of-memory/expected.txt b/test/061-out-of-memory/expected.txt
index ca876299f5..c31980cad7 100644
--- a/test/061-out-of-memory/expected.txt
+++ b/test/061-out-of-memory/expected.txt
@@ -4,4 +4,5 @@ testOomeLarge beginning
testOomeLarge succeeded
testOomeSmall beginning
testOomeSmall succeeded
+Got expected toCharArray OOM
tests succeeded
diff --git a/test/061-out-of-memory/src/Main.java b/test/061-out-of-memory/src/Main.java
index c812c81114..52373d3c5f 100644
--- a/test/061-out-of-memory/src/Main.java
+++ b/test/061-out-of-memory/src/Main.java
@@ -26,6 +26,7 @@ public class Main {
testHugeArray();
testOomeLarge();
testOomeSmall();
+ testOomeToCharArray();
System.out.println("tests succeeded");
}
@@ -106,4 +107,22 @@ public class Main {
}
System.out.println("testOomeSmall succeeded");
}
+
+ private static void testOomeToCharArray() {
+ Object[] o = new Object[1000000];
+ String test = "test";
+ int i = 0;
+ try {
+ for (; i < o.length; ++i) o[i] = new char[1000000];
+ } catch (OutOfMemoryError oom) {}
+ try {
+ for (; i < o.length; ++i) o[i] = new Object();
+ } catch (OutOfMemoryError oom) {}
+ try {
+ test.toCharArray();
+ } catch (OutOfMemoryError oom) {
+ o = null;
+ System.out.println("Got expected toCharArray OOM");
+ }
+ }
}