Skip to content

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

Merged
oneandonlydean merged 1 commit into
boykopovar:mainfrom
BharatYadav007:bharat/libc-mktime-negative-one
Oct 12, 2026
Merged

oneandonlydean merged 1 commit into
boykopovar:mainfrom
BharatYadav007:bharat/libc-mktime-negative-one

Conversation

@BharatYadav007

Copy link
Copy Markdown
Contributor

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

Copilot AI balanced review requested due to automatic review settings October 12, 2026 03:53

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

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.

@BharatYadav007
BharatYadav007 force-pushed the bharat/libc-mktime-negative-one branch from bbd52a2 to f0e852a Compare October 12, 2026 04:55
@oneandonlydean oneandonlydean self-assigned this Oct 12, 2026
@oneandonlydean
oneandonlydean merged commit 0ef9dc9 into boykopovar:main Oct 12, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants