From: Harlan Stenn Date: Wed, 25 May 2005 09:01:29 +0000 (-0400) Subject: [Bug 433] Avoid epoch overflow on 32 bit systems X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=40d7090f888b0e799cf127bb2d359c64f4f257ef;p=thirdparty%2Fntp.git [Bug 433] Avoid epoch overflow on 32 bit systems bk: 42943ee9rAKbU8pFL6Qxss_etS5vIQ --- diff --git a/libntp/prettydate.c b/libntp/prettydate.c index ca96426768..55adf64aee 100644 --- a/libntp/prettydate.c +++ b/libntp/prettydate.c @@ -53,11 +53,20 @@ ntp2unix_tm( for (epoch_nr = 0; epoch_nr < MAX_EPOCH_NR; epoch_nr++) { tm = local ? localtime(&t) : gmtime(&t); +#if SIZEOF_TIME_T < 4 +# include "Bletch: sizeof(time_t) < 4!" +#endif + +#if SIZEOF_TIME_T == 4 + /* If 32 bits, then year is 1970-2038, so no sense looking */ + epoch_nr = MAX_EPOCH_NR; +#else /* SIZEOF_TIME_T > 4 */ /* Check that the resulting year is in the correct epoch: */ if (1900 + tm->tm_year > curr_year - 68) break; /* Epoch wraparound: Add 2^32 seconds! */ t += (time_t) 65536 << 16; +#endif /* SIZEOF_TIME_T > 4 */ } return tm; }