fix(libc): convert scanf integers as FreeBSD does on Windows #4815
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/4815"
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 EagleBearerYS on 2026-10-12T22:43:48Z.
What
On Windows the scanf family (
sscanf,vsscanf,fscanfand their callers) translates the guest's length modifiers and hands the format to the host's scanner. Two integer cases differ from FreeBSD 11.4'svfscanf.%d,%i,%o,%u,%xor%Xwithout a length modifier, or withhorhh, went to the host unchanged. The host converts it with its 32-bitlong, so an out-of-range value was clamped anderrnoset toERANGE. FreeBSD converts every integer withstrtoimaxorstrtoumaxand stores the result truncated to the destination type (vfscanf.cL741-L771).q, FreeBSD's quad length modifier, was not recognized, so%qd,%quand%qxthrewNotImplemented_nid_no_patch("vsscanf format conversion"). FreeBSD treatsqlikell(vfscanf.cL529-L531).Measured with
main's code:"2147483648"%derrno34"3000000000"%ierrno34"4294967296"%uerrno34"100000000"%xerrno34"3000000000"%qdA colour or mask written as
0xFFFFFFFFand read with%iinto aninttherefore came back as0x7FFFFFFF.ScanWindowsArguments_nid_no_patch(WindowsScanning.hpp) now does two things:qas it doeslandll.llinto a temporary. A%nafter it shows whether the conversion took place. The value is then stored truncated to the destination'sint,shortorchar, as FreeBSD's assignment does.A value beyond the 64-bit range still sets
ERANGE, asstrtoimaxdoes there. Linux hands the format to glibc, which already behaves this way. No title is claimed.Tested
Windows 11 (10.0.26300), WinLibs MinGW-w64 GCC 15.2.0 r7 (UCRT), Release,
-DBUILD_TESTING=ON, onmainat43e3a70f8:CheckIntegerScanWidthsinguest_formattingchecks:%d,%i("0xFFFFFFFF"gives -1),%u,%x,%o,%hd("5000000000"gives -3584) and%hhd("300"gives 44), witherrnoleft alone;ERANGEfor"99999999999999999999"with%d(-1);%qdand%qx;%nstill counts after the new conversions, and that a failed conversion leaves its destination unchanged.main'sWindowsScanning.hppthe test fails at its first check ("2147483648"with%dgives 2147483647 anderrno34). With the change it passes, 20 runs in a row.core/libs/prx/libc/CMakeLists.txtandcore/libs/prx/libkernel/CMakeLists.txtthat build on Windows pass.guest_formattingpasses 20 runs in a row; the code change does not apply there, and glibc already gives these results.tools/check_conventions.py --base origin/mainpasses.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-14T02:37:49Z.
Closing: no title is known to reach this. With the queue at 700+ open PRs, please hold off on new PRs that don't name a title needing the change until it's down. If a title stops on this on current main, reopen with the title ID and the log line.
Pull request closed