libc: strtol family leaves the end pointer at a bare 0x prefix on Windows; fix branch ready #3075

Closed
opened 2026-10-10 21:46:04 +00:00 by screamm · 1 comment
screamm commented 2026-10-10 21:46:04 +00:00 (Migrated from github.com)
Contributor

Imported from boykopovar/AnyPS5. Originally posted by screamm on 2026-10-10T21:46:04Z.


On Windows, the libc strtol family (strtol, strtoul, strtoimax, wcstol, wcstoul, _Stoul, ...) sets the end pointer to the start of the string for a bare 0x prefix with no hex digit after it, in base 0 and 16: strtoul("0xg", &end, 16) leaves end at "0xg" instead of just after the 0. The C standard's subject-sequence rule, FreeBSD and glibc all return 0 with the end pointer after the 0; the Linux build already does. The cause is the shared Windows helper StopAtBinaryPrefix_nid_no_patch in Strings.cpp, which only handles the 0b prefix the host C runtime accepts.

Fix branch ready: screamm:fix/libc-strtol-0x-prefix (63cce467, one commit on main 262c0316). I cannot open it as a PR because of the intake check; anyone eligible is welcome to carry it, keeping the commit as is. The helper is renamed StopAtPrefixLetter_nid_no_patch and also stops at a 0x without a hex digit; five rows are added to the existing guest_math strtol/strtoimax and strtoul tables (" -0xz!" base 0, "0xg" and "0x" base 16, " +0Xg!" base 0, "0x!" base 16), each expecting 0 with the end pointer after the 0.

Tested on Windows 11 Pro 26220, WinLibs MinGW-w64 GCC 15.2.0 r7, Ninja, Release, BUILD_TESTING=ON, full build including libs: guest_math 3/3; ctest -j8 -E "^agc_|video_out" 388/388 with this commit alone; tools/check_conventions.py --base main and git diff --check pass. Not run on Linux, where the helper is not used.

Written with Claude Code assistance (found and fixed by a subagent while testing _WStoul, reviewed and validated in this session).

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5795556348 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/3075). Originally posted by [screamm](https://github.com/screamm) on 2026-10-10T21:46:04Z. --- On Windows, the libc `strtol` family (`strtol`, `strtoul`, `strtoimax`, `wcstol`, `wcstoul`, `_Stoul`, ...) sets the end pointer to the start of the string for a bare `0x` prefix with no hex digit after it, in base 0 and 16: `strtoul("0xg", &end, 16)` leaves `end` at `"0xg"` instead of just after the `0`. The C standard's subject-sequence rule, FreeBSD and glibc all return 0 with the end pointer after the `0`; the Linux build already does. The cause is the shared Windows helper `StopAtBinaryPrefix_nid_no_patch` in [Strings.cpp](https://github.com/boykopovar/AnyPS5/blob/main/core/libs/prx/libc/src/Strings.cpp), which only handles the `0b` prefix the host C runtime accepts. **Fix branch ready:** [`screamm:fix/libc-strtol-0x-prefix`](https://github.com/screamm/AnyPS5/tree/fix/libc-strtol-0x-prefix) (`63cce467`, one commit on `main` `262c0316`). I cannot open it as a PR because of the intake check; anyone eligible is welcome to carry it, keeping the commit as is. The helper is renamed `StopAtPrefixLetter_nid_no_patch` and also stops at a `0x` without a hex digit; five rows are added to the existing `guest_math` strtol/strtoimax and strtoul tables (`" -0xz!"` base 0, `"0xg"` and `"0x"` base 16, `" +0Xg!"` base 0, `"0x!"` base 16), each expecting 0 with the end pointer after the `0`. **Tested** on Windows 11 Pro 26220, WinLibs MinGW-w64 GCC 15.2.0 r7, Ninja, Release, `BUILD_TESTING=ON`, full build including `libs`: `guest_math` 3/3; `ctest -j8 -E "^agc_|video_out"` 388/388 with this commit alone; `tools/check_conventions.py --base main` and `git diff --check` pass. Not run on Linux, where the helper is not used. Written with Claude Code assistance (found and fixed by a subagent while testing `_WStoul`, reviewed and validated in this session).
oneandonlydean commented 2026-10-11 01:08:49 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-11T01:08:49Z.


Fixed by #3082.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6104056176 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/3075#issuecomment-6104056176). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-11T01:08:49Z. --- Fixed by #3082.
Sign in to join this conversation.
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#3075
No description provided.