From: Michael G Schwern <schwern@pobox.com>
Date: Sun, 14 Sep 2008 22:26:16 +0000 (-0700)
Subject: Update from y2038 project.
X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=af8328142f6d12b9ede82f0c5739270fe7c09b70;p=p5sagit%2Fp5-mst-13.2.git

Update from y2038 project.

Fix localtime64's over and underflow handling.
---

diff --git a/localtime64.c b/localtime64.c
index b9f60e9..ef8c40a 100644
--- a/localtime64.c
+++ b/localtime64.c
@@ -354,16 +354,27 @@ struct tm *localtime64_r (const Time64_T *time, struct tm *local_tm)
         return local_tm;
     }
 
-    gmtime64_r(time, &gm_tm);
+    if( gmtime64_r(time, &gm_tm) == NULL )
+        return NULL;
+
     orig_year = gm_tm.tm_year;
 
     if (gm_tm.tm_year > (2037 - 1900))
         gm_tm.tm_year = _safe_year(gm_tm.tm_year + 1900) - 1900;
 
     safe_time = TIMEGM(&gm_tm);
-    localtime_r(&safe_time, local_tm);
+    if( localtime_r(&safe_time, local_tm) == NULL )
+        return NULL;
 
     local_tm->tm_year = orig_year;
+    if( local_tm->tm_year != orig_year ) {
+#ifdef EOVERFLOW
+        errno = EOVERFLOW;
+#endif
+        return NULL;
+    }
+
+
     month_diff = local_tm->tm_mon - gm_tm.tm_mon;
 
     /*  When localtime is Dec 31st previous year and