fix(libc): format 16-bit wide arguments in asprintf on Linux #3978
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3978"
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 zmeizy on 2026-10-11T20:26:57Z.
What
On Linux, the narrow printf functions send a format that has a guest wide conversion (
%ls,%lc,%S,%C) to the guest formatter, which reads 16-bit characters. Onlyasprintf(AllocatingStrings.cpp) gave every format to the host'svasprintf. The host reads a 32-bitwchar_tper character, so a guest UTF-16 string came out wrong, or the call failed. Windows was not affected.asprintfnow forwards its arguments tovasprintf, asfprintfdoes withvfprintf.vasprintfalready chooses the formatter and copies the result into the application heap. The null-argument checks and the out-of-memory result are the same as before.Tested
Ubuntu 24.04, GCC 13.3, on
main12c22662.guest_formatting: a new check registers an application heap and callsasprintf("%ls:%S:%lc:%d", u"é", u"ab", 0x20ac, 7). It expects 11 and the UTF-8 texté:ab:€:7, then frees the result with the guestfree.mainwithout the change and passes with it.guest_wide_formattingpasses.vasprintf, which makes the sameFormatWindowscall thatasprintfmade before.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt (n/a).mdfiles or images added to the repository (attach them to this PR)🤖 Generated with Claude Code
https://claude.ai/code/session_01Ha6Tsy62AFUyp9a5Mf7vjA
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-11T21:13:50Z.
Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.
main)core/libs/tests/Formatting.cppL1-2