Skip to content

Commit a0d280e

Browse files
committed
ICU-23120 Fix malloc request larger than PTRDIFF_MAX bytes
* glibc does not allow allocations that exceed PTRDIFF_MAX bytes: https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=9bf8e29ca136094f73f69f725f15c51facc97206 * Without this, we get compile failures on 32-bit platforms: work/icu/source/test/intltest/ustrtest.cpp: In member function ‘void UnicodeStringTest::TestLargeMemory()’: work/icu/source/test/intltest/ustrtest.cpp:2360:37: error: size ‘4294967286’ of array exceeds maximum object size ‘2147483647’ 2360 | char16_t *buf = new char16_t[len]; | ^
1 parent 795d7ac commit a0d280e

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

icu4c/source/test/intltest/ustrtest.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2356,7 +2356,7 @@ void UnicodeStringTest::TestLargeMemory() {
23562356
#if U_PLATFORM_IS_LINUX_BASED || U_PLATFORM_IS_DARWIN_BASED
23572357
if(quick) { return; }
23582358
IcuTestErrorCode status(*this, "TestLargeMemory");
2359-
constexpr uint32_t len = 2147483643;
2359+
constexpr uint32_t len = (PTRDIFF_MAX - 10) / sizeof(char16_t);
23602360
char16_t *buf = new char16_t[len];
23612361
if (buf == nullptr) { return; }
23622362
uprv_memset(buf, 0x4e, len * 2);

0 commit comments

Comments
 (0)