Repository navigation
fix(libc): preserve errno in Windows floating string scans - #18405
oneandonlydean merged 12 commits into
Conversation
|
Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
|
|
Windows check of head Setup: Windows 11 Enterprise 22621, WinLibs GCC 15.2 UCRT, Release. The hosted Windows check does not run these tests on pull requests.
AI-assisted: yes. |
PrivacyOnion
left a comment
There was a problem hiding this comment.
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against 76e96d8555:
- Conventions:
tools/check_conventions.pypassed;git diff --checkclean. - Build:
guest_formatting_testsbuilt cleanly. - CTest (
guest_formatting):1/1 Test #1150: guest_formatting ................. Passed 0.54 sec 100% tests passed, 0 tests failed out of 1 - Negative control: the tests still pass with the change reverted, so they do not cover it
- Code reading:
- Verified HasNarrowScan in core/libs/prx/libc/src/Formatting.cpp correctly parses width, ignored length modifiers, and positional arguments, accurately selecting narrow floating conversions (aAeEfFgG) for Windows string scans while leaving wide scan and stream dispatch paths unaffected.
- Verified DecimalOutOfRange in core/libs/prx/libc/src/Formatting.cpp and its integration into ScanSource (lines 328-332): correctly restores savedError across hexadecimal floats, representable values, and long-double subnormals, updating errno to ERANGE (34) only on genuine decimal long-double overflow or underflow to zero.
- Verified that earlier legitimate errors (e.g. ERANGE from an earlier integer overflow such as LLONG_MAX) are preserved when subsequent floating fields do not trigger an out-of-range condition.
- Verified CheckHexPrefix in core/libs/prx/libc/src/Formatting.cpp safely respects width limits, avoids buffer overrun on truncated or signed inputs (e.g., 0x, -0x, 0x.), and properly differentiates between InputFailure (EOF) and MatchingFailure (0) for floating and integer conversions.
- Verified StoreDefaultNaN and destination padding in core/libs/prx/libc/src/Formatting.cpp: correctly preserves 80-bit extended precision conventions for long double, leaving destination guard bytes beyond 10 bytes untouched.
- Verified AGENTS.md compliance: no comments introduced into source/test files, known gaps and updated source links documented in docs/dev/debt/libc.md, and comprehensive unit tests added to core/libs/tests/Formatting.cpp that properly restore *__error_nid_postfix() without contaminating thread state.
- Note: the AI-assisted checkbox can stay.
Requesting changes for the points above.
|
@PrivacyOnion At
|
MarcZX10
left a comment
There was a problem hiding this comment.
Reviewed — no blocking findings
Nothing blocks this; the points below are optional.
What I ran
- Head reviewed:
76e96d85555cd4afb6378cb349ea2c1bbd13a6c8, the PR's stated head. Base:main. No merged-preview check was run. - Read-only review with the repository reader. Nothing was built or executed on this host.
- The description's claim that stream and non-Windows dispatch are unchanged matches the diff: only the narrow helper and the selector in
ScansInProcesschanged.
Reader commands (all at head)
python3 repo_read.py search HasNarrowCharacterScan
python3 repo_read.py search ScansInProcess
python3 repo_read.py cat core/libs/prx/libc/src/Formatting.cpp 60 150
python3 repo_read.py cat core/libs/prx/libc/src/Formatting.cpp 660 690
python3 repo_read.py cat core/libs/prx/libc/src/Formatting.cpp 1015 1040
python3 repo_read.py cat core/libs/tests/Formatting.cpp 1 40
python3 repo_read.py search __error_nid_postfix core/libs/tests/Formatting.cpp
Results
| Check | Result | Note |
|---|---|---|
| Windows build and 12 CTests | not run | Author-reported on this head; not re-run here |
| Narrow helper guards | passed | Read only; its non-Windows uses are guarded |
| Selector and test expectations | passed | Read only; not executed |
| Linux and macOS | not applicable | Change is in the Windows dispatch |
Findings
Blocking
None.
Non-blocking
- The floating-errno paragraph in
docs/dev/debt/libc.md:316says "Windows narrow string scans" but does not mention narrow stream scans (fscanfand its family). The visible part of the Windows stream dispatch incore/libs/prx/libc/src/Formatting.cpp(lines 687–690) sends only wide formats to the shared scanner, so narrow stream float scans fall outside this rule. The paragraph should say so. Confirm the rest of that branch before adding the clause.
Sources
- Helper, guards and selector:
AnyPS5/core/libs/prx/libc/src/Formatting.cpp
Lines 96 to 137 in 76e96d8
- Stream dispatch (visible part):
AnyPS5/core/libs/prx/libc/src/Formatting.cpp
Lines 687 to 690 in 76e96d8
- Windows test block:
AnyPS5/core/libs/tests/Formatting.cpp
Lines 564 to 677 in 76e96d8
Not verified
- The Windows build and the 12 CTests: author-reported, not run here.
- The errno comparisons from #9973 and #12530 and the 200,000-case run: author-reported, not checked.
- The shared float path that the new letters reach was not read beyond the selector.
- The rest of the Windows stream branch in
Formatting.cpp, past line 690, was not read. docs/dev/debt/libc.mdwas read only through its changed hunks; the other lines were not read.- The #18380 prefix changes (the prefix test block and
docs/dev/debt/libc.md:299) are in this diff but were read only as diff text. - Console behaviour, Linux and macOS, and floating-point exception flags: not tested. The PR says the same.
To get this to a good state
Nothing is required.
Optional: add the narrow-stream clause to the paragraph at docs/dev/debt/libc.md:316 (finding 1).
|
@JJenkx The current-head overlap check for this Windows-only fix now intersects #18765 in Could #18765 and #18768 follow this PR? When rebasing #18765, please retain the Windows The peer combinations have been compared statically, not runtime-tested together. AI-assisted: yes. |
PrivacyOnion
left a comment
There was a problem hiding this comment.
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against 0d1efd624b:
- Conventions:
tools/check_conventions.pypassed;git diff --checkclean. - Build:
guest_formatting_testsbuilt cleanly. - CTest (
guest_formatting):1/1 Test #1198: guest_formatting ................. Passed 0.13 sec 100% tests passed, 0 tests failed out of 1 - Negative control: the tests still pass with the change reverted, so they do not cover it
- Code reading:
- core/libs/prx/libc/src/Formatting.cpp:98-120: Verified HasNarrowScan for null-pointer safety, correct format string traversal, scanset skipping, and exclusion of wide %lc conversions via (*format != 'c' || !(format - length == 1 && *length == 'l')).
- core/libs/prx/libc/src/Formatting.cpp:123-140: Verified preprocessor guarding for ScansInProcess and HasNarrowCharacterScan across _WIN32 and non-Windows targets, ensuring Windows dispatches cxXipaAeEfFgG while Linux maintains narrow character scan routing.
- core/libs/prx/libc/src/Formatting.cpp:231-236: Verified DecimalOutOfRange logic using std::strtold, confirming that hexadecimal float fields bypass range checks and decimal ERANGE is triggered strictly when values overflow to infinity or underflow to zero in long double.
- core/libs/prx/libc/src/Formatting.cpp:370-388: Verified errno handling in ScanSource for contiguous strings, ensuring representable float/double values preserve the incoming errno and multi-field scans preserve errors set by preceding fields.
- core/libs/tests/Formatting.cpp:580-692: Verified Windows test coverage exercising both sscanf_nid_postfix and ScanList across float/double/long-double overflow, underflow, subnormals, normal numbers, prefix edge cases, and destination guard byte checks.
- docs/dev/debt/libc.md:309-326: Verified that the technical debt documentation was updated accurately to reflect the Windows narrow string scan dispatch to shared floating errno rules while noting stream scans and Linux host routing remain unchanged.
- AGENTS.md: Verified strict compliance with all repository conventions, including the complete absence of code comments, Conventional Commits formatting, proper debt tracking, and absence of extraneous files.
- Note: the AI-assisted checkbox can stay.
Requesting changes for the points above.
MarcZX10
left a comment
There was a problem hiding this comment.
Reviewed — looks good
The Windows floating string scan change is sound at head 0d1efd624bba5c4555ef6e087012ac628ace0182; inspected code and supplied integration results support merging, with console behavior and some platforms not verified.
What I ran
No commands were run. I read the prepared description, commits, manifest and diff, then used the pinned reader to inspect all three changed files and relevant scan dispatch and conversion code. The author reports Windows 11 integration builds, 12 passing CTests, convention checks, and whitespace checks; these were not run by me.
Results
| Check | Result | Note |
|---|---|---|
| Source review | passed | All changed files inspected |
| Integration checks | not run | Results supplied by author |
| Console and other platforms | not run | Not verified here |
Findings
Blocking
None.
Non-blocking
None.
Not verified
I did not run tests or commands. Physical console/title behavior, Linux/macOS behavior, floating-point exception flags, the complete product build and full test suite were not verified. The review bundle lists no excluded changed files; all three changed files were read: core/libs/prx/libc/src/Formatting.cpp, core/libs/tests/Formatting.cpp, and docs/dev/debt/libc.md.
To get this to a good state
Nothing is required.
PrivacyOnion
left a comment
There was a problem hiding this comment.
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against 25b88c0fe0:
- Conventions:
tools/check_conventions.pypassed;git diff --checkclean. - Build:
guest_formatting_testsbuilt cleanly. - CTest (
guest_formatting):1/1 Test #1243: guest_formatting ................. Passed 0.08 sec 100% tests passed, 0 tests failed out of 1 - Negative control: the tests still pass with the change reverted, so they do not cover it
- Code reading:
- core/libs/prx/libc/src/Formatting.cpp:HasNarrowScan: Verified conversion parsing safely handles positional specifiers ($), suppression (*), field widths, length prefixes (hljztL), and scansets ([...]), and guards against trailing '%' or null termination reads.
- core/libs/prx/libc/src/Formatting.cpp:ScansInProcess: Verified that Windows narrow string scans route 'cxXipaAeEfFgG' through ScanGuest, while non-Windows paths retain HasNarrowCharacterScan('c') and stream functions (fscanf_nid_postfix/vfscanf_nid_postfix) retain their host-backed routing.
- core/libs/prx/libc/src/Formatting.cpp:ScanSource: Verified that DecimalOutOfRange sets errno = ERANGE (34) only on decimal overflow to infinity or underflow to zero as long double, preserving saved incoming errno (such as 7) on representable values, subnormals, hexadecimal fields (%a), and earlier conversion failures.
- core/libs/tests/Formatting.cpp:RunChecks: Verified the test matrix validates both sscanf_nid_postfix and ScanList (vsscanf_nid_postfix) across float, double, and 10-byte long double storage, checks destination guard bytes, validates %n consumed counts, and restores *__error_nid_postfix() to previousError.
- AGENTS.md compliance: Verified zero comments added to code (only preprocessor directives), no prohibited files added, and technical debt properly updated via the fragment at docs/dev/debt/changes/fix-windows-sscanf-float-range.md.
- Note: the AI-assisted checkbox can stay.
Requesting changes for the points above.
PrivacyOnion
left a comment
There was a problem hiding this comment.
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against 25b88c0fe0:
- Conventions:
tools/check_conventions.pypassed;git diff --checkclean. - Build:
guest_formatting_testsbuilt cleanly. - CTest (
guest_formatting):1/1 Test #1252: guest_formatting ................. Passed 0.23 sec 100% tests passed, 0 tests failed out of 1 - Negative control: with
core/libs/prx/libc/src/Formatting.cppreverted tomainand the new tests kept, the suite fails:Restoring the change makes it pass again.1/1 Test #1252: guest_formatting ................. Passed 1.65 sec 100% tests passed, 0 tests failed out of 1 - Code reading:
- Verified
HasNarrowScanincore/libs/prx/libc/src/Formatting.cpp:92-116safely checksformat == nullptrand*format != '\0'before callingstd::strchr(conversions, *format)while preserving%lcwide-scan exclusion. - Verified
ScansInProcessincore/libs/prx/libc/src/Formatting.cpp:124-131routes Windows narrow string scans withcxXipaAeEfFgGconversions through the in-process scanner while leaving non-Windows dispatch (HasNarrowCharacterScanforc) unchanged. - Verified
DecimalOutOfRangeandStoreDefaultNaNincore/libs/prx/libc/src/Formatting.cpphandle decimallong doubleoverflow/underflowERANGEpreservation and 10-bytelong doublestorage without buffer overruns. - Verified Windows test additions in
core/libs/tests/Formatting.cpp:611-725cover hex prefix rejection (%x,%X,%i,%p), floating-point rangeerrnopreservation acrossfloat,double, and 10-bytelong doubletargets, and restore*__error_nid_postfix(). - Verified technical debt fragment
docs/dev/debt/changes/fix-windows-sscanf-float-range.mdcomplies with AGENTS.md rules andtools/check_conventions.pypassed.
- Verified
- Note: the AI-assisted checkbox can stay.
Looks Good To Me
MarcZX10
left a comment
There was a problem hiding this comment.
Reviewed — no blocking findings
The Windows string-scan dispatch and its tests look consistent with the stated errno behavior; the open ordering dependency means a formal approval is not justified yet.
What I ran
Reviewed head 25b88c0fe050c80dab346b38a1a2ae84772c4fb6 using repo_read.py to inspect the prepared diff and source. I did not run tests or builds; the Windows test results below were reported by the author.
Results
| Check | Result | Note |
|---|---|---|
| Changed-file review | passed | All 3 changed files read |
| Windows build and CTests | not run | Author reports 12 passed |
| Debt and convention checks | not run | Author reports passed |
| Negative control | not run | No control run in this review |
Findings
Blocking
None.
Non-blocking
- The description identifies #12622 as an ordering dependency and says it remains open and conflicts with the current
Formatting.cpp. Resolve the integration order before merging; this review does not assess that unmerged implementation. - The author reports a Windows build and 12 passing CTests, but those checks were not run as part of this review.
Sources
Not verified
No build or test commands were run. The reported Windows environment and results, native console behavior, other operating systems, and the combined behavior with the open ordering dependency were not independently verified. All changed files listed in the manifest were read; none were excluded.
To get this to a good state
Nothing is required by this review. Optional: resolve the #12622 integration order and run the Windows build and CTests on the resulting head.
MarcZX10
left a comment
There was a problem hiding this comment.
Reviewed — looks good
Nothing blocks this change; the inspected Windows string-scan routing, range handling, regression tests, and debt fragments support the stated behavior.
What I ran
Reviewed head aa69388b1c5998516696fdccacc66e7ab53e183a using the prepared diff and repo_read.py targeted reads. No build or tests were run; validation results in the description are author-reported.
Files read: core/libs/prx/libc/src/Formatting.cpp, core/libs/tests/Formatting.cpp, docs/dev/debt/changes/fix-windows-sscanf-float-range.md, and docs/dev/debt/changes/fix-windows-sscanf-hex-prefix.md. All four files marked reviewed in the manifest were read. No changed files were excluded by the manifest.
Results
| Check | Result | Note |
|---|---|---|
| Diff and targeted source review | passed | Changed behavior and relevant call path inspected |
| Build and tests | not run | The description reports successful Windows validation |
| Console and non-Windows execution | not run | No execution performed in this review |
Findings
Blocking
None.
Non-blocking
None.
Not verified
The reported Windows build, CTests, debt validation, conventions check, and whitespace check were not rerun. Native console behavior, non-Windows runtime behavior, and the combined behavior with dependent PRs were not independently verified.
To get this to a good state
Nothing is required.
What
Ordinary Windows
sscanf/vsscanfcan setERANGEwhen a value only overflows or underflows its float/double destination. For example,%fof1e39changes errno from 7 to 34, while the bundled library preserves it.Extend #18380's Windows string dispatch to
aAeEfFgG, using the existing shared scanner and per-field long-double range check. Actual decimal long-double overflow/underflow setsERANGE; representable, subnormal and hexadecimal fields preserve the incoming error, including legitimate errors from earlier fields. Return/count, destination padding and the 10-byte long-double store remain covered. Stream and non-Windows routing retain main's behavior.The 2026-11-15 integration merges main
d9e6b8cf8eae21ec85210543bc53879f54dfff17into the previous public head0d1efd624bba5c4555ef6e087012ac628ace0182, producing25b88c0fe050c80dab346b38a1a2ae84772c4fb6. The scanner conflict preserves both main's removal of the positional-wide exception and this PR's Windows selector. Main's high-byte literal rejection, range-check optimization and new tests remain intact. The debt conflict is resolved by moving the two existing edits intodocs/dev/debt/changes/fix-windows-sscanf-float-range.md, following the current fragment workflow; the generated debt file matches main.Depends on #18380 (
fac97d17feb91be5e004a73c67f64865ea5a7411, included ancestor, still OPEN) and #12622 (376f7a5bf7bcb186b099f1e895eb35600333344f, still OPEN, not an ancestor). #12622 remains an ordering dependency; its current merge preview now conflicts inFormatting.cpp, so the old documentation-only preview is historical and no longer describes its current head. I did not include or execute that unmerged implementation.Expected errno results come from the reported calls in #9973 and the existing rule from #12530. Those are contributor reference measurements, not new console or title measurements.
Tested
Current local validation, 2026-11-15: head
25b88c0fe050c80dab346b38a1a2ae84772c4fb6against integrated maind9e6b8cf8eae21ec85210543bc53879f54dfff17.Windows 11 Pro 10.0.26300, Ryzen 9 7900X (24 logical CPUs), 31.7 GiB RAM, RTX 4070 Ti SUPER present; no GPU tests. WinLibs MinGW-w64 GCC 15.2.0 r7 UCRT POSIX SEH, Python 3.14.7, full Release runtime configuration (
BUILD_TESTING=ON,ANYPS5_RELINKER_ONLY=OFF). The existing isolated source/build was reconfigured and rebuilt with at most three compiler jobs. Eight runtime targets and NID-patchedlibc.prxbuilt successfully. All 12 registered CTests passed, 0 failed, 0 skipped, with no reported internal skips. This includes the Windows float/prefix matrices through both entry points, plus main's new positional-wide, high-byte literal and floating-range tests.The staging helper explicitly refreshed
tests/libc.prxand all three compiler runtime DLLs. Seven source/staged hash pairs match. Rebuilt unpatched/stagedlibc.prxSHA-256:af6aeff7bd9cbd9766b7604d9e08d96d24d7159e604ee31f6c363fcb530bc03e. Separately NID-patchedlibc.prxSHA-256:68ebc9fec9e8b9fa4d293e253f8a73b97a14f530decdae8cec9545ba46ce19db. Generated runtime provenance records the tested head25b88c0fe050c80dab346b38a1a2ae84772c4fb6.Debt-fragment validation, conventions against refreshed main and whitespace checks pass. Main later advanced to
ef6a94fb54e6c3644d0563fbac66eddbf8b29145; its nine changed files (camera, font, shader debt and patch-advisor tooling) do not intersect the 284 source/header inputs recorded by Ninja for these targets. No build scripts or dependency pins changed in that advance, and the merge preview is clean. Tested main remains the exact revision stated above.Original regression evidence, not rerun during this merge: base
4c75011c4cdfa17853c3a4abda7ddd414ba121fc(then-main plus #18380) with the new tests failedsscanf("1e39", "%f%n")with errno 34 instead of 7. Fixed head76e96d85555cd4afb6378cb349ea2c1bbd13a6c8passed. The current integration independently passes the retained matrix.%f%nscans1e39, initially 7The full default product build, complete suite, Linux/macOS, native console/title execution and floating-point exception flags were not tested in this integration. Automatic PR checks do not establish a full hosted Build.
The isolated
pr_overlap.pyrun fetched 1,542 open PR heads against main55b1b0ded04bcfa01c691809d6dcc8c0688c3951, then probed 1,540 peer heads. Exit 2 is not a clean overlap result: #18765 overlaps the selector, and four stale-base comparisons remain incomplete (#9087, #9340, #11332, #12622). Their shared-file diffs were compared manually. #9087 changes secure constraints/capacities, #9340 changes Unicode wide fields, #11332 changes printf bounds, and #12622 adds secure formatting/constraint behavior. The first three retain the exact heads already inspected during the earlier integration; #12622 was refreshed to its current head. None duplicates the ordinary Windows floating-string selector fix. Peer branches were not executed. The later main advance does not touch this PR's files, so these relevant comparisons remain applicable.The existing integration-order request remains unanswered. #18765 at
428ef900bd480a86e2457c20aa90630cb3780c89still conflicts in the selector and must retain the Windows conversion letters when integrating its Linux routing change; its ordering agreement is unresolved. #18768 at1053ec0cf26542f1a4067bc5c49fc967ffdb5ec3now merges cleanly after the debt-fragment migration, and its combined debt-fold preview passes. These peer combinations were not runtime-tested together. No duplicate question was posted.MarcZX10's APPROVED review
5900338470is on the previous head. PrivacyOnion's latest CHANGES_REQUESTED review5879963433also remains unresolved; the earlier Windows/Linux coverage explanation is already in the discussion. This integration does not mark either the review or the ordering blocker resolved, and is not a ready/approved claim.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)