From fe21241ee0268b3740a1e9980201115775a8d191 Mon Sep 17 00:00:00 2001 From: Konstantin Belousov Date: Fri, 12 Dec 2014 09:37:18 +0000 Subject: [PATCH] For architectures where time_t is wide enough, in particular, 64bit platforms, avoid overflow after year 2038 in clock_ct_to_ts(). PR: 195868 Reviewed by: bde Sponsored by: The FreeBSD Foundation MFC after: 1 week --- sys/kern/subr_clock.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/sys/kern/subr_clock.c b/sys/kern/subr_clock.c index f30f529dbdba..05de5b94c819 100644 --- a/sys/kern/subr_clock.c +++ b/sys/kern/subr_clock.c @@ -133,7 +133,6 @@ print_ct(struct clocktime *ct) int clock_ct_to_ts(struct clocktime *ct, struct timespec *ts) { - time_t secs; int i, year, days; year = ct->year; @@ -167,11 +166,10 @@ clock_ct_to_ts(struct clocktime *ct, struct timespec *ts) days += days_in_month(year, i); days += (ct->day - 1); - /* Add hours, minutes, seconds. */ - secs = ((days * 24 + ct->hour) * 60 + ct->min) * 60 + ct->sec; - - ts->tv_sec = secs; + ts->tv_sec = (((time_t)days * 24 + ct->hour) * 60 + ct->min) * 60 + + ct->sec; ts->tv_nsec = ct->nsec; + if (ct_debug) printf(" = %ld.%09ld\n", (long)ts->tv_sec, (long)ts->tv_nsec); return (0);