_Stoul truncates to 32 bits on Windows (unsigned long is 32-bit there) #2424

Closed
opened 2026-10-09 19:19:48 +00:00 by reyani-dev · 5 comments
reyani-dev commented 2026-10-09 19:19:48 +00:00 (Migrated from github.com)
Contributor

Imported from boykopovar/AnyPS5. Originally posted by reyani-dev on 2026-10-09T19:19:48Z.


_Stoul_nid_postfix (core/libs/prx/libc/src/RuntimeSupport.cpp) is declared to return unsigned long and calls std::strtoul. On the PS5 (LP64), unsigned long is 64-bit. On Windows (LLP64), both the return type and strtoul are 32-bit. So on the Windows build, the guest's _Stoul (the Dinkumware helper behind std::stoul) clamps every value above UINT32_MAX and sets ERANGE. A guest std::stoul would then throw out_of_range on inputs the console accepts.

Probe calling the export directly, on current main (Windows 11, WinLibs GCC 15.2.0 r7):

input _Stoul errno _Stoull (correct)
4294967295 4294967295 0 4294967295
4294967296 4294967295 34 4294967296
5000000000 4294967295 34 5000000000
18446744073709551615 4294967295 34 18446744073709551615
-1 4294967295 0 18446744073709551615

On Linux, unsigned long is 64-bit, so the same code is correct there.

A fix is a one-liner: return std::uint64_t (or unsigned long long) and call std::strtoull, like strtoul_nid_postfix in Strings.cpp already does. A grep of the exports found no other function with a plain long in its signature.

I haven't opened a PR because #1459 changes the body of this function and #2170 touches the lines next to it, and intake is paused for my account. Whichever lands first could include it.

AI-assisted: yes (the probe was written and run with Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5783436536 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/2424). Originally posted by [reyani-dev](https://github.com/reyani-dev) on 2026-10-09T19:19:48Z. --- `_Stoul_nid_postfix` (`core/libs/prx/libc/src/RuntimeSupport.cpp`) is declared to return `unsigned long` and calls `std::strtoul`. On the PS5 (LP64), `unsigned long` is 64-bit. On Windows (LLP64), both the return type and `strtoul` are 32-bit. So on the Windows build, the guest's `_Stoul` (the Dinkumware helper behind `std::stoul`) clamps every value above `UINT32_MAX` and sets `ERANGE`. A guest `std::stoul` would then throw `out_of_range` on inputs the console accepts. Probe calling the export directly, on current `main` (Windows 11, WinLibs GCC 15.2.0 r7): | input | `_Stoul` | errno | `_Stoull` (correct) | |---|---|---|---| | `4294967295` | 4294967295 | 0 | 4294967295 | | `4294967296` | **4294967295** | **34** | 4294967296 | | `5000000000` | **4294967295** | **34** | 5000000000 | | `18446744073709551615` | **4294967295** | **34** | 18446744073709551615 | | `-1` | **4294967295** | 0 | 18446744073709551615 | On Linux, `unsigned long` is 64-bit, so the same code is correct there. A fix is a one-liner: return `std::uint64_t` (or `unsigned long long`) and call `std::strtoull`, like `strtoul_nid_postfix` in `Strings.cpp` already does. A grep of the exports found no other function with a plain `long` in its signature. I haven't opened a PR because #1459 changes the body of this function and #2170 touches the lines next to it, and intake is paused for my account. Whichever lands first could include it. AI-assisted: yes (the probe was written and run with Claude Code).
MarcZX10 commented 2026-10-09 20:57:26 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-09T20:57:26Z.


Update after checking the live PR queue: #2442 was automatically closed by the repository’s intake-pause workflow shortly after opening; its Conventions check passed, and the closure comment says this was not a quality judgment. Open PR #1459 also edits _Stoul_nid_postfix while fixing Linux C17 binary-prefix parsing. I left a coordination note there asking whether the compatible Windows 64-bit conversion should be folded into that existing branch or kept as a future follow-up. No duplicate patch or PR has been created.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6089129851 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/2424#issuecomment-6089129851). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-09T20:57:26Z. --- Update after checking the live PR queue: #2442 was automatically closed by the repository’s intake-pause workflow shortly after opening; its Conventions check passed, and the closure comment says this was not a quality judgment. Open PR #1459 also edits `_Stoul_nid_postfix` while fixing Linux C17 binary-prefix parsing. I left a coordination note there asking whether the compatible Windows 64-bit conversion should be folded into that existing branch or kept as a future follow-up. No duplicate patch or PR has been created.
nauroth commented 2026-10-09 21:41:52 +00:00 (Migrated from github.com)
Author
Contributor

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


Thanks @AchrafReyani for the clear report and the probe values. Since #1459 already touches _Stoul_nid_postfix, and @MarcZX100 suggested folding it in rather than waiting for intake to resume, the 64-bit fix is now a separate commit on that branch: std::uint64_t from std::strtoull, with guest_math checking "4294967296", "18446744073709551615" and "-1". The cases come from @SurajKhanna's #2442, credited in the commit message. If #1459 lands, this can close with it.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6089735875 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/2424#issuecomment-6089735875). Originally posted by [nauroth](https://github.com/nauroth) on 2026-10-09T21:41:52Z. --- Thanks @AchrafReyani for the clear report and the probe values. Since #1459 already touches `_Stoul_nid_postfix`, and @MarcZX100 suggested folding it in rather than waiting for intake to resume, the 64-bit fix is now a separate commit on that branch: `std::uint64_t` from `std::strtoull`, with `guest_math` checking `"4294967296"`, `"18446744073709551615"` and `"-1"`. The cases come from @SurajKhanna's #2442, credited in the commit message. If #1459 lands, this can close with it.
mrlempticles commented 2026-10-10 00:06:18 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by mrlempticles on 2026-10-10T00:06:18Z.


I've implemented a fix for this in my fork (branch ix/libc-stoul-windows-truncation). Changed _Stoul_nid_postfix to return unsigned long long and use std::strtoull to match PS5 LP64 behavior. Will resubmit a PR when intake reopens.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6091397859 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/2424#issuecomment-6091397859). Originally posted by [mrlempticles](https://github.com/mrlempticles) on 2026-10-10T00:06:18Z. --- I've implemented a fix for this in my fork (branch ix/libc-stoul-windows-truncation). Changed _Stoul_nid_postfix to return unsigned long long and use std::strtoull to match PS5 LP64 behavior. Will resubmit a PR when intake reopens.
Yuva1024 commented 2026-10-10 02:11:19 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by Yuva1024 on 2026-10-10T02:11:19Z.


The 64-bit fix is on main as 2243e17f, merged with #1459: _Stoul_nid_postfix returns std::uint64_t from std::strtoull. I think this can be closed.

AI-assisted: yes (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6092569649 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/2424#issuecomment-6092569649). Originally posted by [Yuva1024](https://github.com/Yuva1024) on 2026-10-10T02:11:19Z. --- The 64-bit fix is on `main` as `2243e17f`, merged with #1459: `_Stoul_nid_postfix` returns `std::uint64_t` from `std::strtoull`. I think this can be closed. AI-assisted: yes (Claude Code).
oneandonlydean commented 2026-10-10 03:08:05 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-10T03:08:05Z.


Fixed by #1459 (2243e17f): _Stoul now returns a 64-bit value from strtoull on Windows too. Reopen if it still truncates on current main.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6093147157 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/2424#issuecomment-6093147157). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-10T03:08:05Z. --- Fixed by #1459 (2243e17f): `_Stoul` now returns a 64-bit value from `strtoull` on Windows too. Reopen if it still truncates on current main.
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#2424
No description provided.