Skip to content

fix(libc): format 16-bit wide arguments in asprintf on Linux - #3978

Merged
oneandonlydean merged 1 commit into
boykopovar:mainfrom
zmeizy:claude/asprintf-guest-wide
Oct 12, 2026
Merged

oneandonlydean merged 1 commit into
boykopovar:mainfrom
zmeizy:claude/asprintf-guest-wide

Conversation

@zmeizy

@zmeizy zmeizy commented Oct 11, 2026

Copy link
Copy Markdown
Contributor

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. Only asprintf (AllocatingStrings.cpp) gave every format to the host's vasprintf. The host reads a 32-bit wchar_t per character, so a guest UTF-16 string came out wrong, or the call failed. Windows was not affected.

asprintf now forwards its arguments to vasprintf, as fprintf does with vfprintf. vasprintf already 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 main 12c22662.

  • guest_formatting: a new check registers an application heap and calls asprintf("%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 guest free.
  • The check fails on main without the change and passes with it.
  • guest_wide_formatting passes.
  • Windows was not built. Its path calls vasprintf, which makes the same FormatWindows call that asprintf made before.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt (n/a)
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source (n/a)
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes

🤖 Generated with Claude Code

https://claude.ai/code/session_01Ha6Tsy62AFUyp9a5Mf7vjA

@github-actions github-actions Bot added the libc label Oct 11, 2026
@github-actions

github-actions Bot commented Oct 11, 2026 •

Copy link
Copy Markdown

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.

Pull request Conflicting files (lines on main) Same exports Same new files
#3982 core/libs/tests/Formatting.cpp L1-2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants