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
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=275727

View File

@ -133,7 +133,6 @@ print_ct(struct clocktime *ct)
int int
clock_ct_to_ts(struct clocktime *ct, struct timespec *ts) clock_ct_to_ts(struct clocktime *ct, struct timespec *ts)
{ {
time_t secs;
int i, year, days; int i, year, days;
year = ct->year; year = ct->year;
@ -167,11 +166,10 @@ clock_ct_to_ts(struct clocktime *ct, struct timespec *ts)
days += days_in_month(year, i); days += days_in_month(year, i);
days += (ct->day - 1); days += (ct->day - 1);
/* Add hours, minutes, seconds. */ ts->tv_sec = (((time_t)days * 24 + ct->hour) * 60 + ct->min) * 60 +
secs = ((days * 24 + ct->hour) * 60 + ct->min) * 60 + ct->sec; ct->sec;
ts->tv_sec = secs;
ts->tv_nsec = ct->nsec; ts->tv_nsec = ct->nsec;
if (ct_debug) if (ct_debug)
printf(" = %ld.%09ld\n", (long)ts->tv_sec, (long)ts->tv_nsec); printf(" = %ld.%09ld\n", (long)ts->tv_sec, (long)ts->tv_nsec);
return (0); return (0);