test(libc): cover memmove, memchr, strtoll, strtod and other untested string functions #1843

Closed
NahuelGenchi wants to merge 1 commit from upstream-pr/1843 into main
NahuelGenchi commented 2026-10-08 21:24:20 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by NahuelGenchi on 2026-10-08T21:24:20Z.


What

A scan for libc exports that no test mentions turned up a group of basic string functions in Strings.cpp: memmove, memchr, bzero, bcmp, strcat, strncpy, strrchr, strspn, strcoll, strxfrm, atoi, strtoll, _Stoull, strtod and strncpy_s. Most of them forward to the host C library, so a wrong signature, a wrong argument order or a host difference would go unnoticed. This adds guest_string_basics, one test with the results the C standard defines for each: overlapping memmove in both directions, memchr with a character above 255 and a length limit, strncpy padding and its missing terminator when truncated, strrchr on the terminator, strtoll bases 0, 16 and 36 with the end pointer and with clamping at both ends, _Stoull wrapping a negative number and clamping above the maximum, and strtod with signs, exponents, inf and out of range exponents. strncpy_s is checked for the guest error values it returns today (22 and 34), the same way guest_strings already checks strcpy_s.

Left out on purpose because the answer depends on the host C library: atoi overflow, hex floats and nan in strtod, and strncpy_s with a count of -1 (truncate), which the code doesn't treat as Annex K does and which I couldn't confirm for the console.

I did not touch GuestStrings.cpp, which #1490 edits, so the two don't conflict. No library code changes.

Tested

Ubuntu 26.04, GCC 15.2. The new test passes, and I flipped one expectation to confirm that it aborts when a result is wrong. The convention and test registration checks pass. Not run on Windows locally, so the Windows job is the first run there.

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:4792969743 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1843). Originally posted by [NahuelGenchi](https://github.com/NahuelGenchi) on 2026-10-08T21:24:20Z. --- ### What A scan for libc exports that no test mentions turned up a group of basic string functions in `Strings.cpp`: `memmove`, `memchr`, `bzero`, `bcmp`, `strcat`, `strncpy`, `strrchr`, `strspn`, `strcoll`, `strxfrm`, `atoi`, `strtoll`, `_Stoull`, `strtod` and `strncpy_s`. Most of them forward to the host C library, so a wrong signature, a wrong argument order or a host difference would go unnoticed. This adds `guest_string_basics`, one test with the results the C standard defines for each: overlapping `memmove` in both directions, `memchr` with a character above 255 and a length limit, `strncpy` padding and its missing terminator when truncated, `strrchr` on the terminator, `strtoll` bases 0, 16 and 36 with the end pointer and with clamping at both ends, `_Stoull` wrapping a negative number and clamping above the maximum, and `strtod` with signs, exponents, `inf` and out of range exponents. `strncpy_s` is checked for the guest error values it returns today (22 and 34), the same way `guest_strings` already checks `strcpy_s`. Left out on purpose because the answer depends on the host C library: `atoi` overflow, hex floats and `nan` in `strtod`, and `strncpy_s` with a count of `-1` (truncate), which the code doesn't treat as Annex K does and which I couldn't confirm for the console. I did not touch `GuestStrings.cpp`, which #1490 edits, so the two don't conflict. No library code changes. ### Tested Ubuntu 26.04, GCC 15.2. The new test passes, and I flipped one expectation to confirm that it aborts when a result is wrong. The convention and test registration checks pass. Not run on Windows locally, so the Windows job is the first run there. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [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
oneandonlydean commented 2026-10-09 08:53:45 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-09T08:53:45Z.


Closing: this pins what the existing string exports return today and passes on main, so it can't catch anything yet; tests go in with the change they cover. If one of these functions turns out wrong, a fix with this test would be welcome.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6077690751 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1843#issuecomment-6077690751). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-09T08:53:45Z. --- Closing: this pins what the existing string exports return today and passes on main, so it can't catch anything yet; tests go in with the change they cover. If one of these functions turns out wrong, a fix with this test would be welcome.

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