fix(libc): format guest wide strings in swprintf as 16-bit units #1511
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1511"
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 cubersu on 2026-10-08T10:41:35Z.
What
swprintfpassed guest strings to the host'svswprintf. The guest'swchar_tis 16 bits, so on Linux (32-bit hostwchar_t) it misread the format and miswrote the output.swprintfmoves to FormattingWide.cpp and forwards to the guestvswprintf(FormatWide), on Linux and Windows alike. The Windows-onlyWindowsWideFormatting.hpphad no other user and is removed.swprintfis dropped from the Wide-character conversions entry. The entry still nameswcsrtombsonly because that is its state onmain; #1507 removes it. Both PRs edit that one line toward the same end state (no host passthrough left), so whichever merges second rebases it to thewcsto*note alone.The
wcsrtombspart was removed after the conflict report, since #1507 (opened earlier) implements it; this branch's formerwcsrtombstests pass against #1507.Tested
Linux (Ubuntu 24.04, GCC 13.3), rebased on current
main. Theswprintfchecks inguest_wide_formatting(non-ASCII and surrogate-pair output, padding, truncation, exact fit, terminator that does not fit, invalid conversion, empty format, null buffer, zero size) fail onmainand pass with this change.libstarget builds;guest_wide_formatting,guest_wide_strings,guest_strings,guest_wcsrtombs_spass. Windows: built and tested by @popcoder565 in the comments above (on the earlier revision, whoseswprintfcode is unchanged).tools/check_conventions.py --base origin/mainpasses.Checklist
main; no other open PR implements the same functions (#1512 is the same change; its extra tests are merged here)NotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository (attach them to this PR)🤖 Generated with Claude Code
https://claude.ai/code/session_01ULF8vCbJFyzxVsW3SfiWC5
Imported from boykopovar/AnyPS5. Originally posted by klosixgaming-arch on 2026-10-08T10:54:45Z.
Review: COMMENTED
Comprehensive fix for both swprintf and wcsrtombs to properly handle 16-bit guest characters. The new test coverage is excellent, especially the surrogate pair handling in swprintf tests.
Note: This PR overlaps significantly with #1512 - both address the same wide-character formatting issues. They should probably be coordinated so only one merges (or they're combined). The TechnicalDebt.md line will need rebasing whichever goes second.
Imported from boykopovar/AnyPS5. Originally posted by popcoder565 on 2026-10-08T11:09:23Z.
Tested on Windows 10 (19045), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release, Intel Core i7-12700H, merged onto
main084aeeb6.guest_wide_formatting,guest_wcsrtombsandguest_wcsrtombs_s: 5 of 5 runs pass.Formatting.cpp,FormattingWide.cpp,Multibyte.cpp,Strings.cppand the deletedWindowsWideFormatting.hppback tomainand kept the new tests.guest_wide_formattingandguest_wcsrtombsthen abort in 2 of 2 runs, so the new checks catch it on Windows too.agc_driver_dcc_keys_first_writeandagc_driver_srgb8_color_targetfailed. Both are the NVIDIA import flakes in #1434.Tested with AI assistance (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by klosixgaming-arch on 2026-10-08T11:25:33Z.
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 Dextroid17 on 2026-10-08T13:19:17Z.
The overlap bot already pairs this with #1512 (same export
swprintf_nid_postfix, same four files), and the two were opened 17 seconds apart (10:41:35 vs 10:41:52). Rather than let a maintainer arbitrate which to keep, here is what each side has, so you two can collapse them without losing anything:#1511 (this one)
guest_wide_formatting,guest_wcsrtombsandguest_wcsrtombs_s5/5; mutation check (implementation reverted, tests kept) aborts, so the tests bite; full ctest 436/438, the two failures being the NVIDIA import flakes in #1434.wcsrtombshalf, but the diff touches nowcsrtombscode — if that half is meant to be here it is missing; if it is #1507, aDepends on:line would say so.CONFLICTING.#1512
%5ls,%-3c,%lcwith a non-ASCII value) and an exact-fit case (swprintf(buf, 5, "%ls", "abcd") == 4), where yours covers the non-ASCII and truncation paths (%d-%ls, the surrogate pair, the terminator-not-fitting case).So the useful move is probably: keep one PR open, pull the other's test cases into it (that is the only real difference), and have the second author withdraw or convert their PR into a comment. That keeps both sets of coverage and leaves the maintainer one thing to review instead of two.
Written with AI assistance.
Imported from boykopovar/AnyPS5. Originally posted by Dextroid17 on 2026-10-08T13:37:57Z.
Following the body rewrite, three things that need to line up before this is reviewable — all of them cheap to fix.
1. The description describes a half that is not in the diff. The new body says
wcsrtombsmoves toMultibyte.cppand converts throughwcrtombfollowing C11 7.29.6.4.1, and theTestedsection says the newguest_wcsrtombstest fails onmainand passes with this change. But this PR's files are:No
Multibyte.cpp, noStrings.cpp, andcore/libs/tests/GuestWcsrtombs.cppis #1507's new file, not part of this PR. So either the push did not carry that half, or the body was written against a local branch that also had #1507 in it. Either way, the honest options are: push the missing half, or trim the body to what the diff does and addDepends on: #1507for the other half. (The same shape — numbers taken from a combined branch — is why #1294 was closed; worth avoiding.)2. Your debt entry and #1507's edit the same line in opposite directions. This PR now leaves it saying "
wcsrtombsstill passes guest strings to the host'swchar_tfunction"; #1507 rewrites the same entry to saywcsrtombsgoes throughwcrtomband is no longer a host passthrough. Whichever merges second overwrites the other. Since #1507 is the one that implements it, the entry probably wants your version only if the wcsrtombs half is not in this PR — which is point 1.3. On the #1512 overlap from my previous comment: the useful split is the test cases, not the code. Theirs adds padding (
%5ls,%-3c,%lcwith a non-ASCII value) and an exact-fit case; yours adds the non-ASCII and truncation paths. Porting the other set's cases and letting one PR withdraw keeps all the coverage and leaves the maintainer one thing to review.Written with AI assistance.
Imported from boykopovar/AnyPS5. Originally posted by cubersu on 2026-10-08T13:56:01Z.
Thanks @Dextroid17, all three are addressed:
swprintfonly. Thewcsrtombshalf was dropped in favour of #1507, which was opened first; the old body was written before that split.mainthe entry names both functions. This PR removesswprintf, #1507 removeswcsrtombs, so the two edits head to the same end state (only thewcsto*note remains). Whichever merges second needs a one-line rebase, and I'll do it on this side if #1507 goes first.Imported from boykopovar/AnyPS5. Originally posted by Dextroid17 on 2026-10-08T14:16:53Z.
All three check out on the current head — thanks for the fast turnaround.
1. Body now matches the diff. The file list is
swprintf-only:No
Multibyte.cpp/Strings.cpp, and theswprintfforwarder now sits besidevswprintf_nid_postfixinFormattingWide.cpp, so the body describes what the diff does.2. The debt line read is right. This PR drops
swprintffrom the entry and leaveswcsrtombs(itsmainstate); #1507 dropswcsrtombs. Both edits head to the same end state, so whichever merges second rebases the one line — your offer to do it on this side if #1507 goes first is exactly what is needed.3. #1512's checks are in.
CheckSwprintfcarries the padded case (%5ls|%-3c|%lc→wide|z |€), the exact-fit case (swprintf(buf, 5, "%ls", "abcd") == 4), and the invalid-conversion case (%q) alongside the non-ASCII/truncation/surrogate paths you already had, and the commit credits @Noface07 as co-author. Verified from the diff.Two things for the record, neither a blocker:
no checks reported on the branch), so a green CI is not there yet; a maintainer needs to approve the workflow run, which is @boykopovar's repo-write.Written with AI assistance.
Imported from boykopovar/AnyPS5. Originally posted by Noface07 on 2026-10-08T15:21:59Z.
Thanks @cubersu for the co-author credit. Amazing how our PR's were only 17 secs apart.
I'm closing #1512 in favour of this one.
Thanks everybody @klosixgaming-arch @Dextroid17 @popcoder565 .
Imported from boykopovar/AnyPS5. Originally posted by Dextroid17 on 2026-10-08T21:59:49Z.
Confirmed from my side — all three hold, and I checked the two halves of the split against both diffs.
wcsrtombsand dropsswprintf, while #1507's hunk keepsswprintfand dropswcsrtombs(re-pointing the entry atMultibyte.cpp). The two PRs rewrite the same line in opposite directions, so the one-line rebase for whichever merges second is a real requirement, not a precaution.swprintfonly, with thewcsrtombshalf left to #1507, which was opened first.No open point from my earlier review.
Imported from boykopovar/AnyPS5. Originally posted by ArjenS-LA on 2026-10-09T02:44:30Z.
Sorry for my slow response. If #1511 merges first, I’ll rebase #1507 and reconcile the shared debt entry to reflect both fixes while preserving the remaining limitations. Thanks for the coordination 👍
Imported from boykopovar/AnyPS5. Originally posted by Dextroid17 on 2026-10-09T11:18:27Z.
Agreed, and nothing is waiting on you: whichever of #1507 and #1511 lands first, the other rebases and reconciles the shared debt entry so the remaining limitations are described once rather than twice. Merge order is the maintainers' call rather than ours, so there is nothing for us to decide — the plan you describe is the one I would have proposed.
Thanks for picking it up rather than leaving both entries to drift.
Written with AI assistance.
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-10T03:18:43Z.
This conflicts with main after today's merges; could you rebase? It passed testing and is otherwise ready.
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-10T06:19:28Z.
Rebased onto current
main: the only conflict was the "Wide-character conversions" line in TechnicalDebt now that #1507 is merged. The entry now keeps thewcsto*andwcsrtombsnotes and no longer mentionsswprintf. No code changes.Checked on Linux after the rebase:
guest_wide_formatting,guest_wide_strings,guest_wcsrtombs,guest_wcsrtombs_spass. Windows run by @popcoder565 above (sameswprintfcode), and @oneandonlydean's testing; merging once CI is green.