fix(libc): print NaN without a sign in the guest printf formatter #4548
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/4548"
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 coltken95 on 2026-10-12T15:23:08Z.
What
The guest printf formatter (
LibcDetail::FormatWindows, used for every format on Windows and for formats with 16-bit wide arguments on Linux) handed NaN to the host'ssnprintf, which prints-nanfor a negative NaN and+nanornanwith the+and space flags. FreeBSD 11 vfprintf.c clears the sign of every NaN (sign = '\0') and printsnan(NANfor the upper-case conversions), keeping the width and the-flag and dropping zero padding. The formatter now prints NaN that way fora,e,f,g, their upper-case forms andlong double; infinities are unchanged.Formats without wide arguments still go to glibc on Linux, so the TechnicalDebt note that already lists
%p((nil)) there now lists NaN too.Tested
Linux (Ubuntu 24.04, GCC 13.3). New
guest_formattingcases throughvsnprintfwith a wide argument: negative and positive NaN with%f,%+f,% F,%5.1e,%-6g,%06a,%LG, and-inffor comparison. They fail before this change (-nan,+nan) and pass after. All 44 libcguest_*tests registered in this configuration pass. Windows not built locally (no MinGW toolchain available). No title tested.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-13T10:35:51Z.
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.cppL5docs/dev/debt/libc.mdL53Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-13T14:17:12Z.
Checked against FreeBSD
vfprintf.c(NaN clears the sign, printsnan/NAN, drops zero padding), build + libc/libs ctest on Linux, and the newguest_formattingcases fail without the change. Merging after the full Build.