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
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions newlib/libc/time/mktime.c
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,10 @@ mktime_utc (struct tm *tim_p, long *days_p)
/* validate structure */
validate_structure (tim_p);

/* check if year has valid value */
if (tim_p->tm_year > 10000 || tim_p->tm_year < 0)
return (time_t) -1;

/* compute hours, minutes, seconds */
tim += tim_p->tm_sec + (tim_p->tm_min * SECSPERMIN) +
(tim_p->tm_hour * SECSPERHOUR);
Expand All @@ -204,9 +208,6 @@ mktime_utc (struct tm *tim_p, long *days_p)
/* compute day of the year */
tim_p->tm_yday = days;

if (tim_p->tm_year > 10000 || tim_p->tm_year < -10000)
return (time_t) -1;

/* compute days in other years */
if ((year = tim_p->tm_year) > 70)
{
Expand Down
Loading