]> git.ipfire.org Git - thirdparty/ntp.git/commitdiff
Code cleanup. Harlan Stenn.
authorHarlan Stenn <stenn@ntp.org>
Sun, 19 Jul 2015 05:37:40 +0000 (05:37 +0000)
committerHarlan Stenn <stenn@ntp.org>
Sun, 19 Jul 2015 05:37:40 +0000 (05:37 +0000)
bk: 55ab37a4SshLPY5-w06Nko5GAhgTqw

24 files changed:
ChangeLog
include/Makefile.am
include/rc_cmdlength.h [new file with mode: 0644]
libntp/audio.c
libntp/icom.c
libntp/ntp_worker.c
ntpd/ntp_config.c
ntpd/ntp_control.c
ntpd/ntp_crypto.c
ntpd/ntp_monitor.c
ntpd/ntp_peer.c
ntpd/ntp_proto.c
ntpd/ntp_restrict.c
ntpd/rc_cmdlength.c
ntpd/refclock_arc.c
ntpd/refclock_chu.c
ntpd/refclock_nmea.c
ntpd/refclock_parse.c
ntpd/refclock_wwv.c
ntpq/ntpq.c
sntp/networking.c
tests/sec-2853/run-sec-2853.c
tests/sec-2853/sec-2853.c
util/ntp-keygen.c

index a689abab69ddb63a57c7ca0cb143dbf3cbd8e764..186f5d432c7607c45b20c206989511865f92a31e 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -46,6 +46,7 @@
 * br-flock: --enable-local-libevent.  Harlan Stenn.
 * scripts/lib/NTP/Util.pm: stratum output is version-dependent.  Harlan Stenn.
 * Get rid of the NTP_ prefix on our assertion macros.  Harlan Stenn.
+* Code cleanup.  Harlan Stenn.
 ---
 (4.2.8p3) 2015/06/29 Released by Harlan Stenn <stenn@ntp.org>
 
index 8b063c3c66f5c95b274d8cfdde211cc8a7bb2da3..f032c97e792d7eb60bf0b4a21c8c1b20fcaa25f8 100644 (file)
@@ -62,6 +62,7 @@ noinst_HEADERS =      \
        ntpsim.h        \
        parse.h         \
        parse_conf.h    \
+       rc_cmdlength.h  \
        recvbuff.h      \
        refclock_atom.h \
        refidsmear.h    \
