fix(libc): format swprintf output as 16-bit guest units #1512
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1512"
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 Noface07 on 2026-10-08T10:41:52Z.
What
swprintfpassed guest strings to the host'svswprintf. The guest'swchar_tis 16 bits; on Linux the host's is 32 bits, so the output and the%lsarguments were misread and miswritten. On Windows it used a separate formatter (FormatWideWindows) that did not decode UTF-8%sarguments asvswprintfdoes.swprintfnow formats throughvswprintf_nid_postfix(16-bitFormatWide) on both hosts, so the two functions behave the same:%sarguments are decoded from UTF-8, as invswprintfandsnwprintf_s.vswprintfdoes.vswprintfdoes; the Windows formatter calledNotImplemented_nid_no_patchfor it.WindowsWideFormatting.hpphas no other user and is removed. The TechnicalDebt entry keepswcsrtombs, which #1507 implements.Tested
x86_64-ucrt-posix-seh; not the 15.2.0 release from BUILD.md), Ninja Release,BUILD_TESTING=ON: full build andlibstarget,ctest434/434 passed.FormattingWide.cppcompiled withGuestWideFormatting.cppdirectly; the test passes. The same test againstmain'sFormatting.cppaborts at the firstswprintfcheck.tools/check_conventions.pypassed. No title tested.tools/pr_overlap.pyreports #1507 on the same TechnicalDebt line (L232) only: it changeswcsrtombs, this PR changesswprintf, no shared exports. Whichever merges second needs that line rebased.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-08T10:53:47Z.
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/GuestWideFormatting.cppL10, L113, L116docs/dev/TechnicalDebt.mdL241swprintf_nid_postfixImported from boykopovar/AnyPS5. Originally posted by klosixgaming-arch on 2026-10-08T10:54:29Z.
Review: COMMENTED
Good fix that unifies swprintf behavior across Linux and Windows by using the 16-bit FormatWide implementation on both platforms. The test coverage is comprehensive, covering UTF-8 decoding, padding, truncation, exact fit, zero size, and invalid conversions.
The removal of WindowsWideFormatting.hpp simplifies the codebase nicely. One minor note: this PR overlaps with #1511 on the TechnicalDebt.md line (L232) - whichever merges second will need to rebase that line.
Imported from boykopovar/AnyPS5. Originally posted by klosixgaming-arch on 2026-10-08T11:25:11Z.
Review: APPROVED
Good fix for swprintf formatting consistency across platforms. This simplifies the codebase by removing the separate Windows-specific implementation and routing through the 16-bit guest formatter on both hosts.
Strengths:
Technical notes:
This will improve compatibility with titles that use swprintf. Ready to merge.
Imported from boykopovar/AnyPS5. Originally posted by cubersu on 2026-10-08T13:57:22Z.
Hi @Noface07, #1511 is the same
swprintfchange and was opened just before this one. Following the suggestion in #1511, I've merged your padded, exact-fit and invalid-conversion tests into it (you're credited as co-author in the commit), so it now covers both test sets. If that works for you, this one could be closed as a duplicate. Thanks for the extra cases!Imported from boykopovar/AnyPS5. Originally posted by Dextroid17 on 2026-10-08T14:00:43Z.
Independent run on Linux, since your
Testedsection notes the WSL compile-without-CMake route — this is the same change through the real build, and then through CI's own test target.Merged onto current
main(63c57d22): no conflicts. That is worth stating plainly, because in this pair you are the one that still merges cleanly.The tests bite. Implementation reverted to
main(Formatting.cpp,FormattingWide.cppback,WindowsWideFormatting.hpprestored) with your tests and registration kept:So your claim — the same test aborts against
main'sFormatting.cpp— reproduces here with the CMake target and the fulllibc.prx, not only with the two translation units compiled together.On the two halves of this change: #1511 is the same
swprintffix, opened 17 seconds after this one, currentlyCONFLICTING, and it does carry an independent Windows run (@popcoder565: 5/5 on the three wide tests, with a mutation check, 436/438 on the full suite). Its extra value over this PR is the test cases: it covers the non-ASCII path and a surrogate pair, where you cover padding (%5ls,%-3c,%lc) and an exact fit. That is the only real difference between the two diffs. Bringing those cases over here — or having the maintainer take this one and #1511 withdraw — keeps every case and leaves one thing to review instead of two.One line of the checklist is worth revisiting given that: "no other open PR implements the same functions" is no longer true, and the honest version is what your
Testedsection already does — say which PR is the other half.For the record, your
TechnicalDebt.mdhandling reads correctly to me: keepingwcsrtombsin the entry because #1507 implements it. #1511's current edit of the same line says the opposite (wcsrtombsstill passes guest strings), so that line will collide whichever of those two merges second.Written with AI assistance.
Imported from boykopovar/AnyPS5. Originally posted by Noface07 on 2026-10-08T15:22:46Z.
Closing as a duplicate of #1511.
Thanks @Dextroid17 for the independent Linux run and @klosixgaming-arch for the review.
Pull request closed