fix(libc): return 0, not EOF, from scanf when input ends after suppressed conversions #2766
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2766"
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 husseinkad on 2026-10-10T13:27:43Z.
What
On Windows
sscanf,vsscanfandfscanfreturnedEOFinstead of 0 when the input ran out after only suppressed conversions had completed:sscanf("12", "%*d%d", &v)returned -1. C17 7.21.6.2p16 returnsEOFonly if an input failure occurs before the first conversion has completed, and FreeBSD'svfscanf.c(releng/11.4, lines 799 to 806) incrementsnconversionsfor suppressed conversions too and ends withreturn (nconversions != 0 ? nassigned : EOF);%nand%*nare not conversions. The host scanf does not count the suppressed ones.WindowsScanning.hppnow appends a private%nto each suppressed conversion (slots are heap allocated, one per%, so a format with hundreds of them is fine) and, when the host returnsEOFbut a slot was written, returns 0. Everything else is passed through unchanged. The Linux path hands the format to glibc, which returnsEOFin this case; that and a related Windows host quirk (the host stops after thexof a0xwith no hex digit and after theeof an exponent with no digits, where C17 and FreeBSD stop before it) are recorded in TechnicalDebt and left alone, as fixing them needs per-directive scanning.Tested
Windows 11 (10.0.26200), WinLibs GCC 15.2.0 r7, Release:
guest_formatting(sscanf) andguest_standard_streams(fscanf) gain%*d%don exhausted input (0),%*don empty or blank input (stillEOF), and the other forms; both are_WIN32-only because Linux keeps glibc's behaviour. They fail without the change (exit0xc0000409) and pass with it.ctest -R "guest_formatting|guest_standard_stream|guest_scan_count|guest_strings"passes (4 of 4).main's and this branch'slibc.prxagainst a reference written from C17 and FreeBSD'svfscanf: about 273 million format/input pairs (all formats of up to four directives over%*d %d %*c %c %*s %s %*[a-c] %[a-c] %*x %n %*5d %*ld %*lf %*i %*[^,] %%against inputs of up to five characters, a million random formats with length modifiers and scansets, 300 to 5,000 suppressed conversions in one format,vsscanfandfscanfthrough real streams): formats without%*are byte-identical tomainin return value, assigned values and consumed length (19 million cases); with%*the only change frommainisEOFbecoming 0, 43.5 million times, and in all but 18 thousand of those it matches the reference. The remaining divergences from the reference are the host quirks above, whichmainhas as well.tools/check_conventions.py --base origin/mainpasses;tools/pr_overlap.py --branchreports no overlap.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 repositoryImported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-10T13:27:52Z.
Thank you for your interest in the project! We are sorry, but we cannot accept more PRs while we work through the existing backlog. This PR has been automatically closed and labeled "intake paused". This is not a judgment of the quality of your changes.
Pull request closed