diff --git a/include/rc_cmdlength.h b/include/rc_cmdlength.h
new file mode 100644 (file)
index 0000000..8794757
--- /dev/null
@@ -0,0 +1,2 @@
+
+extern size_t remoteconfig_cmdlength( const char *src_buf, const char *src_end );
index 6f2262c991f3609f62f49cd856a75fbcab39984b..726dfa94d8190ef314bf23a15e83d49f6565d884 100644 (file)
@@ -377,7 +377,9 @@ audio_gain(
 #ifdef PCM_STYLE_SOUND
        int l, r;
 
-       rval = 0;
+# ifdef GCC
+       rval = 0;               /* GCC thinks rval is used uninitialized */
+# endif
 
        r = l = 100 * gain / 255;       /* Normalize to 0-100 */
 # ifdef DEBUG
@@ -392,10 +394,11 @@ audio_gain(
        if (cf_agc[0] != '\0')
                rval = ioctl(ctl_fd, agc, &l);
        else
-               if (2 == port)
-                       rval = ioctl(ctl_fd, SOUND_MIXER_WRITE_LINE, &l);
-               else
-                       rval = ioctl(ctl_fd, SOUND_MIXER_WRITE_MIC, &l);
+               rval = ioctl(ctl_fd
+                           , (2 == port)
+                               ? SOUND_MIXER_WRITE_LINE
+                               : SOUND_MIXER_WRITE_MIC
+                           , &l);
        if (-1 == rval) {
                printf("audio_gain: agc write: %s\n", strerror(errno));
                return rval;
index 80700114255ef2347f950c65437b6e09dcc6a6c7..1185e69dbd85b3cedeac37f17cf9a42a35e5fc0e 100644 (file)
@@ -6,14 +6,16 @@
  * frequency. All other parameters must be manually set before use.
  */
 #include <config.h>
-#include "icom.h"
+#include <ntp_stdlib.h>
+#include <ntp_tty.h>
+#include <l_stdlib.h>
+#include <icom.h>
+
 #include <unistd.h>
 #include <stdio.h>
 #include <fcntl.h>
 #include <errno.h>
 
-#include "ntp_tty.h"
-#include "l_stdlib.h"
 
 #ifdef SYS_WINNT
 #undef write   /* ports/winnt/include/config.h: #define write _write */
@@ -60,9 +62,14 @@ static void doublefreq               (double, u_char *, int);
 
 /*
  * icom_freq(fd, ident, freq) - load radio frequency
+ *
+ * returns:
+ *  0 (ok)
+ * -1 (error)
+ *  1 (short write to device)
  */
 int
-icom_freq(                     /* returns 0 (ok), EIO (error) */
+icom_freq(
        int fd,                 /* file descriptor */
        int ident,              /* ICOM radio identifier */
        double freq             /* frequency (MHz) */
@@ -71,6 +78,7 @@ icom_freq(                    /* returns 0 (ok), EIO (error) */
        u_char cmd[] = {PAD, PR, PR, 0, TX, V_SFREQ, 0, 0, 0, 0, FI,
            FI};
        int temp;
+       int rc;
 
        cmd[3] = (char)ident;
        if (ident == IC735)
@@ -78,9 +86,17 @@ icom_freq(                   /* returns 0 (ok), EIO (error) */
        else
                temp = 5;
        doublefreq(freq * 1e6, &cmd[6], temp);
-       temp = write(fd, cmd, temp + 7);
+       rc = write(fd, cmd, temp + 7);
+       if (rc != -1) {
+               msyslog(LOG_ERR, "icom_freq: write() failed: %m");
+               return -1;
+       } else if (rc != temp + 7) {
+               msyslog(LOG_ERR, "icom_freq: only wrote %d of %d bytes.",
+                       rc, temp+7);
+               return 1;
+       }
 
-       return (0);
+       return 0;
 }
 
 
index bb1cb87e44a049d20dbbfc530beac27b80f60e38..32970da0d124068f1b1e6913f62e7b4f7d401f9a 100644 (file)
@@ -278,7 +278,7 @@ blocking_child_common(
                req = receive_blocking_req_internal(c);
                if (NULL == req) {
                        say_bye = TRUE;
-                       break;
+                       continue;
                }
 
                DEBUG_REQUIRE(BLOCKING_REQ_MAGIC == req->magic_sig);
index 0ea5d455dbc74ac600eb859afdbdd84006527ac9..041c80705b043275c89025b81b0edf048851f369 100644 (file)
@@ -1825,7 +1825,9 @@ config_auth(
 
        /* Crypto Command */
 #ifdef AUTOKEY
+# ifdef GCC
        item = -1;      /* quiet warning */
+# endif
        my_val = HEAD_PFIFO(ptree->auth.crypto_cmd_list);
        for (; my_val != NULL; my_val = my_val->link) {
                switch (my_val->attr) {
@@ -1978,7 +1980,9 @@ config_tos(
        int             item;
        double          val;
 
+#ifdef GCC
        item = -1;      /* quiet warning */
+#endif
        tos = HEAD_PFIFO(ptree->orphan_cmds);
        for (; tos != NULL; tos = tos->link) {
                val = tos->value.d;
@@ -2661,7 +2665,9 @@ config_tinker(
        attr_val *      tinker;
        int             item;
 
+#ifdef GCC
        item = -1;      /* quiet warning */
+#endif
        tinker = HEAD_PFIFO(ptree->tinker);
        for (; tinker != NULL; tinker = tinker->link) {
                switch (tinker->attr) {
@@ -2775,12 +2781,14 @@ config_nic_rules(
                switch (curr_node->match_class) {
 
                default:
+#ifdef GCC
                        /*
                         * this assignment quiets a gcc "may be used
                         * uninitialized" warning and is here for no
                         * other reason.
                         */
                        match_type = MATCH_ALL;
+#endif
                        INSIST(FALSE);
                        break;
 
@@ -2833,12 +2841,14 @@ config_nic_rules(
                switch (curr_node->action) {
 
                default:
+#ifdef GCC
                        /*
                         * this assignment quiets a gcc "may be used
                         * uninitialized" warning and is here for no
                         * other reason.
                         */
                        action = ACTION_LISTEN;
+#endif
                        INSIST(FALSE);
                        break;
 
index 2ed209bdf89d7b1c0cfaabc094986865548c1391..bee2b26d32d23d47a2275d72f3ecd43a97d2f0de 100644 (file)
 #include "ntp_leapsec.h"
 #include "ntp_md5.h"   /* provides OpenSSL digest API */
 #include "lib_strbuf.h"
+#include <rc_cmdlength.h>
 #ifdef KERNEL_PLL
 # include "ntp_syscall.h"
 #endif
 
-extern size_t remoteconfig_cmdlength( const char *src_buf, const char *src_end );
 
 /*
  * Structure to hold request procedure information
@@ -2928,7 +2928,6 @@ ctl_getitem(
         * Look for a first character match on the tag.  If we find
         * one, see if it is a full match.
         */
-       v = var_list;
        cp = reqpt;
        for (v = var_list; !(EOV & v->flags); v++) {
                if (!(PADDING & v->flags) && *cp == *(v->text)) {
index cd767cc15d493e0ccebae1ce6fae39ad9e08bfe2..e9cd6c2036f323c9abba43128bd1d423a7c335e4 100644 (file)
@@ -1770,7 +1770,7 @@ crypto_send(
                if (j * 4 < siglen)
                        ep->pkt[i + j++] = 0;
                memcpy(&ep->pkt[i], vp->sig, siglen);
-               i += j;
+               /* i += j; */   /* We don't use i after this */
        }
        opcode = ntohl(ep->opcode);
        ep->opcode = htonl((opcode & 0xffff0000) | len); 
index 44676b2b6b1759bf6f7c295f0edb2bc032a20fc1..a07a1aaef1962ac99eb135b2602f5c87f2c029e5 100644 (file)
@@ -325,6 +325,8 @@ ntp_monitor(
        int             leak;           /* new headway */
        int             limit;          /* average threshold */
 
+       REQUIRE(rbufp != NULL);
+
        if (mon_enabled == MON_OFF)
                return ~(RES_LIMITED | RES_KOD) & flags;
 
@@ -466,6 +468,8 @@ ntp_monitor(
                }
        }
 
+       INSIST(mon != NULL);
+
        /*
         * Got one, initialize it
         */
index 41dbae561f3238bd4421de9783eaec97915266fe..448441715e5c0262a4c377edceb1827fe8e32d28 100644 (file)
@@ -817,6 +817,7 @@ newpeer(
        if (peer_free_count == 0)
                getmorepeermem();
        UNLINK_HEAD_SLIST(peer, peer_free, p_link);
+       INSIST(peer != NULL);
        peer_free_count--;
        peer_associations++;
        if (FLAG_PREEMPT & flags)
index 40624066746f5456da9da0f939286f927c8f46ba..d76bbbd9dcb25e96e89bf6a7e6712a928b8e8b59 100644 (file)
@@ -1540,7 +1540,9 @@ process_packet(
        sys_processed++;
        peer->processed++;
        p_del = FPTOD(NTOHS_FP(pkt->rootdelay));
-       p_offset = 0;
+#ifdef GCC
+       p_offset = 0;           /* quiet bogus uninitialized value warning */
+#endif
        p_disp = FPTOD(NTOHS_FP(pkt->rootdisp));
        NTOHL_FP(&pkt->reftime, &p_reftime);
        NTOHL_FP(&pkt->org, &p_org);
index dee705e8837c7fdfa0a252815c6b4c2096a8ff09..9cc9248979ac4c5b27cfc5ef6be4eae08524ed9d 100644 (file)
@@ -503,9 +503,13 @@ hack_restrict(
        }
 
        ZERO(match);
+
+#if 0
        /* silence VC9 potentially uninit warnings */
+       // HMS: let's use a compiler-specific "enable" for this.
        res = NULL;
        v6 = 0;
+#endif
 
        if (IS_IPV4(resaddr)) {
                v6 = 0;
index 2807d2acd73e7b78d982a77ee0442814077bbdc0..922312e62a7bafcc55030c7089b519a1c63e0ff9 100644 (file)
@@ -1,4 +1,5 @@
 #include <config.h>
+#include <rc_cmdlength.h>
 
 #if HAVE_UNISTD_H
 # include <unistd.h>
index e5d4cb44086c661f3f0afc84772a45fb328d6b63..7daae8d3a03ab02cec67572baae82d84ba049a76 100644 (file)
@@ -657,7 +657,7 @@ arc_start(
                return 0;
        }
        close(temp_fd);
-       temp_fd = -1;
+       temp_fd = -1;           /* not used after this, at *this* time. */
 
 #ifndef SYS_WINNT
        if (-1 == fcntl(fd, F_SETFL, 0)) /* clear the descriptor flags */
index 6b1ae5554adf0df74fe0abe9649be875626eca4e..1f02a1c1f4a7504af9e1aa6ce60c1cbf162af80c 100644 (file)
@@ -1194,7 +1194,7 @@ chu_a(
         * only if the maximum distance is at least MINSYNC.
         */
        up->syndist = k = 0;
-       val = -16;
+       // val = -16;
        for (i = -1; i < 2; i++) {
                temp = up->cbuf[i + 4] & 0xf;
                if (i >= 0)
index 126b53026a9e9b7d5a1f5b36c397f58b128bc7f6..b1ea2946b620c712eef7c619cbb0b8233f4458bb 100644 (file)
@@ -810,9 +810,10 @@ nmea_receive(
        ZERO(tofs);
        ZERO(date);
        ZERO(gpsw);
-       sentence = 0;
-       rc_date = 0;
-       rc_time = 0;
+       sentence = 0;   // Should never be needed.
+       rc_date = 0;    // Should never be needed.
+       rc_time = 0;    // Should never be needed.
+
        /* 
         * Read the timecode and timestamp, then initialise field
         * processing. The <CR><LF> at the NMEA line end is translated
index 147a462231dd8def5cd6dbdb58be6484a950f726..8e905957367711bdafe779d61893a098a3a26f06 100644 (file)
@@ -2587,6 +2587,9 @@ parsestate(
                        i++;
                }
                t = ap(buffer, size, t, ")");
+               /* t is unused here, but if we don't track it and
+                * need it later, that's a bug waiting to happen.
+                */
        }
        return buffer;
 }
index 79c0afd5bcfb3fb06f9b339ba594d4555a850a18..2736cfa32fd71980ece738a9a1ab4d6ba2e96d8d 100644 (file)
@@ -2241,6 +2241,7 @@ wwv_tsec(
                temp = carry(&up->decvec[HR]);
        if (temp == 0)
                temp = carry(&up->decvec[HR + 1]);
+       // XXX: Does temp have an expected value here?
 
        /*
         * Decode the current minute and day. Set leap day if the
@@ -2271,7 +2272,7 @@ wwv_tsec(
        if (minute != 1440)
                return;
 
-       minute = 0;
+       // minute = 0;
        while (carry(&up->decvec[HR]) != 0); /* advance to minute 0 */
        while (carry(&up->decvec[HR + 1]) != 0);
        day++;
@@ -2280,6 +2281,7 @@ wwv_tsec(
                temp = carry(&up->decvec[DA + 1]);
        if (temp == 0)
                temp = carry(&up->decvec[DA + 2]);
+       // XXX: Is there an expected value of temp here?
 
        /*
         * Roll the year if this the first day and propagate carries
@@ -2288,7 +2290,7 @@ wwv_tsec(
        if (day != (isleap ? 365 : 366))
                return;
 
-       day = 1;
+       // day = 1;
        while (carry(&up->decvec[DA]) != 1); /* advance to day 1 */
        while (carry(&up->decvec[DA + 1]) != 0);
        while (carry(&up->decvec[DA + 2]) != 0);
index af5f6815c4f834a58096d760e7f79f09b1cbdc20..fa7d59339e72947e1c1b58a0f51f821b033bbd20 100644 (file)
@@ -3206,7 +3206,6 @@ tstflags(
        register const char *sep;
 
        sep = "";
-       i = 0;
        s = cp = circ_buf[nextcb];
        if (++nextcb >= NUMCB)
                nextcb = 0;
index bef7352d3a63b4579fc4d57e0a46b5fe35eac180..ddd45efe3cb5a1e856f443db0f119661949848a9 100644 (file)
@@ -113,7 +113,7 @@ process_pkt (
        l_fp            sent_xmt;
        l_fp            resp_org;
 
-       key_id = 0;
+       // key_id = 0;
        pkt_key = NULL;
        is_authentic = (HAVE_OPT(AUTHENTICATION)) ? 0 : -1;
 
index c8771bf2022e0f5bba9a3095164634f82c5ae612..66f0c34a02249b970676e7d1957f90dca853742e 100644 (file)
@@ -47,8 +47,8 @@ int main(int argc, char *argv[])
   progname = argv[0];
   Unity.TestFile = "sec-2853.c";
   UnityBegin("sec-2853.c");
-  RUN_TEST(test_main, 8);
-  RUN_TEST(test_main, 8);
+  RUN_TEST(test_main, 10);
+  RUN_TEST(test_main, 10);
 
   return (UnityEnd());
 }
index 6499fdf1f85ac24bee1eed38bc531a2cdf512795..49589d28363317e336c3909abb891d5461fa86dc 100644 (file)
@@ -1,5 +1,7 @@
 #include <config.h>
 
+#include <rc_cmdlength.h>
+
 #include "unity.h"
 
 void setUp(void);
@@ -10,8 +12,6 @@ int basic_good( void );
 int embedded_nul( void );
 int trailing_space( void );
 
-extern size_t remoteconfig_cmdlength(const char *, const char *);
-
 static int verbose = 1;        // if not 0, also print results if test passed
 static int exit_on_err = 0;    // if not 0, exit if test failed
 
index 494bedb19d24750f65a94998194e46cfeb14f3fe..86d040ddeea2e6997ec74bb10d32763da137912f 100644 (file)
@@ -355,8 +355,8 @@ main(
        fstamp = (u_int)(epoch + JAN_1970);
 
        optct = ntpOptionProcess(&ntp_keygenOptions, argc, argv);
-       argc -= optct;
-       argv += optct;
+       argc -= optct;  // Just in case we care later.
+       argv += optct;  // Just in case we care later.
 
 #ifdef OPENSSL
        if (SSLeay() == SSLEAY_VERSION_NUMBER)