From: Harlan Stenn Date: Sun, 19 Jul 2015 05:37:40 +0000 (+0000) Subject: Code cleanup. Harlan Stenn. X-Git-Tag: NTP_4_3_61~2^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c469ec3d3ed39f34b7d83af3e723ca46fba4af5c;p=thirdparty%2Fntp.git Code cleanup. Harlan Stenn. bk: 55ab37a4SshLPY5-w06Nko5GAhgTqw --- diff --git a/ChangeLog b/ChangeLog index a689abab6..186f5d432 100644 --- 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 diff --git a/include/Makefile.am b/include/Makefile.am index 8b063c3c6..f032c97e7 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -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 index 000000000..87947573d --- /dev/null +++ b/include/rc_cmdlength.h @@ -0,0 +1,2 @@ + +extern size_t remoteconfig_cmdlength( const char *src_buf, const char *src_end ); diff --git a/libntp/audio.c b/libntp/audio.c index 6f2262c99..726dfa94d 100644 --- a/libntp/audio.c +++ b/libntp/audio.c @@ -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; diff --git a/libntp/icom.c b/libntp/icom.c index 807001142..1185e69db 100644 --- a/libntp/icom.c +++ b/libntp/icom.c @@ -6,14 +6,16 @@ * frequency. All other parameters must be manually set before use. */ #include -#include "icom.h" +#include +#include +#include +#include + #include #include #include #include -#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; } diff --git a/libntp/ntp_worker.c b/libntp/ntp_worker.c index bb1cb87e4..32970da0d 100644 --- a/libntp/ntp_worker.c +++ b/libntp/ntp_worker.c @@ -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); diff --git a/ntpd/ntp_config.c b/ntpd/ntp_config.c index 0ea5d455d..041c80705 100644 --- a/ntpd/ntp_config.c +++ b/ntpd/ntp_config.c @@ -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; diff --git a/ntpd/ntp_control.c b/ntpd/ntp_control.c index 2ed209bdf..bee2b26d3 100644 --- a/ntpd/ntp_control.c +++ b/ntpd/ntp_control.c @@ -28,11 +28,11 @@ #include "ntp_leapsec.h" #include "ntp_md5.h" /* provides OpenSSL digest API */ #include "lib_strbuf.h" +#include #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)) { diff --git a/ntpd/ntp_crypto.c b/ntpd/ntp_crypto.c index cd767cc15..e9cd6c203 100644 --- a/ntpd/ntp_crypto.c +++ b/ntpd/ntp_crypto.c @@ -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); diff --git a/ntpd/ntp_monitor.c b/ntpd/ntp_monitor.c index 44676b2b6..a07a1aaef 100644 --- a/ntpd/ntp_monitor.c +++ b/ntpd/ntp_monitor.c @@ -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 */ diff --git a/ntpd/ntp_peer.c b/ntpd/ntp_peer.c index 41dbae561..448441715 100644 --- a/ntpd/ntp_peer.c +++ b/ntpd/ntp_peer.c @@ -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) diff --git a/ntpd/ntp_proto.c b/ntpd/ntp_proto.c index 406240667..d76bbbd9d 100644 --- a/ntpd/ntp_proto.c +++ b/ntpd/ntp_proto.c @@ -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); diff --git a/ntpd/ntp_restrict.c b/ntpd/ntp_restrict.c index dee705e88..9cc924897 100644 --- a/ntpd/ntp_restrict.c +++ b/ntpd/ntp_restrict.c @@ -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; diff --git a/ntpd/rc_cmdlength.c b/ntpd/rc_cmdlength.c index 2807d2acd..922312e62 100644 --- a/ntpd/rc_cmdlength.c +++ b/ntpd/rc_cmdlength.c @@ -1,4 +1,5 @@ #include +#include #if HAVE_UNISTD_H # include diff --git a/ntpd/refclock_arc.c b/ntpd/refclock_arc.c index e5d4cb440..7daae8d3a 100644 --- a/ntpd/refclock_arc.c +++ b/ntpd/refclock_arc.c @@ -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 */ diff --git a/ntpd/refclock_chu.c b/ntpd/refclock_chu.c index 6b1ae5554..1f02a1c1f 100644 --- a/ntpd/refclock_chu.c +++ b/ntpd/refclock_chu.c @@ -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) diff --git a/ntpd/refclock_nmea.c b/ntpd/refclock_nmea.c index 126b53026..b1ea2946b 100644 --- a/ntpd/refclock_nmea.c +++ b/ntpd/refclock_nmea.c @@ -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 at the NMEA line end is translated diff --git a/ntpd/refclock_parse.c b/ntpd/refclock_parse.c index 147a46223..8e9059573 100644 --- a/ntpd/refclock_parse.c +++ b/ntpd/refclock_parse.c @@ -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; } diff --git a/ntpd/refclock_wwv.c b/ntpd/refclock_wwv.c index 79c0afd5b..2736cfa32 100644 --- a/ntpd/refclock_wwv.c +++ b/ntpd/refclock_wwv.c @@ -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); diff --git a/ntpq/ntpq.c b/ntpq/ntpq.c index af5f6815c..fa7d59339 100644 --- a/ntpq/ntpq.c +++ b/ntpq/ntpq.c @@ -3206,7 +3206,6 @@ tstflags( register const char *sep; sep = ""; - i = 0; s = cp = circ_buf[nextcb]; if (++nextcb >= NUMCB) nextcb = 0; diff --git a/sntp/networking.c b/sntp/networking.c index bef7352d3..ddd45efe3 100644 --- a/sntp/networking.c +++ b/sntp/networking.c @@ -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; diff --git a/tests/sec-2853/run-sec-2853.c b/tests/sec-2853/run-sec-2853.c index c8771bf20..66f0c34a0 100644 --- a/tests/sec-2853/run-sec-2853.c +++ b/tests/sec-2853/run-sec-2853.c @@ -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()); } diff --git a/tests/sec-2853/sec-2853.c b/tests/sec-2853/sec-2853.c index 6499fdf1f..49589d283 100644 --- a/tests/sec-2853/sec-2853.c +++ b/tests/sec-2853/sec-2853.c @@ -1,5 +1,7 @@ #include +#include + #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 diff --git a/util/ntp-keygen.c b/util/ntp-keygen.c index 494bedb19..86d040dde 100644 --- a/util/ntp-keygen.c +++ b/util/ntp-keygen.c @@ -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)