Repository navigation
fix(libc): print the guest errno message for %m in the printf family - #4353
Merged
oneandonlydean merged 1 commit intoOct 12, 2026
Merged
Conversation
FreeBSD's printf formats %m as the message for the errno value at the time of the call. On Linux a format with %m went to glibc, which looks the number up in Linux's table, so guest errno values above 34 got another error's text: with errno 35 (EAGAIN) "[%m]" printed "[Resource deadlock avoided]" instead of "[Resource temporarily unavailable]", and errno 63 (ENAMETOOLONG) printed "Out of streams resources". On Windows, and on Linux when the format also had a wide argument, the guest formatter threw on %m. FreeBSD 11.4, lib/libc/stdio/vfprintf.c: saved_errno = errno; ... case 'm': cp = strerror(saved_errno); size = (prec >= 0) ? strnlen(cp, prec) : strlen(cp); sign = '\0'; break; The guest formatter now saves errno when it starts and formats %m as a string with the guest strerror_r text, so width, precision and the - flag apply as FreeBSD's string path applies them. On Linux a format with %m goes to the guest formatter like one with a wide argument. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
10 tasks done
Contributor
|
Windows test: head AI-assisted (Claude Code). |
|
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.
|
9 tasks done
11 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Fixes #4045.
FreeBSD's printf formats
%mas the message for the errno value at the time of the call. On Linux a format with%mwent to glibc, which looks the number up in Linux's table, so guest errno values above 34 printed another error's text. With errno 35 (EAGAIN),"[%m]"printed[Resource deadlock avoided]instead of[Resource temporarily unavailable], and errno 63 (ENAMETOOLONG) printedOut of streams resources. On Windows, and on Linux when the format also had a wide argument, the guest formatter threw on%m(listed in TechnicalDebt.md).FreeBSD 11.4,
lib/libc/stdio/vfprintf.c:%mas a string holding the gueststrerror_rtext, so width, precision and-apply as they do in FreeBSD's string path. errno is left unchanged.%mgoes to the guest formatter, as a format with a wide argument already does.%mas throwing.asprintfon Linux still calls the host'svasprintfdirectly. #3978 routes it throughvasprintf, which then picks this up.Overlap: #3987 (Windows printf conversions, carrying #3975) keeps
%mthrowing on Windows and lists it among its unsupported cases. This branch implements%mthere instead, so whichever lands first, the other needs a small rebase: the conversion chain inFormatWindowsand that test line.Tested
main5a59d4e after fix(libc): format 16-bit wide arguments in asprintf on Linux #3978 (asprintf, same test file):guest_formattingpasses with this change and fails with thatmain's formatter; all 295guest_*tests pass.Ubuntu 24.04, GCC 13.3 (CI's compiler), Release with CI's configure flags.
guest_formattinggained%mchecks: errno 35 with[%m][%.8m][%-10.5m], errno 63 throughvsnprintf, and errno unchanged afterwards. The test fails with main'sWindowsFormatting.hppandFormatting.cpp("Formatting check failed") and passes with this change.ctest -R '^guest_' -E '^guest_video_out_': 281/281 pass.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)