fix(libc): stop strto* at the x of a bare 0x prefix on Windows #2676

Closed
husseinkad wants to merge 1 commit from upstream-pr/2676 into main
husseinkad commented 2026-10-10 10:44:31 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by husseinkad on 2026-10-10T10:44:31Z.


What

On Windows the host strtoll/strtoull leave endptr at the start of the string for a 0x (or 0X) that is not followed by a hex digit, in bases 0 and 16: strtol("0x", &e, 0), strtoul("0x", &e, 16), strtol(" -0x!", &e, 16) all report that nothing was converted. C17 7.22.1.4p4 makes the subject sequence "0", so the value is 0 and endptr must point at the x; FreeBSD's libc does the same. The guest already guards the analogous 0b case (StopAtBinaryPrefix_nid_no_patch).

The guard now also stops at a 0x/0X with no hex digit after it (bases 0 and 16), and is renamed StopAtRadixPrefix_nid_no_patch because it is no longer binary-only (_nid_no_patch helpers are not exports). Everything routed through it is covered: strtol, strtoul, strtoll, strtoull, strtoimax, strtoumax, _Stoul, _Stoull and the wcsto* variants. Behaviour for every other input is unchanged.

Tested

Windows 11 (10.0.26200), WinLibs GCC 15.2.0 r7, Release:

  • guest_math, guest_wide_strings, guest_wide_formatting, guest_strings, guest_scan_count: all pass. The new rows (signed, unsigned, imax and _Stoul variants in GuestMath.cpp; wide variants in GuestWideStrings.cpp) make guest_math and guest_wide_strings fail without the change.
  • Differential check outside the repo: the changed Strings.cpp and the strtoimax/strtoumax/_Stoul wrappers compiled against an independent implementation of C17 7.22.1.4, over every string of length 0 to 6 from a 15-character alphabet, bases {0, 2, 8, 10, 16, 36}, all 12 exports (value, endptr, errno): 0 divergences from the reference and 0 regressions against main; main diverges on about 1.26 million of those cases and the branch on none.
  • tools/check_conventions.py --base origin/main passes; tools/pr_overlap.py --branch reports no overlap.
  • Linux not run (glibc already stops at the x).

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt
  • No notes, investigation .md files or images added to the repository
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4810609201 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2676). Originally posted by [husseinkad](https://github.com/husseinkad) on 2026-10-10T10:44:31Z. --- ### What On Windows the host `strtoll`/`strtoull` leave `endptr` at the start of the string for a `0x` (or `0X`) that is not followed by a hex digit, in bases 0 and 16: `strtol("0x", &e, 0)`, `strtoul("0x", &e, 16)`, `strtol(" -0x!", &e, 16)` all report that nothing was converted. C17 7.22.1.4p4 makes the subject sequence `"0"`, so the value is 0 and `endptr` must point at the `x`; FreeBSD's libc does the same. The guest already guards the analogous `0b` case (`StopAtBinaryPrefix_nid_no_patch`). The guard now also stops at a `0x`/`0X` with no hex digit after it (bases 0 and 16), and is renamed `StopAtRadixPrefix_nid_no_patch` because it is no longer binary-only (`_nid_no_patch` helpers are not exports). Everything routed through it is covered: `strtol`, `strtoul`, `strtoll`, `strtoull`, `strtoimax`, `strtoumax`, `_Stoul`, `_Stoull` and the `wcsto*` variants. Behaviour for every other input is unchanged. ### Tested Windows 11 (10.0.26200), WinLibs GCC 15.2.0 r7, Release: - `guest_math`, `guest_wide_strings`, `guest_wide_formatting`, `guest_strings`, `guest_scan_count`: all pass. The new rows (signed, unsigned, imax and `_Stoul` variants in `GuestMath.cpp`; wide variants in `GuestWideStrings.cpp`) make `guest_math` and `guest_wide_strings` fail without the change. - Differential check outside the repo: the changed `Strings.cpp` and the `strtoimax`/`strtoumax`/`_Stoul` wrappers compiled against an independent implementation of C17 7.22.1.4, over every string of length 0 to 6 from a 15-character alphabet, bases {0, 2, 8, 10, 16, 36}, all 12 exports (value, `endptr`, errno): 0 divergences from the reference and 0 regressions against `main`; `main` diverges on about 1.26 million of those cases and the branch on none. - `tools/check_conventions.py --base origin/main` passes; `tools/pr_overlap.py --branch` reports no overlap. - Linux not run (glibc already stops at the `x`). ### Checklist - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except technical debt - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed in TechnicalDebt - [x] No notes, investigation `.md` files or images added to the repository - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] AI-assisted: yes
github-actions[bot] commented 2026-10-10 10:45:23 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-10T10:45:23Z.


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.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6096690687 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2676#issuecomment-6096690687). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-10T10:45:23Z. --- 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

Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!2676
No description provided.