test(libc): cover getcwd zero-size buffer #1369

Merged
MarcZX10 merged 1 commit from upstream-pr/1369 into main 2026-10-09 22:36:51 +00:00
MarcZX10 commented 2026-10-08 00:33:41 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-08T00:33:41Z.


What

Add regression coverage for getcwd with a non-null buffer and a zero size. It must return null and set EINVAL; this distinguishes that branch from the adjacent ERANGE case.

Tested

Current head d809ccf79779a42a32d126ef1dabbaf53ebd233d, rebased onto upstream main f8c2f072463465f875dedb0d20b66c339160c1a1:

  • Linux x86-64, GCC 12.2, Release: rebuilt guest_working_directory_tests; guest_working_directory passed (1/1). The local build checkout also contained a separate, unrelated AGC fix; the PR diff itself remains the single assertion shown above.
  • python3 tools/check_conventions.py --base upstream/main and git diff --check upstream/main...HEAD pass on the rebased PR tree.

Earlier Windows evidence on the pre-rebase head 09a410df (based on d70b8998): guest_working_directory passed with no skipped cases. The aggregate CTest run passed 519/519 but needed local fixes to unrelated #1611, #1796, and #1824. That run is not evidence for the current PR head or an unmodified upstream Build.

The required upstream Linux/Windows Build and relinker matrix has not been run on current head d809ccf. No PS5 hardware or title runtime was tested.

Checklist

  • Based on current main; no other open PR implements the same behavior
  • One topic per PR; follow-ups go in a new PR
  • No code comments except technical debt comments
  • No notes, investigation files or images added to the repository
  • No third-party code added
  • Generic behavior
  • Depends on: none
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4780168828 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1369). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-08T00:33:41Z. --- ### What Add regression coverage for `getcwd` with a non-null buffer and a zero size. It must return null and set `EINVAL`; this distinguishes that branch from the adjacent `ERANGE` case. ### Tested Current head `d809ccf79779a42a32d126ef1dabbaf53ebd233d`, rebased onto upstream `main` `f8c2f072463465f875dedb0d20b66c339160c1a1`: - Linux x86-64, GCC 12.2, Release: rebuilt `guest_working_directory_tests`; `guest_working_directory` passed (1/1). The local build checkout also contained a separate, unrelated AGC fix; the PR diff itself remains the single assertion shown above. - `python3 tools/check_conventions.py --base upstream/main` and `git diff --check upstream/main...HEAD` pass on the rebased PR tree. Earlier Windows evidence on the pre-rebase head `09a410df` (based on `d70b8998`): `guest_working_directory` passed with no skipped cases. The aggregate CTest run passed 519/519 but needed local fixes to unrelated #1611, #1796, and #1824. That run is not evidence for the current PR head or an unmodified upstream Build. The required upstream Linux/Windows Build and relinker matrix has not been run on current head `d809ccf`. No PS5 hardware or title runtime was tested. ### Checklist - [x] Based on current `main`; no other open PR implements the same behavior - [x] One topic per PR; follow-ups go in a new PR - [x] No code comments except technical debt comments - [x] No notes, investigation files or images added to the repository - [x] No third-party code added - [x] Generic behavior - [x] Depends on: none - [x] AI-assisted: yes
Dextroid17 commented 2026-10-08 02:24:57 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Dextroid17 on 2026-10-08T02:24:57Z.

Review: COMMENTED


Built and ran it, and checked the assertion is not vacuous.

Linux (CachyOS, GCC, Release):

cmake --build build --target guest_working_directory_tests --parallel 16
ctest -R guest_working_directory    →  1/1 Passed

The assertion bites, proven by mutation. General.cpp:136 is an explicit branch:

if (buffer && size == 0) { errno = 22; return nullptr; }

Changing only the value it sets (22 → 34) while keeping your test:

errno 22 (as written):  1/1 Passed
errno 34 (mutated):     ***Failed

So the line is pinned to that branch and to EINVAL, rather than passing on whatever getcwd happens to return.

Why the line earns its place rather than repeating line 27. The test already asserts the ERANGE case (getcwd(tiny, 2) == nullptr && errno == 34). Your case is a different input reaching a different branch, and the two are genuinely adjacent:

if (buffer && size == 0) { errno = 22; return nullptr; }          // your case → EINVAL
...
if ((buffer || size) && size < required) { errno = 34; return nullptr; }   // ERANGE

For buffer != NULL, size == 0 the ERANGE guard is also true ((buffer || size) holds, 0 < required holds), so if the explicit EINVAL branch were ever removed or reordered, this call would silently start returning 34 — and only your assertion would notice, because line 27 uses a non-zero size. That is the gap this closes, and it is the right one.

The function's other outcomes are already covered: the normal path (lines 16, 23), too-small with ERANGE (27), size 0 with EINVAL (29, yours) and the allocating path (30). I did not find a branch of getcwd in this implementation left unpinned by the file after your change, so I have nothing to ask for.

Nothing further from me — this is coverage of behaviour that already existed, correctly, and it now fails loudly if that behaviour changes.

This is a comment, not an approval — I have no merge rights here.

Written with AI assistance.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5450664783 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1369#pullrequestreview-5450664783). Originally posted by [Dextroid17](https://github.com/Dextroid17) on 2026-10-08T02:24:57Z. **Review:** COMMENTED --- Built and ran it, and checked the assertion is not vacuous. **Linux (CachyOS, GCC, Release):** ``` cmake --build build --target guest_working_directory_tests --parallel 16 ctest -R guest_working_directory → 1/1 Passed ``` **The assertion bites, proven by mutation.** `General.cpp:136` is an explicit branch: ```cpp if (buffer && size == 0) { errno = 22; return nullptr; } ``` Changing only the value it sets (22 → 34) while keeping your test: ``` errno 22 (as written): 1/1 Passed errno 34 (mutated): ***Failed ``` So the line is pinned to that branch and to `EINVAL`, rather than passing on whatever `getcwd` happens to return. **Why the line earns its place rather than repeating line 27.** The test already asserts the ERANGE case (`getcwd(tiny, 2) == nullptr && errno == 34`). Your case is a *different* input reaching a *different* branch, and the two are genuinely adjacent: ```cpp if (buffer && size == 0) { errno = 22; return nullptr; } // your case → EINVAL ... if ((buffer || size) && size < required) { errno = 34; return nullptr; } // ERANGE ``` For `buffer != NULL, size == 0` the ERANGE guard is *also* true (`(buffer || size)` holds, `0 < required` holds), so if the explicit EINVAL branch were ever removed or reordered, this call would silently start returning `34` — and only your assertion would notice, because line 27 uses a non-zero size. That is the gap this closes, and it is the right one. The function's other outcomes are already covered: the normal path (lines 16, 23), too-small with `ERANGE` (27), size 0 with `EINVAL` (29, yours) and the allocating path (30). I did not find a branch of `getcwd` in this implementation left unpinned by the file after your change, so I have nothing to ask for. Nothing further from me — this is coverage of behaviour that already existed, correctly, and it now fails loudly if that behaviour changes. This is a comment, not an approval — I have no merge rights here. Written with AI assistance.
oneandonlydean commented 2026-10-08 05:12:55 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-08T05:12:55Z.


Please fill in the PR template (What, Tested, Checklist); the conventions check fails without those sections.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6052801662 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1369#issuecomment-6052801662). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-08T05:12:55Z. --- Please fill in the PR template (What, Tested, Checklist); the conventions check fails without those sections.
MarcZX10 commented 2026-10-08 11:43:40 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-08T11:43:40Z.


The PR description now has the requested What / Tested / Checklist sections. The current Linux, Windows, Conventions and Progress report checks all pass, and the PR is cleanly mergeable against main.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6059117535 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1369#issuecomment-6059117535). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-08T11:43:40Z. --- The PR description now has the requested What / Tested / Checklist sections. The current Linux, Windows, Conventions and Progress report checks all pass, and the PR is cleanly mergeable against `main`.
MarcZX10 commented 2026-10-08 19:26:59 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-08T19:26:59Z.


Rebased this one-line test change directly onto current upstream/main (0447793). I rebuilt guest_working_directory_tests; focused CTest passes (1/1), conventions pass, and git diff --check passes. The updated head is 372f4a4, but upstream currently reports no checks or workflow runs for it. Per CONTRIBUTING, fork workflows may need maintainer approval; could an authorized maintainer approve the runs so CI can validate this head?

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6067439003 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1369#issuecomment-6067439003). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-08T19:26:59Z. --- Rebased this one-line test change directly onto current `upstream/main` (`0447793`). I rebuilt `guest_working_directory_tests`; focused CTest passes (1/1), conventions pass, and `git diff --check` passes. The updated head is `372f4a4`, but upstream currently reports no checks or workflow runs for it. Per CONTRIBUTING, fork workflows may need maintainer approval; could an authorized maintainer approve the runs so CI can validate this head?
MarcZX10 commented 2026-10-08 21:23:28 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-08T21:23:28Z.


