fix(libc): size collate<char>::do_transform strings as the console does #4733
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/4733"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by fdfawef324 on 2026-10-12T20:01:05Z.
What
collate<char>::do_transformgave the resultstd::stringa capacity of exactly its length and threw for results of 4095 characters or more.The console's
libc.prxgrows the string from its inline capacity of 15 tolength | 15, so a 26-character result has capacity 31 and a 32-byte allocation. Oncecapacity + 1reaches 0x1000 bytes it takes the over-aligned large allocation that the guest's inlined deallocation expects:operator new(bytes + 0x27), the data aligned to 32 bytes and the raw pointer stored just before it. This is the scheme of Dinkumware'sbasic_stringgrowth (_Newsize | _ALLOC_MASK) and of its_Allocatein<xmemory0>(_BIG_ALLOCATION_THRESHOLD4096,_BIG_ALLOCATION_ALIGNMENT32,_NON_USER_SIZE=sizeof(void*) + 31in release builds). As in Dinkumware, the large path throwsbad_allocifbytes + 0x27would wrap.do_transformnow uses that capacity and allocation, and the throw for long results is removed. Thecollate<char>entry indocs/dev/debt/libc.mdnow says that the capacity and the large-allocation layout come from the console'slibc.prxcode and have not been checked on hardware.This replaces fork branch
fix/libc-collate-char-capacity, which was never opened as a PR. That branch was stacked onfeat/libc-collate-wcharto share an allocation helper. This version is based directly onmainand changes only the narrow facet, because #4409 implementscollate<wchar_t>::_Getcatseparately. Both PRs touchLocaleSupport.cppbut change different functions. Once this one is merged, the wide transform in #4409 could useAllocateStringStoragefor results of 2047 code units or more, which #4409 currently rejects with a throw.Tested
Windows Server 2025, RTX 3060, GCC 15.2 (WinLibs UCRT), Release
-O3, based onmain1acfa7f78.guest_collatechecks the capacity and allocation size of a 26-character result, the last small result (4079 characters, a 4080-byte block) and the first large one (4080 characters, capacity 4095, a 4096 + 0x27-byte block with the data aligned to 32 and the raw pointer before it).main'sLocaleSupport.cpp,guest_collateaborts (exit 0xc0000409) at the allocation-size check of the 26-character result: the allocation is 27 bytes, not 32. With the fix it passes (0.24 s).core/libs/prx/libc/CMakeLists.txtin this Windows build (55 executables) were run withctest -j 4: 81 pass;log_macrosfails ("a short line differs") the same way on unchangedmain.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-13T01:09:29Z.
Windows test: head
0ca047e60merged onto currentmain1c5e62878(clean merge, no conflicts). Windows 10, MinGW GCC (WinLibs), Ninja Release,-j2: full build 0 errors; ctest with the filterguest_collate: guest_collate passed (1 test(s), 0 failed);python tools/check_conventions.py --base upstream/mainpassed. I did not run the new tests againstmainwithout the change.AI-assisted (Claude Code).