Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

libc/time: Fix mktime() wrong behavior when time can not be represented #5

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Abdallahs70
Copy link
Collaborator

Part 7.23.2.1 requires that, quoting,

The tm structure shall contain at least the following members,
in any order. The semantics of the members and their normal ranges are expressed in the
comments.
int tm_sec; // seconds after the minute — [0, 60]
int tm_min; // minutes after the hour — [0, 59]
int tm_hour; // hours since midnight — [0, 23]
int tm_mday; // day of the month — [1, 31]
int tm_mon; // months since January — [0, 11]
int tm_year; // years since 1900
int tm_wday; // days since Sunday — [0, 6]
int tm_yday; // days since January 1 — [0, 365]
int tm_isdst; // Daylight Saving Time flag
So the tm structure can only represent years after 1900 which can only be indicated by positive value.

Part 7.23.2.3 also described the limitations on input and output as follows:
quoting:

The original values of the tm_wday and tm_yday components of the structure are ignored, 
and the original values of the other components are not restricted to the ranges indicated above.

On successful completion, the values of the tm_wday and tm_yday components of the structure are set appropriately, and the other components are set to represent the specified calendar time, but with their values forced to the ranges indicated above; the final value of tm_mday is not set until tm_mon and tm_year are determined.

And accordingly the check on the year value in related code was changed.

…nted

Part 7.23.2.3 requires mktime() function to return -1 in case of the calendar time cannot be represented.
and if year is negative that's wrong representation as part 7.23.2.1 specify the year component to be, quoting,

> int tm_year; // years since 1900

So it can only represent years after 1900 which can only be indicated by positive value.

Signed-off-by: Abdallah Abdelhafeez <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant