fix(libc): normalize valid mktime minus-one results #4277

Merged
BharatYadav007 merged 1 commit from upstream-pr/4277 into main 2026-10-12 12:30:27 +00:00
BharatYadav007 commented 2026-10-12 03:53:52 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by BharatYadav007 on 2026-10-12T03:53:52Z.


What

A successful mktime can return -1 for the second before the Unix epoch. The libc wrapper treated every -1 result as a failure and left the guest calendar unnormalized.

Initialize the host weekday to an invalid value and treat -1 as failure only if the host conversion leaves that value unchanged. This preserves the guest input on genuine failures and normalizes valid -1 results through both libc_mktime and mktime. The distinction follows the documented tm_wday check in Linux man-pages.

Add a runtime test for both exports covering normalization around the epoch, multiple time zones, stale EOVERFLOW, unrepresentable calendars, and the Windows CRT's existing pre-epoch failure behavior. Windows pre-epoch support remains as documented in TechnicalDebt.

Replaces #3547, which was automatically closed under the open PR limit while #3542 was open. #3542 has now merged. The branch code is unchanged. Before the original submission, 132 open PR heads were checked for overlap; none implemented this change.

Tested

Validation performed on October 11 on branch commit bbd52a249, based on upstream a11c8f7f7:

  • Linux, Kali WSL, GCC 15.2.0: compiled the production Time.cpp with the regression fixture and ran it. The unmodified implementation failed at the valid -1 timestamp; the fix passed. This was a focused native runtime check, not a full Linux build.
  • Windows, GCC 15.2.0, Release Ninja build: guest_mktime passed in 0.10 s and guest_time_conversion passed in 0.13 s.
  • Windows: full default build and libs target passed.
  • tools/check_conventions.py --base upstream/main passed.
  • tools/check_test_registration.py build passed; all 638 test executables are registered.
  • No title, console hardware, or macOS testing.

Checklist

  • Based on main; no other open PR implements the same functions at the original overlap audit
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw; no silent stubs added
  • No notes, investigation .md files or images added to the repository
  • No new third-party code
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: no
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4824716032 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4277). Originally posted by [BharatYadav007](https://github.com/BharatYadav007) on 2026-10-12T03:53:52Z. --- ### What A successful `mktime` can return `-1` for the second before the Unix epoch. The libc wrapper treated every `-1` result as a failure and left the guest calendar unnormalized. Initialize the host weekday to an invalid value and treat `-1` as failure only if the host conversion leaves that value unchanged. This preserves the guest input on genuine failures and normalizes valid `-1` results through both `libc_mktime` and `mktime`. The distinction follows the documented `tm_wday` check in [Linux man-pages](https://man7.org/linux/man-pages/man3/mktime.3.html). Add a runtime test for both exports covering normalization around the epoch, multiple time zones, stale `EOVERFLOW`, unrepresentable calendars, and the Windows CRT's existing pre-epoch failure behavior. Windows pre-epoch support remains as documented in TechnicalDebt. Replaces #3547, which was automatically closed under the open PR limit while #3542 was open. #3542 has now merged. The branch code is unchanged. Before the original submission, 132 open PR heads were checked for overlap; none implemented this change. ### Tested Validation performed on October 11 on branch commit `bbd52a249`, based on upstream `a11c8f7f7`: - Linux, Kali WSL, GCC 15.2.0: compiled the production `Time.cpp` with the regression fixture and ran it. The unmodified implementation failed at the valid `-1` timestamp; the fix passed. This was a focused native runtime check, not a full Linux build. - Windows, GCC 15.2.0, Release Ninja build: `guest_mktime` passed in 0.10 s and `guest_time_conversion` passed in 0.13 s. - Windows: full default build and `libs` target passed. - `tools/check_conventions.py --base upstream/main` passed. - `tools/check_test_registration.py build` passed; all 638 test executables are registered. - No title, console hardware, or macOS testing. ### Checklist - [x] Based on main; no other open PR implements the same functions at the original overlap audit - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except technical debt - [x] Unimplemented paths throw; no silent stubs added - [x] No notes, investigation `.md` files or images added to the repository - [x] No new third-party code - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] AI-assisted: no
copilot-pull-request-reviewer[bot] commented 2026-10-12 03:57:00 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by copilot-pull-request-reviewer[bot] on 2026-10-12T03:57:00Z.

Review: COMMENTED


The focused implementation follows documented libc behavior and is covered by comprehensive cross-platform regression tests.

0 open findings

What changed in this PR

Fixes valid mktime results of -1 being mistaken for failures while preserving input on genuine failures.

Changes:

  • Uses tm_wday to distinguish valid -1 timestamps from errors.
  • Adds cross-platform normalization and failure regression tests.
  • Registers the new test target.
File Description
core/​libs/​tests/​GuestMktime.cpp Tests both exports across timestamps, time zones, and failures.
core/​libs/​prx/​libc/​src/​Time.cpp Correctly handles valid mktime results of -1.
core/​libs/​prx/​libc/​CMakeLists.txt Builds and registers the regression test.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5486410115 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4277#pullrequestreview-5486410115). Originally posted by [copilot-pull-request-reviewer[bot]](https://github.com/apps/copilot-pull-request-reviewer) on 2026-10-12T03:57:00Z. **Review:** COMMENTED --- <!-- ccr-overview-v2 --> ### 🟢 Approval recommended The focused implementation follows documented libc behavior and is covered by comprehensive cross-platform regression tests. **0 open findings** <details> <summary><strong>What changed in this PR</strong></summary> Fixes valid `mktime` results of `-1` being mistaken for failures while preserving input on genuine failures. **Changes:** - Uses `tm_wday` to distinguish valid `-1` timestamps from errors. - Adds cross-platform normalization and failure regression tests. - Registers the new test target. | File | Description | | ---- | ----------- | | `core/​libs/​tests/​GuestMktime.cpp` | Tests both exports across timestamps, time zones, and failures. | | `core/​libs/​prx/​libc/​src/​Time.cpp` | Correctly handles valid `mktime` results of `-1`. | | `core/​libs/​prx/​libc/​CMakeLists.txt` | Builds and registers the regression test. | </details> 🧠 **Review effort:** Balanced --- 💡 <a href="/boykopovar/AnyPS5/new/main?filename=.github/skills/code-review/SKILL.md" class="Link--inTextBlock" target="_blank" rel="noopener noreferrer">Add a `code-review` agent skill</a> or configure MCP servers for context-aware, tailored reviews. <a href="https://docs.github.com/copilot/how-tos/use-copilot-agents/request-a-code-review/use-code-review?tool=webui#mcp-servers-and-agent-skills" class="Link--inTextBlock" target="_blank" rel="noopener noreferrer">Learn more in the docs.</a>
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!4277
No description provided.