fix(libc): read %i without the C23 binary prefix in the scanf family on Linux #4358
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/4358"
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 milescoviello on 2026-10-12T07:31:51Z.
What
On Linux,
sscanf,vsscanf,fscanfandsscanf_shand their conversions to glibc. Since glibc 2.38, code built as GNU C++ calls the C23 entry points (__isoc23_vsscanf,__isoc23_vfscanf,__isoc23_sscanf), whose%ireads a0b/0Bbinary prefix. On main,sscanf("0b101 x", "%i%n%7s", &value, &end, rest)storesvalue5 andend5 and leavesxfor the%s;" -0B11"gives -3. TechnicalDebt records this; #1459 fixed the same prefix in thestrtolfamily and leftscanfthere.FreeBSD's
%iknows only the0and0xprefixes. FreeBSD 11.4lib/libc/stdio/vfscanf.c,parseint:so
"0b101"stores 0, consumes the0and leavesb101, as C17 does and as thestrtolfamily here already does.With glibc, the scanf family now calls
__isoc99_vsscanfand__isoc99_vfscanf: the entry points GNU C++ used before glibc 2.38 (exported since 2.7), which read%iwithout the binary prefix. Other hosts keepstd::vsscanfandstd::vfscanf. The TechnicalDebt entry is removed. No title is claimed.Tested
Ubuntu 24.04 (glibc 2.39), GCC 13.3 (CI's compiler), Release with CI's configure flags.
guest_formattingcheckssscanf("0b101", "%i%n%7s")(0, end 1, restb101),vsscanf(" -0B11", "%i")(0),vsscanf_s("0b1", "%i")(0) and thatsscanf("0x1f", "%i")still stores 31.guest_standard_streamschecksfscanfon a stream holding0b101(0, next characterb).guest_formatting:Formatting check failed;guest_standard_streamsaborts). Before the fix the same calls store 5, -3 and 1 and consume the whole prefix.guest_scan_count, and all 294guest_*tests pass (-E '^guest_video_out_').nm -D libc.prxshows__isoc99_vsscanf@GLIBC_2.7and__isoc99_vfscanf@GLIBC_2.7imported.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 xXPBSXx on 2026-10-12T13:20:28Z.
Windows test: head
89bc9d108merged onto currentmain0ef9dc928(clean merge, no conflicts). Windows 10, MinGW GCC (WinLibs), Ninja Release,-j4: full build 0 errors; ctest with the filterguest_formatting|guest_standard_stream|guest_wide_formatting: guest_wide_formatting passed, guest_standard_streams passed, guest_formatting passed (3 test(s), 0 failed);python tools/check_conventions.py --base upstream/mainpassed. I did not run the new tests againstmainwithout the change. The title names Linux, so this Windows run only shows that the change builds and the tests still pass on Windows.AI-assisted (Claude Code).