fix(libc): return 64-bit values from _Stoul on Windows #2442

Closed
SurajKhanna wants to merge 1 commit from upstream-pr/2442 into main
SurajKhanna commented 2026-10-09 20:34:45 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by SurajKhanna on 2026-10-09T20:34:45Z.


What

_Stoul_nid_postfix in RuntimeSupport.cpp was declared returning unsigned long and delegating to std::strtoul. On the PS5 (LP64), unsigned long is 64-bit, but on Windows (LLP64), unsigned long and std::strtoul are 32-bit. On Windows host builds, inputs exceeding UINT32_MAX (4294967295) were clamped to UINT32_MAX and set errno to ERANGE (34), which causes guest std::stoul calls to throw std::out_of_range on values the console accepts.

Fixes this by:

  • Updating _Stoul_nid_postfix return type to std::uint64_t and delegating to std::strtoull (matching strtoul_nid_postfix in Strings.cpp).
  • Adding regression test cases in GuestMath.cpp verifying parsing of 64-bit values (4294967296 and 18446744073709551615) without truncation or setting ERANGE.

Fixes #2424.

Tested

Windows 11, GCC 16.2.0 (UCRT64):

  • Direct probe verifying _Stoul_nid_postfix parses 64-bit values up to UINT64_MAX without setting ERANGE.
  • Unit test suite (guest_math_tests).

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 (attach them to this PR)
  • 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:4805579899 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2442). Originally posted by [SurajKhanna](https://github.com/SurajKhanna) on 2026-10-09T20:34:45Z. --- ### What `_Stoul_nid_postfix` in `RuntimeSupport.cpp` was declared returning `unsigned long` and delegating to `std::strtoul`. On the PS5 (LP64), `unsigned long` is 64-bit, but on Windows (LLP64), `unsigned long` and `std::strtoul` are 32-bit. On Windows host builds, inputs exceeding `UINT32_MAX` (4294967295) were clamped to `UINT32_MAX` and set `errno` to `ERANGE` (34), which causes guest `std::stoul` calls to throw `std::out_of_range` on values the console accepts. Fixes this by: - Updating `_Stoul_nid_postfix` return type to `std::uint64_t` and delegating to `std::strtoull` (matching `strtoul_nid_postfix` in `Strings.cpp`). - Adding regression test cases in `GuestMath.cpp` verifying parsing of 64-bit values (`4294967296` and `18446744073709551615`) without truncation or setting `ERANGE`. Fixes #2424. ### Tested Windows 11, GCC 16.2.0 (UCRT64): - Direct probe verifying `_Stoul_nid_postfix` parses 64-bit values up to `UINT64_MAX` without setting `ERANGE`. - Unit test suite (`guest_math_tests`). ### 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](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/TechnicalDebt.md#silent-stubs) - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [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-09 20:51:14 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-09T20:51:14Z.


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:6089043991 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2442#issuecomment-6089043991). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-09T20:51:14Z. --- 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.
nauroth commented 2026-10-09 21:41:05 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by nauroth on 2026-10-09T21:41:05Z.


Thanks @SurajKhanna, the fix was right and the intake pause was just unlucky timing. Rather than let it sit, I've carried it into #1459, which already changes the same function: same std::uint64_t + std::strtoull, and your two guest_math cases exactly as you wrote them, with you credited in the commit message. Thanks also to @MarcZX100 for pointing me to it and @AchrafReyani for the report in #2424.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6089724486 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2442#issuecomment-6089724486). Originally posted by [nauroth](https://github.com/nauroth) on 2026-10-09T21:41:05Z. --- Thanks @SurajKhanna, the fix was right and the intake pause was just unlucky timing. Rather than let it sit, I've carried it into #1459, which already changes the same function: same `std::uint64_t` + `std::strtoull`, and your two `guest_math` cases exactly as you wrote them, with you credited in the commit message. Thanks also to @MarcZX100 for pointing me to it and @AchrafReyani for the report in #2424.

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!2442
No description provided.