From a8611821d75c4de4831f482c1746bf756a601a8c Mon Sep 17 00:00:00 2001 From: Thomas Gellekum Date: Mon, 8 Jan 1996 08:45:11 +0000 Subject: [PATCH] Fix leap year calculations in parse_to_unixtime() --- usr.sbin/xntpd/parse/parse.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/usr.sbin/xntpd/parse/parse.c b/usr.sbin/xntpd/parse/parse.c index 713d3e6ace6c..d283b662f880 100644 --- a/usr.sbin/xntpd/parse/parse.c +++ b/usr.sbin/xntpd/parse/parse.c @@ -605,7 +605,9 @@ parse_iodone(parseio) /* * convert a struct clock to UTC since Jan, 1st 1970 0:00 (the UNIX EPOCH) */ -#define dysize(x) ((x) % 4 ? 365 : ((x % 400) ? 365 :366)) +#define dysize(x) (((x) % 4) ? 365 : \ + (((x) % 100) ? : 366 \ + (((x) % 400) ? 365 : 366))) time_t parse_to_unixtime(clock, cvtrtc) @@ -649,8 +651,8 @@ parse_to_unixtime(clock, cvtrtc) return -1; /* bad month */ } /* adjust leap year */ - if (clock->month >= 3 && dysize(clock->year) == 366) - t++; + if (clock->month < 3 && dysize(clock->year) == 366) + t--; for (i = 1; i < clock->month; i++) {