Repository navigation
fix(libc): copy count units of a strxfrm or wcsxfrm result that does not fit, as titles' libc.prx does - #11983
Conversation
…not fit, as titles' libc.prx does When the transformed string does not fit, strxfrm and wcsxfrm wrote count - 1 characters and a terminator. The libc.prx bundled with titles copies the first count characters and writes no terminator, as a plain copy of count units would, and copies the terminator only when the whole result fits. Both functions now do the same; the return value, the length of the source, is unchanged. The tests that expected the terminated prefix expect the measured units instead. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
MarcZX10
left a comment
There was a problem hiding this comment.
Reviewed exact head 7c7cc70f2e443d2f20e6afe1209a96b3933f716a.
The implementation and added assertions match the reported title behavior: when the source length is below count, it copies the terminating unit; otherwise it writes exactly count bytes/UTF-16 units and leaves the following destination unit untouched. A zero count avoids writing, and the return remains the source length. The tests cover fit, truncation, count one, zero count/null destination, and UTF-16 surrogate data.
Local verification: Release build of guest_string_tests and guest_wide_string_tests succeeded; guest_wide_strings passed natively; guest_strings passed under QEMU Haswell because the host Xeon lacks AVX2 and the other required guest CPU features; conventions and git diff --check passed; the current-main merge preview is clean. Hosted Windows, Ubuntu register-context, Ubuntu/Windows relinker, ASan relinker, conventions, eligibility, intake, labels, and report checks passed. Linux product was skipped; macOS relinker/register-context/write-watch checks are still queued. I did not run on a PS5 console. The native title comparison described in the PR is author-provided evidence.
|
Linux run at this PR's exact head Arch Linux, kernel 7.2.9, Ryzen 9 7950X, g++ (GCC) 16.2.1 20260810, glibc 2.44, x86-64. Release, Passed in each of 3 runs, exit code 0 each time, with no failed, skipped or not-run tests:
These are the focused tests only; no title or console was used. AI-assisted: yes (Claude Code). |
What
strxfrmandwcsxfrmwrotecount - 1characters and a terminator when the transformed string did not fit. Thelibc.prxthat titles ship does something different: it copies the firstcountcharacters and writes no terminator. When the result fits, it copies the whole string with its terminator. Both functions now do the same. The return value, the source's length, is unchanged.libc.prxmainstrxfrm(buf, "abcdef", 1)a\0strxfrm(buf, "abcdef", 4)abcdabc\0strxfrm(buf, "abcdef", 6)abcdefabcde\0strxfrm(buf, "abcdef", 7)abcdef\0abcdef\0wcsxfrm(buf, u"much too long", 4)muchmuc\0All return 6 or 13 on both sides. C leaves the array's contents indeterminate when the result does not fit, so this changes only what a title can observe in that case.
Tested
Windows 11 Enterprise 10.0.22621, Ryzen 9 5950X, WinLibs GCC 15.2.0 UCRT r7, Ninja, Release,
BUILD_TESTING=ON, onmaine2a5118839.libc.prxof PPSA07923, PPSA13934 and PPSA34008 natively. Each title got 100,000 calls each tostrxfrmandwcsxfrm: random strings of 0 to 19 non-null bytes or UTF-16 units, sizes 0 to 25, and a null destination with size 0. The rule above predicts the return value and all 32 bytes or units of the pre-filled destination in every call, on all three titles.guest_strings: the truncatedstrxfrmchecks expect the measured characters:abcdfor size 4,abcdefghfor size 8, andafor size 1, with the bytes after them untouched.guest_wide_strings: thewcsxfrmtruncation checks expectmuchfor size 4,wfor size 1,widefor size 4, and four units of the surrogate case.guest_stringsandguest_wide_stringspass in each of 3 runs on the exact head7c7cc70f2e.main'sStrings.cppand these tests, both abort (exit 0xc0000409).python tools/check_conventions.py --base origin/mainandgit diff --checkpass._Strxfrmand doesn't change these two functions.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)AI-assisted (Claude Code).
🤖 Generated with Claude Code