]> git.ipfire.org Git - thirdparty/ntp.git/commitdiff
[Bug 433] Avoid epoch overflow on 32 bit systems
authorHarlan Stenn <stenn@ntp.org>
Wed, 25 May 2005 09:01:29 +0000 (05:01 -0400)
committerHarlan Stenn <stenn@ntp.org>
Wed, 25 May 2005 09:01:29 +0000 (05:01 -0400)
bk: 42943ee9rAKbU8pFL6Qxss_etS5vIQ

libntp/prettydate.c

index ca96426768a78eb584915cff25fe66deca50e0b3..55adf64aeeb25f226ab5d7eb74d41b95252bb8f5 100644 (file)
@@ -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;
 }