]> git.ipfire.org Git - thirdparty/ntp.git/commitdiff
Bug 1118: Fixed sign extension for 32 bit time_t in caljulian() and prettydate().
authorMartin Burnicki <burnicki@ntp.org>
Fri, 16 Jan 2009 14:53:26 +0000 (15:53 +0100)
committerMartin Burnicki <burnicki@ntp.org>
Fri, 16 Jan 2009 14:53:26 +0000 (15:53 +0100)
Fixed some compiler warnings about missing prototypes.
Fixed some other simple compiler warnings.

bk: 49709f66VY4tQgRNU4AaO2JZaiZ44A

ChangeLog
include/recvbuff.h
libntp/caljulian.c
libntp/prettydate.c
ntpd/ntp_timer.c

index 98c6aa224fce341adaf3fcaa0dcb8916120345d9..89f88bd75d84bfc964c2bf2f1fc53c31ae02f309 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,6 @@
+* [Bug 1118] Fixed sign extension for 32 bit time_t in caljulian() and prettydate().
+  Fixed some compiler warnings about missing prototypes.
+  Fixed some other simple compiler warnings.
 (4.2.5p154) 2009/01/13 Released by Harlan Stenn <stenn@ntp.org>
 * [Bug 992] support interface event change on Linux from
   Miroslav Lichvar.
index 769b6c8ab18664f2245c0909996bf3af01c68c2e..590bba77626067437e9671a7e14c9208b4aa7069 100644 (file)
@@ -93,7 +93,8 @@ extern        void    freerecvbuf (struct recvbuf *);
  *  The buffer is removed from the free list. Make sure
  *  you put it back with freerecvbuf() or 
  */
-extern struct recvbuf *get_free_recv_buffer (void);
+extern struct recvbuf *get_free_recv_buffer (void); /* signal safe - no malloc */
+extern struct recvbuf *get_free_recv_buffer_alloc (void); /* signal unsafe - may malloc */
 
 /*   Add a buffer to the full list
  */
index 7125d0a9462319de3ed91a57ad154b39ed4d054b..7673061b57ce8df9339e16c7e6de0280914711a7 100644 (file)
@@ -60,7 +60,16 @@ caljulian(
         */
        now   = time(NULL);
        tmplo = (u_int32)now;
+#if ( SIZEOF_TIME_T > 4 )
        tmphi = (int32)(now >> 16 >> 16);
+#else
+       /*
+        * Get the correct sign extension in the high part. 
+        * (now >> 32) may not work correctly on every 32 bit 
+        * system, e.g. it yields garbage under Win32/VC6.
+        */
+    tmphi = (int32)(now >> 31);
+#endif
        
        M_ADD(tmphi, tmplo, 0, ((1UL << 31)-1)); /* 32-bit max signed */
        M_ADD(tmphi, tmplo, 0, JAN_1970);
@@ -141,10 +150,10 @@ caljulian(
                 */
                sclday = ntp_day * 7 + 217;
                leaps  = ((n1 == 3) && ((n4 != 24) || (n100 == 3))) ? 1 : 0;
-               if (ntp_day >= JAN + FEB + leaps)
+               if (ntp_day >= (u_long)(JAN + FEB + leaps))
                        sclday += (2 - leaps) * 7;
                ++jt->year;
-               jt->month    = sclday / 214;
+               jt->month    = (u_char)(sclday / 214);
                jt->monthday = (u_char)((sclday % 214) / 7 + 1);
                jt->yearday  = (u_short)(1 + ntp_day);
        }
index 2899ea52d4e39980230c3f1bdef6f6576b6ec808..eb9789bc0338747f785180c6291d2cb6f49d626e 100644 (file)
@@ -57,7 +57,16 @@ ntp2unix_tm(
        int32      folds = 0;
        time_t     t     = time(NULL);
        u_int32    dwlo  = (int32)t; /* might expand for SIZEOF_TIME_T < 4 */
+#if ( SIZEOF_TIME_T > 4 )
        int32      dwhi  = (int32)(t >> 16 >> 16);/* double shift: avoid warnings */
+#else
+       /*
+        * Get the correct sign extension in the high part. 
+        * (now >> 32) may not work correctly on every 32 bit 
+        * system, e.g. it yields garbage under Win32/VC6.
+        */
+    int32              dwhi = (int32)(t >> 31);
+#endif
        
        /* Shift NTP to UN*X epoch, then unfold around currrent time. It's
         * important to use a 32 bit max signed value -- LONG_MAX is 64 bit on
@@ -117,7 +126,7 @@ ntp2unix_tm(
 #   endif /* Microsoft specific */
 
        /* 't' should be a suitable value by now. Just go ahead. */
-       while (!(tm = (*(local ? localtime : gmtime))(&t)))
+       while ( (tm = (*(local ? localtime : gmtime))(&t)) != 0)
                /* seems there are some other pathological implementations of
                ** 'gmtime()' and 'localtime()' somewhere out there. No matter
                ** if we have 32-bit or 64-bit 'time_t', try to fix this by
index b28b9caf0edab4e372db94e8c177443d4053580a..be3bfb0510325033cb1db7ba8e9d4af281177973 100644 (file)
 #include "ntp_syscall.h"
 #endif /* KERNEL_PLL */
 
+#ifdef OPENSSL
+#include <openssl/rand.h>
+#endif /* OPENSSL */
+
 /*
  * These routines provide support for the event timer. The timer is
  * implemented by an interrupt routine which sets a flag once every
@@ -376,7 +380,6 @@ timer(void)
        }
 
 #ifdef OPENSSL
-
        /*
         * Garbage collect expired keys.
         */