Rebased this one-assertion test onto current upstream main (364a56b). The full diff still checks getcwd(path, 0) returns nullptr and sets EINVAL; the focused CTest passed (1/1) on the prior head. Conventions and git diff --check pass. No checks are reported for the rebased head yet.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6069321294 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1369#issuecomment-6069321294). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-08T21:23:28Z. --- Rebased this one-assertion test onto current upstream `main` (`364a56b`). The full diff still checks `getcwd(path, 0)` returns `nullptr` and sets `EINVAL`; the focused CTest passed (1/1) on the prior head. Conventions and `git diff --check` pass. No checks are reported for the rebased head yet.
MarcZX10 commented 2026-10-08 21:24:43 +00:00 (Migrated from github.com)

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


The Build/Conventions workflow runs for current head 35cd29c5c28ef152f52a7671e968a311a27d8858 are marked action_required and have no jobs, so upstream CI has not run yet. CONTRIBUTING requires maintainer approval for fork workflows. Could an authorized maintainer approve these current-head runs?

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6069339768 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1369#issuecomment-6069339768). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-08T21:24:43Z. --- The Build/Conventions workflow runs for current head `35cd29c5c28ef152f52a7671e968a311a27d8858` are marked `action_required` and have no jobs, so upstream CI has not run yet. CONTRIBUTING requires maintainer approval for fork workflows. Could an authorized maintainer approve these current-head runs?
MarcZX10 commented 2026-10-08 21:53:17 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-08T21:53:17Z.


Rebased the one-assertion test onto current upstream main (94b1eecb; head e58a7d40). It still checks getcwd(path, 0) returns nullptr and sets EINVAL; focused CTest passed on the prior head. Conventions and git diff --check pass. Current Build/Conventions/Progress runs are action_required with no jobs; could a maintainer approve this final head?

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6069761429 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1369#issuecomment-6069761429). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-08T21:53:17Z. --- Rebased the one-assertion test onto current upstream `main` (`94b1eecb`; head `e58a7d40`). It still checks `getcwd(path, 0)` returns `nullptr` and sets `EINVAL`; focused CTest passed on the prior head. Conventions and `git diff --check` pass. Current Build/Conventions/Progress runs are `action_required` with no jobs; could a maintainer approve this final head?
MarcZX10 commented 2026-10-09 00:13:46 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-09T00:13:46Z.


Rebased the one-assertion getcwd test onto current upstream main f1451396 at head 8cb00eea. The focused CTest passed 1/1 on the rebased source; conventions and git diff --check pass. Could a maintainer approve the upstream Build and Conventions runs for this new head under the fork workflow policy?

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6071588028 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1369#issuecomment-6071588028). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-09T00:13:46Z. --- Rebased the one-assertion `getcwd` test onto current upstream `main` `f1451396` at head `8cb00eea`. The focused CTest passed 1/1 on the rebased source; conventions and `git diff --check` pass. Could a maintainer approve the upstream Build and Conventions runs for this new head under the fork workflow policy?
MarcZX10 commented 2026-10-09 08:35:12 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-09T08:35:12Z.


Rebased the one-assertion regression onto current upstream main 6cc0503d; the full diff remains a single assertion. Current Linux guest_working_directory CTest passes (1/1, 0.00 s), and conventions/diff checks pass. Fork Build 37905837164 is running on the new head. The existing independent review confirmed the assertion is non-vacuous by mutation testing.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6077423106 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1369#issuecomment-6077423106). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-09T08:35:12Z. --- Rebased the one-assertion regression onto current upstream `main` `6cc0503d`; the full diff remains a single assertion. Current Linux `guest_working_directory` CTest passes (1/1, 0.00 s), and conventions/diff checks pass. Fork Build [37905837164](https://github.com/MarcZX100/AnyPS5/actions/runs/37905837164) is running on the new head. The existing independent review confirmed the assertion is non-vacuous by mutation testing.
MarcZX10 commented 2026-10-09 08:38:00 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-09T08:38:00Z.


Addressed: the PR now has explicit What, Tested and Checklist sections with current-base, focused CTest and conventions evidence. The one-assertion diff is rebased onto 6cc0503d; current-head fork Build is running.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6077462668 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1369#issuecomment-6077462668). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-09T08:38:00Z. --- Addressed: the PR now has explicit What, Tested and Checklist sections with current-base, focused CTest and conventions evidence. The one-assertion diff is rebased onto `6cc0503d`; current-head fork Build is running.
MarcZX10 commented 2026-10-09 08:47:12 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-09T08:47:12Z.


