]> git.ipfire.org Git - thirdparty/ntp.git/commitdiff
[Bug 3853] Clean up warnings with modern compilers.
authorDave Hart <hart@ntp.org>
Mon, 31 Jul 2023 12:41:01 +0000 (12:41 +0000)
committerDave Hart <hart@ntp.org>
Mon, 31 Jul 2023 12:41:01 +0000 (12:41 +0000)
           partial, more to come.

bk: 64c7abddN54Is0_FJwBEhz-vsspluw

ChangeLog
include/lib_strbuf.h
include/ntp_stdlib.h
include/ntp_tty.h
libntp/lib_strbuf.c
libntp/machines.c
ntpd/ntp_proto.c
ntpd/ntp_refclock.c
sntp/tests/crypto.c
tests/libntp/a_md5encrypt.c

index dd1cdb3f575cf4eced4aae74134d32cc9772e5a2..3c6059e791a7323e4915322544d423cd25063d7a 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,6 @@
 ---
 
+* [Bug 3853] Clean up warnings with modern compilers. <hart@ntp.org>
 * [Bug 3852] check-libntp.mf and friends are not triggering rebuilds as
              intended. <hart@ntp.org>
 * [Bug 3851] Drop pool server when no local address can reach it.
index 5ee92d6f83417dcd9cd1fcf98ed0c2db4026ed21..7c79713c4aa4bc68f3072ceb6b4727083fbc3bcd 100644 (file)
@@ -5,28 +5,33 @@
 #define LIB_STRBUF_H
 
 #include <ntp_types.h>
-#include <ntp_malloc.h>                        /* for ZERO() */
+#include <ntp_malloc.h>                        /* 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 */
index 446837e3adcb9ae8ca3c8465544dc49a38bbb806..b44734cf05592069cf16f088d7fb820e0d6598e4 100644 (file)
@@ -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"
index 6dc48b6c71f19d6feb5c481570f9306cf82943b1..56f75c115907cf29e7cb3c40e46b39d5790695f1 100644 (file)
@@ -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 */
index 76f70163de981a50490dc404e71ab368975506c2..e0c20e1221e7ce63a41f5354e884663c0d774a80 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * lib_strbuf - library string storage
+ * lib_strbuf.c - init_lib() and library string storage
  */
 #ifdef HAVE_CONFIG_H
 #include <config.h>
 
 #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;
 }
index 7a29ac07ea5fa6ff1f562205e0277050929bea8c..163abf15c6db5b7cc7ac2285bd44d66894a3feb1 100644 (file)
 #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 <unistd.h>
 #endif
 
 #ifdef SYS_WINNT
-int _getch(void);      /* Declare the one function rather than include conio.h */
+#include <conio.h>
 #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 */
index b9011d26218dd2fbe4dcf199d019e0e49542da99..82074ca14510acd1ea77a24f23cb98996e312e0e 100644 (file)
@@ -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)
index a16c980e5b095a90bd848924018852e38af357dc..d96a524c8841dfbb6490f78f5a6468d269e5250d 100644 (file)
@@ -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 */
index 8ecd74368011aab9bc7c201a7320a77cc5f88e90..e033cfb6020950cd3076486b5c2f50a9b54f9610 100644 (file)
@@ -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;
index 212ec8313973c765a5d27d1b3375129ccf275501..87e3fa5c7b3469f5f42c4b984367048b331869c3 100644 (file)
@@ -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
 }