summaryrefslogtreecommitdiff
path: root/Libraries/LibC
diff options
context:
space:
mode:
authorNico Weber <thakis@chromium.org>2020-08-23 21:37:03 -0400
committerAndreas Kling <kling@serenityos.org>2020-08-24 09:30:11 +0200
commit84f729c2b4dea4c6abf8aad69928dfe4cf72fb32 (patch)
treebd64bc573159923af661b2c6f9c657230962eb00 /Libraries/LibC
parent465d46c66542ca96eceb4e1765518ec6b934afec (diff)
downloadserenity-84f729c2b4dea4c6abf8aad69928dfe4cf72fb32.zip
LibJS+LibC: Add tests for Date tuple ctor overflow and make mktime()/timegm() handle month overflow
Diffstat (limited to 'Libraries/LibC')
-rw-r--r--Libraries/LibC/time.cpp8
1 files changed, 7 insertions, 1 deletions
diff --git a/Libraries/LibC/time.cpp b/Libraries/LibC/time.cpp
index a3fe523de2..018ccf6cda 100644
--- a/Libraries/LibC/time.cpp
+++ b/Libraries/LibC/time.cpp
@@ -103,6 +103,13 @@ static void time_to_tm(struct tm* tm, time_t t)
static time_t tm_to_time(struct tm* tm, long timezone_adjust_seconds)
{
+ tm->tm_year += tm->tm_mon / 12;
+ tm->tm_mon %= 12;
+ if (tm->tm_mon < 0) {
+ tm->tm_year--;
+ tm->tm_mon += 12;
+ }
+
int days = 0;
for (int year = 70; year < tm->tm_year; ++year)
days += 365 + __is_leap_year(1900 + year);
@@ -110,7 +117,6 @@ static time_t tm_to_time(struct tm* tm, long timezone_adjust_seconds)
days -= 365 + __is_leap_year(1900 + year);
tm->tm_yday = tm->tm_mday - 1;
- // FIXME: What if tm->tm_mon < 0 or tm->tm_mon > 12?
for (int month = 0; month < tm->tm_mon; ++month)
tm->tm_yday += __days_per_month[month];
if (tm->tm_mon > 1 && __is_leap_year(1900 + tm->tm_year))