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
This commit is contained in:
Konstantin Belousov 2014-12-12 09:37:18 +00:00
parent 0f49f14626
commit fe21241ee0

View File

@ -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);