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

Closed
BharatYadav007 wants to merge 1 commit from upstream-pr/3547 into main
BharatYadav007 commented 2026-10-11 13:00:38 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by BharatYadav007 on 2026-10-11T13:00:38Z.


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.

Rebased onto upstream main at a11c8f7f7. Checked 132 open PR heads for overlap before submission; none implements this change.

Tested

  • 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 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; 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:4819231788 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3547). Originally posted by [BharatYadav007](https://github.com/BharatYadav007) on 2026-10-11T13:00:38Z. --- ### 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. Rebased onto upstream main at `a11c8f7f7`. Checked 132 open PR heads for overlap before submission; none implements this change. ### Tested - 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 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 - [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
github-actions[bot] commented 2026-10-11 13:00:50 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-11T13:00:50Z.


Thank you for your contribution! Authors with no pull requests merged into main can have 1 open pull request at a time, authors with at least 1 merged can have 20, and from 20 merged there is no limit. This PR has been automatically closed and labeled "open PR limit" because that limit was reached. This is not a judgment of the quality of your changes: reopen it once one of your open pull requests is merged or closed.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6109288670 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3547#issuecomment-6109288670). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-11T13:00:50Z. --- Thank you for your contribution! Authors with no pull requests merged into `main` can have 1 open pull request at a time, authors with at least 1 merged can have 20, and from 20 merged there is no limit. This PR has been automatically closed and labeled "open PR limit" because that limit was reached. This is not a judgment of the quality of your changes: reopen it once one of your open pull requests is merged or closed.
copilot-pull-request-reviewer[bot] commented 2026-10-11 13:03:02 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by copilot-pull-request-reviewer[bot] on 2026-10-11T13:03:02Z.

Review: COMMENTED


The implementation is focused, preserves failure behavior, and includes comprehensive regression coverage.

0 open findings

What changed in this PR

Fixes mktime handling for the valid -1 epoch-adjacent timestamp while preserving inputs on genuine failures.

Changes:

  • Distinguishes valid -1 results using tm_wday.
  • Adds cross-platform normalization and failure regression tests.
  • Registers the new test executable.
File Description
core/​libs/​tests/​GuestMktime.cpp Adds mktime regression coverage.
core/​libs/​prx/​libc/​src/​Time.cpp Correctly handles valid -1 results.
core/​libs/​prx/​libc/​CMakeLists.txt Registers the new tests.

🧠 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:5483397953 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3547#pullrequestreview-5483397953). Originally posted by [copilot-pull-request-reviewer[bot]](https://github.com/apps/copilot-pull-request-reviewer) on 2026-10-11T13:03:02Z. **Review:** COMMENTED --- <!-- ccr-overview-v2 --> ### 🟢 Approval recommended The implementation is focused, preserves failure behavior, and includes comprehensive regression coverage. **0 open findings** <details> <summary><strong>What changed in this PR</strong></summary> Fixes `mktime` handling for the valid `-1` epoch-adjacent timestamp while preserving inputs on genuine failures. **Changes:** - Distinguishes valid `-1` results using `tm_wday`. - Adds cross-platform normalization and failure regression tests. - Registers the new test executable. | File | Description | | ---- | ----------- | | `core/​libs/​tests/​GuestMktime.cpp` | Adds `mktime` regression coverage. | | `core/​libs/​prx/​libc/​src/​Time.cpp` | Correctly handles valid `-1` results. | | `core/​libs/​prx/​libc/​CMakeLists.txt` | Registers the new tests. | </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>

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