Fork Build completed with Linux and Windows blocked on the unrelated agc_shader_fusion_tests compile error: VulkanTestDevice.hpp cannot find spirv/unified1/spirv.hpp. All three relinker jobs passed. I recorded the result in the PR description and linked #2093 as the dependency fix.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6077594618 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1369#issuecomment-6077594618). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-09T08:47:12Z. --- Fork Build completed with Linux and Windows blocked on the unrelated `agc_shader_fusion_tests` compile error: `VulkanTestDevice.hpp` cannot find `spirv/unified1/spirv.hpp`. All three relinker jobs passed. I recorded the result in the PR description and linked #2093 as the dependency fix.
Dextroid17 commented 2026-10-09 11:23:05 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Dextroid17 on 2026-10-09T11:23:05Z.


Useful to have this on the record, and it matches what a full build shows here: agc_shader_fusion_tests compiles on this box, because SPIRV-Headers is present in the tree — so the spirv/unified1/spirv.hpp failure is your fork's dependency wiring rather than anything in your change. Linking #2093 as the dependency fix is the right call, and stating it in the description rather than leaving the Fork Build line unexplained is exactly the habit that makes a blocked run readable.

The assertion itself I did verify when I first looked: it pins the EINVAL branch for a zero-size buffer and fails when that branch's errno changes, so it is real coverage rather than a test that passes for the wrong reason.

Written with AI assistance.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6079880961 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1369#issuecomment-6079880961). Originally posted by [Dextroid17](https://github.com/Dextroid17) on 2026-10-09T11:23:05Z. --- Useful to have this on the record, and it matches what a full build shows here: `agc_shader_fusion_tests` compiles on this box, because SPIRV-Headers is present in the tree — so the `spirv/unified1/spirv.hpp` failure is your fork's dependency wiring rather than anything in your change. Linking #2093 as the dependency fix is the right call, and stating it in the description rather than leaving the Fork Build line unexplained is exactly the habit that makes a blocked run readable. The assertion itself I did verify when I first looked: it pins the `EINVAL` branch for a zero-size buffer and fails when that branch's errno changes, so it is real coverage rather than a test that passes for the wrong reason. Written with AI assistance.
popcoder565 commented 2026-10-09 15:45:18 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by popcoder565 on 2026-10-09T15:45:18Z.


Native Windows run, since no Windows results were posted. Setup: Windows 10 (19045), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release. Head 09a410df, merged onto main d70b8998 in one build with 38 other PRs that had no Windows run.

  • This PR's tests pass: guest_working_directory. None of them reported skipping a case.
  • Full ctest in that build: 519 of 519. That needed local fixes to three other PRs in the batch that don't build or pass on Windows: #1611, #1796 and #1824 (reported there).

No title was run.

🤖 Addressed by Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6084253543 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1369#issuecomment-6084253543). Originally posted by [popcoder565](https://github.com/popcoder565) on 2026-10-09T15:45:18Z. --- Native Windows run, since no Windows results were posted. Setup: Windows 10 (19045), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release. Head `09a410df`, merged onto `main` d70b8998 in one build with 38 other PRs that had no Windows run. - This PR's tests pass: `guest_working_directory`. None of them reported skipping a case. - Full ctest in that build: 519 of 519. That needed local fixes to three other PRs in the batch that don't build or pass on Windows: #1611, #1796 and #1824 (reported there). No title was run. _🤖 Addressed by [Claude Code](https://claude.com/claude-code)_
MarcZX10 commented 2026-10-09 17:35:09 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-09T17:35:09Z.


Thanks for the exact-head Windows run. I added the focused test result and aggregate CTest result to the PR description, including the local fixes to unrelated PRs so the batch is not presented as an unmodified upstream Build. The required upstream matrix and title testing remain outstanding.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6086014102 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1369#issuecomment-6086014102). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-09T17:35:09Z. --- Thanks for the exact-head Windows run. I added the focused test result and aggregate CTest result to the PR description, including the local fixes to unrelated PRs so the batch is not presented as an unmodified upstream Build. The required upstream matrix and title testing remain outstanding.
MarcZX10 commented 2026-10-09 17:39:48 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-09T17:39:48Z.


I rebased this existing PR onto current main (f8c2f072); the full diff remains the single EINVAL assertion. The focused Linux build and test pass 1/1, and Conventions is queued on the updated head. The earlier Windows result was on the pre-rebase head, so the current-head Windows and full upstream Build matrix remain outstanding.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6086085932 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1369#issuecomment-6086085932). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-09T17:39:48Z. --- I rebased this existing PR onto current `main` (`f8c2f072`); the full diff remains the single `EINVAL` assertion. The focused Linux build and test pass 1/1, and Conventions is queued on the updated head. The earlier Windows result was on the pre-rebase head, so the current-head Windows and full upstream Build matrix remain outstanding.
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!1369
No description provided.