From: Dave Hart Date: Mon, 31 Jul 2023 12:41:01 +0000 (+0000) Subject: [Bug 3853] Clean up warnings with modern compilers. X-Git-Tag: NTP_4_2_8P18_RC1~35 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bd8ab0c277f0ee3362c9a7acb63449759d06e7fa;p=thirdparty%2Fntp.git [Bug 3853] Clean up warnings with modern compilers. partial, more to come. bk: 64c7abddN54Is0_FJwBEhz-vsspluw --- diff --git a/ChangeLog b/ChangeLog index dd1cdb3f5..3c6059e79 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,6 @@ --- +* [Bug 3853] Clean up warnings with modern compilers. * [Bug 3852] check-libntp.mf and friends are not triggering rebuilds as intended. * [Bug 3851] Drop pool server when no local address can reach it. diff --git a/include/lib_strbuf.h b/include/lib_strbuf.h index 5ee92d6f8..7c79713c4 100644 --- a/include/lib_strbuf.h +++ b/include/lib_strbuf.h @@ -5,28 +5,33 @@ #define LIB_STRBUF_H #include -#include /* for ZERO() */ +#include /* for zero_mem() */ /* * Sizes of things */ -#define LIB_NUMBUF 16 +#define LIB_NUMBUF 10 #define LIB_BUFLENGTH 128 -typedef char libbufstr[LIB_BUFLENGTH]; -extern libbufstr lib_stringbuf[LIB_NUMBUF]; -extern int lib_nextbuf; -extern int lib_inited; +extern char * lib_stringbuf[LIB_NUMBUF]; +extern int lib_nextbuf; +extern int lib_inited; +extern int ipv4_works; +extern int ipv6_works; +extern void init_lib(void); /* * Macro to get a pointer to the next buffer */ -#define LIB_GETBUF(bufp) \ - do { \ - ZERO(lib_stringbuf[lib_nextbuf]); \ - (bufp) = &lib_stringbuf[lib_nextbuf++][0]; \ - lib_nextbuf %= COUNTOF(lib_stringbuf); \ +#define LIB_GETBUF(bufp) \ + do { \ + if (!lib_inited) { \ + init_lib(); \ + } \ + zero_mem(lib_stringbuf[lib_nextbuf], LIB_BUFLENGTH); \ + (bufp) = lib_stringbuf[lib_nextbuf++]; \ + lib_nextbuf %= COUNTOF(lib_stringbuf); \ } while (FALSE) #endif /* LIB_STRBUF_H */ diff --git a/include/ntp_stdlib.h b/include/ntp_stdlib.h index 446837e3a..b44734cf0 100644 --- a/include/ntp_stdlib.h +++ b/include/ntp_stdlib.h @@ -15,6 +15,7 @@ #include "ntp_net.h" #include "ntp_debug.h" #include "ntp_malloc.h" +#include "lib_strbuf.h" #include "ntp_string.h" #include "ntp_syslog.h" #include "ntp_keyacc.h" diff --git a/include/ntp_tty.h b/include/ntp_tty.h index 6dc48b6c7..56f75c115 100644 --- a/include/ntp_tty.h +++ b/include/ntp_tty.h @@ -100,4 +100,9 @@ extern int ntp_tty_ioctl(int, u_int); # endif #endif +extern int symBaud2numBaud(int symBaud); +# if 0 +extern int numBaud2symBaud(int numBaud); +#endif + #endif /* NTP_TTY_H */ diff --git a/libntp/lib_strbuf.c b/libntp/lib_strbuf.c index 76f70163d..e0c20e122 100644 --- a/libntp/lib_strbuf.c +++ b/libntp/lib_strbuf.c @@ -1,5 +1,5 @@ /* - * lib_strbuf - library string storage + * lib_strbuf.c - init_lib() and library string storage */ #ifdef HAVE_CONFIG_H #include @@ -10,19 +10,17 @@ #include "ntp_fp.h" #include "ntp_stdlib.h" -#include "lib_strbuf.h" - /* * Storage declarations */ -int debug; -libbufstr lib_stringbuf[LIB_NUMBUF]; +static char lib_stringbuf_storage[LIB_NUMBUF * LIB_BUFLENGTH]; +char * lib_stringbuf[LIB_NUMBUF]; int lib_nextbuf; +int lib_inited; int ipv4_works; int ipv6_works; -int lib_inited; - +int debug; /* * initialization routine. Might be needed if the code is ROMized. @@ -30,10 +28,18 @@ int lib_inited; void init_lib(void) { + u_int u; + if (lib_inited) return; ipv4_works = (ISC_R_SUCCESS == isc_net_probeipv4()); ipv6_works = (ISC_R_SUCCESS == isc_net_probeipv6()); init_systime(); + /* avoid -Wrestrict warnings by keeping a pointer to each buffer */ + lib_stringbuf[0] = lib_stringbuf_storage; + for (u = 1; u < COUNTOF(lib_stringbuf); u++) { + lib_stringbuf[u] = lib_stringbuf[u - 1] + LIB_BUFLENGTH; + } + lib_inited = TRUE; } diff --git a/libntp/machines.c b/libntp/machines.c index 7a29ac07e..163abf15c 100644 --- a/libntp/machines.c +++ b/libntp/machines.c @@ -13,17 +13,16 @@ #include "ntp_syslog.h" #include "ntp_stdlib.h" #include "ntp_unixtime.h" -#include "lib_strbuf.h" #include "ntp_debug.h" +#include "ntp_tty.h" #ifdef HAVE_UNISTD_H #include #endif #ifdef SYS_WINNT -int _getch(void); /* Declare the one function rather than include conio.h */ +#include #else - #ifdef SYS_VXWORKS #include "taskLib.h" #include "sysLib.h" @@ -531,3 +530,58 @@ getpass(const char * prompt) return password; } #endif /* SYS_WINNT */ + + +static const int baudTable[][2] = { + {B0, 0}, + {B50, 50}, + {B75, 75}, + {B110, 110}, + {B134, 134}, + {B150, 150}, + {B200, 200}, + {B300, 300}, + {B600, 600}, + {B1200, 1200}, + {B1800, 1800}, + {B2400, 2400}, + {B4800, 4800}, + {B9600, 9600}, + {B19200, 19200}, + {B38400, 38400}, +# ifdef B57600 + {B57600, 57600 }, +# endif +# ifdef B115200 + {B115200, 115200}, +# endif + {-1, -1} +}; + + +int symBaud2numBaud(int symBaud) +{ + int i; + + for (i = 0; baudTable[i][1] >= 0; ++i) { + if (baudTable[i][0] == symBaud) { + break; + } + } + return baudTable[i][1]; +} + + +#if 0 /* unused */ +int numBaud2symBaud(int numBaud) +{ + int i; + + for (i = 0; baudTable[i][1] >= 0; ++i) { + if (baudTable[i][1] == numBaud) { + break; + } + } + return baudTable[i][0]; +} +#endif /* unused fn */ diff --git a/ntpd/ntp_proto.c b/ntpd/ntp_proto.c index b9011d262..82074ca14 100644 --- a/ntpd/ntp_proto.c +++ b/ntpd/ntp_proto.c @@ -4854,7 +4854,7 @@ pool_xmit( do { /* copy_addrinfo_list ai_addr points to a sockaddr_u */ - rmtadr = (sockaddr_u*)(void*)pool->ai->ai_addr; + rmtadr = (sockaddr_u *)(void *)pool->ai->ai_addr; pool->ai = pool->ai->ai_next; /* do not solicit when hopeless [Bug 3845] */ if ( (IS_IPV4(rmtadr) && !nonlocal_v4_addr_up) diff --git a/ntpd/ntp_refclock.c b/ntpd/ntp_refclock.c index a16c980e5..d96a524c8 100644 --- a/ntpd/ntp_refclock.c +++ b/ntpd/ntp_refclock.c @@ -72,8 +72,6 @@ static int refclock_cmpl_fp (const void *, const void *); static int refclock_sample (struct refclockproc *); static int refclock_ioctl(int, u_int); static void refclock_checkburst(struct peer *, struct refclockproc *); -static int symBaud2numBaud(int symBaud); -static int numBaud2symBaud(int numBaud); /* circular buffer functions * @@ -841,9 +839,9 @@ refclock_fdwrite( } else if (nret != len) { nerr = errno; msyslog(LOG_NOTICE, - "%s: %s shortened, fd=%d, wrote %zu of %zu bytes", + "%s: %s shortened, fd=%d, wrote %u of %u bytes", refnumtoa(&peer->srcadr), what, - fd, nret, len); + fd, (u_int)nret, (u_int)len); errno = nerr; } } @@ -1651,7 +1649,7 @@ refclock_pps( * ------------------------------------------------------------------- */ -int/*BOOL*/ +int refclock_ppsaugment( const struct refclock_atom * ap , /* for PPS io */ l_fp * rcvtime , @@ -1826,10 +1824,11 @@ refclock_vformat_lcode( long len; len = vsnprintf(pp->a_lastcode, sizeof(pp->a_lastcode), fmt, va); - if (len <= 0) + if (len <= 0) { len = 0; - else if (len >= sizeof(pp->a_lastcode)) + } else if (len >= sizeof(pp->a_lastcode)) { len = sizeof(pp->a_lastcode) - 1; + } pp->lencode = (u_short)len; pp->a_lastcode[len] = '\0'; @@ -1850,47 +1849,4 @@ refclock_format_lcode( va_end(va); } -static const int baudTable[][2] = { - {B0, 0}, - {B50, 50}, - {B75, 75}, - {B110, 110}, - {B134, 134}, - {B150, 150}, - {B200, 200}, - {B300, 300}, - {B600, 600}, - {B1200, 1200}, - {B1800, 1800}, - {B2400, 2400}, - {B4800, 4800}, - {B9600, 9600}, - {B19200, 19200}, - {B38400, 38400}, -# ifdef B57600 - {B57600, 57600 }, -# endif -# ifdef B115200 - {B115200, 115200}, -# endif - {-1, -1} -}; - - -static int symBaud2numBaud(int symBaud) -{ - int i; - for (i = 0; baudTable[i][1] >= 0; ++i) - if (baudTable[i][0] == symBaud) - break; - return baudTable[i][1]; -} -static int numBaud2symBaud(int numBaud) -{ - int i; - for (i = 0; baudTable[i][1] >= 0; ++i) - if (baudTable[i][1] == numBaud) - break; - return baudTable[i][0]; -} -#endif /* REFCLOCK */ +#endif /* REFCLOCK */ diff --git a/sntp/tests/crypto.c b/sntp/tests/crypto.c index 8ecd74368..e033cfb60 100644 --- a/sntp/tests/crypto.c +++ b/sntp/tests/crypto.c @@ -169,12 +169,6 @@ test_VerifySHA1(void) void test_VerifyCMAC(void) { - const char* PKT_DATA = - "sometestdata" /* Data */ - "\0\0\0\0" /* Key-ID (unused) */ - "\x4e\x0c\xf0\xe2\xc7\x8e\xbb\xbf" /* MAC */ - "\x79\xfc\x87\xc7\x8b\xb7\x4a\x0b"; - const int PKT_LEN = 12; struct key cmac; cmac.next = NULL; diff --git a/tests/libntp/a_md5encrypt.c b/tests/libntp/a_md5encrypt.c index 212ec8313..87e3fa5c7 100644 --- a/tests/libntp/a_md5encrypt.c +++ b/tests/libntp/a_md5encrypt.c @@ -98,15 +98,16 @@ test_IPv6AddressToRefId(void) { } } }; sockaddr_u addr; + ZERO(addr); addr.sa6.sin6_family = AF_INET6; - addr.sa6.sin6_addr = address; #if 0 TEST_ASSERT_EQUAL(expected, addr2refid(&addr)); #else - (void)expected; + UNUSED_LOCAL(expected); + UNUSED_LOCAL(addr); TEST_IGNORE_MESSAGE("Skipping because of big endian problem?"); #endif }