diff --git a/src/kits/support/String.cpp b/src/kits/support/String.cpp index 2089d62960..9bdfcbb280 100644 --- a/src/kits/support/String.cpp +++ b/src/kits/support/String.cpp @@ -2360,14 +2360,9 @@ BString::_Resize(int32 length) if (length < 0) length = 0; - char* newData = (char*)realloc(data, length + kPrivateDataOffset + 1); - if (newData == NULL) { - free(data); - data = NULL; + data = (char*)realloc(data, length + kPrivateDataOffset + 1); + if (data == NULL) return NULL; - } else { - data = newData; - } data += kPrivateDataOffset; diff --git a/src/tests/kits/support/bstring/StringAppendTest.cpp b/src/tests/kits/support/bstring/StringAppendTest.cpp index 130137553b..0cb65e727f 100644 --- a/src/tests/kits/support/bstring/StringAppendTest.cpp +++ b/src/tests/kits/support/bstring/StringAppendTest.cpp @@ -116,7 +116,14 @@ StringAppendTest::PerformTest(void) CPPUNIT_ASSERT(strcmp(str1->String(), "BaseCCCCC") == 0); delete str1; - + // TODO: The following test cases only work with hoard2, which will not + // allow allocations via malloc() larger than the largest size-class + // (see threadHeap::malloc(size_t). Other malloc implementations like + // rpmalloc will allow arbitrarily large allocations via create_area(). + // + // This test should be made more robust by breaking the dependency on + // the allocator to simulate failures in another way. This may require + // a tricky build configuration to avoid breaking the ABI of BString. #ifndef TEST_R5 const int32 OUT_OF_MEM_VAL = 2 * 1000 * 1000 * 1000; // Append(char, int32) with excessive length: diff --git a/src/tests/kits/support/bstring/StringAssignTest.cpp b/src/tests/kits/support/bstring/StringAssignTest.cpp index edb26e2f98..414c76492c 100644 --- a/src/tests/kits/support/bstring/StringAssignTest.cpp +++ b/src/tests/kits/support/bstring/StringAssignTest.cpp @@ -99,6 +99,14 @@ StringAssignTest::PerformTest(void) delete str; #ifndef TEST_R5 + // TODO: The following test cases only work with hoard2, which will not + // allow allocations via malloc() larger than the largest size-class + // (see threadHeap::malloc(size_t). Other malloc implementations like + // rpmalloc will allow arbitrarily large allocations via create_area(). + // + // This test should be made more robust by breaking the dependency on + // the allocator to simulate failures in another way. This may require + // a tricky build configuration to avoid breaking the ABI of BString. const int32 OUT_OF_MEM_VAL = 2 * 1000 * 1000 * 1000; // SetTo(char, int32) with excessive length: NextSubTest();