From: Martin Burnicki Date: Fri, 16 Jan 2009 14:53:26 +0000 (+0100) Subject: Bug 1118: Fixed sign extension for 32 bit time_t in caljulian() and prettydate(). X-Git-Tag: NTP_4_2_5P156~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e27f7db5c50bde0eac6d69e654a185f591ece9ad;p=thirdparty%2Fntp.git 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. bk: 49709f66VY4tQgRNU4AaO2JZaiZ44A --- diff --git a/ChangeLog b/ChangeLog index 98c6aa224..89f88bd75 100644 --- 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 * [Bug 992] support interface event change on Linux from Miroslav Lichvar. diff --git a/include/recvbuff.h b/include/recvbuff.h index 769b6c8ab..590bba776 100644 --- a/include/recvbuff.h +++ b/include/recvbuff.h @@ -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 */ diff --git a/libntp/caljulian.c b/libntp/caljulian.c index 7125d0a94..7673061b5 100644 --- a/libntp/caljulian.c +++ b/libntp/caljulian.c @@ -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); } diff --git a/libntp/prettydate.c b/libntp/prettydate.c index 2899ea52d..eb9789bc0 100644 --- a/libntp/prettydate.c +++ b/libntp/prettydate.c @@ -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 diff --git a/ntpd/ntp_timer.c b/ntpd/ntp_timer.c index b28b9caf0..be3bfb051 100644 --- a/ntpd/ntp_timer.c +++ b/ntpd/ntp_timer.c @@ -27,6 +27,10 @@ #include "ntp_syscall.h" #endif /* KERNEL_PLL */ +#ifdef OPENSSL +#include +#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. */