public inbox for newlib-cvs@sourceware.org
help / color / mirror / Atom feed
* [newlib-cygwin] Fix 32-bit overflow in mktime() when time_t is 64-bits long
@ 2018-05-29 13:27 Corinna Vinschen
  0 siblings, 0 replies; only message in thread
From: Corinna Vinschen @ 2018-05-29 13:27 UTC (permalink / raw)
  To: newlib-cvs

https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=3305f3557064a3cc981e3566959d7833bb81e192

commit 3305f3557064a3cc981e3566959d7833bb81e192
Author: Freddie Chopin <freddie.chopin@gmail.com>
Date:   Tue May 15 20:58:08 2018 +0200

    Fix 32-bit overflow in mktime() when time_t is 64-bits long
    
    When converting number of days since epoch (32-bits) to seconds,
    calculations using 32-bit `long` overflow for years above 2038. Solve
    this by casting number of days to `time_t` just before final
    multiplication.
    
    Signed-off-by: Freddie Chopin <freddie.chopin@gmail.com>

Diff:
---
 newlib/libc/time/mktime.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/newlib/libc/time/mktime.c b/newlib/libc/time/mktime.c
index 9bcef32..0203259 100644
--- a/newlib/libc/time/mktime.c
+++ b/newlib/libc/time/mktime.c
@@ -188,7 +188,7 @@ mktime (struct tm *tim_p)
     }
 
   /* compute total seconds */
-  tim += (days * _SEC_IN_DAY);
+  tim += (time_t)days * _SEC_IN_DAY;
 
   TZ_LOCK;


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2018-05-29 13:27 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-05-29 13:27 [newlib-cygwin] Fix 32-bit overflow in mktime() when time_t is 64-bits long Corinna Vinschen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).