[Git][NTPsec/ntpsec][master] 5 commits: Add missing statics and casts found by clang.

Gary E. Miller gitlab at mg.gitlab.com
Wed Feb 15 21:53:37 UTC 2017


Gary E. Miller pushed to branch master at NTPsec / ntpsec


Commits:
eccb5761 by Gary E. Miller at 2017-02-15T13:21:03-08:00
Add missing statics and casts found by clang.

ntp_proto.c is a mess.  Lots more work to do there...

- - - - -
4772ed88 by Gary E. Miller at 2017-02-15T13:23:48-08:00
Add missing casts and static found by clang.

- - - - -
6e656832 by Gary E. Miller at 2017-02-15T13:50:55-08:00
Add missing externs, statics, casts found by clang.

Even found a real mismatched extern!

- - - - -
6eb98b9b by Gary E. Miller at 2017-02-15T13:52:07-08:00
Added statics and casts found by clang.

- - - - -
18b6689d by Gary E. Miller at 2017-02-15T13:52:29-08:00
Fix statics and cass found by clang.

- - - - -


6 changed files:

- include/ntpd.h
- ntpd/ntp_io.c
- ntpd/ntp_proto.c
- ntpd/ntp_scanner.c
- ntpd/ntp_timer.c
- ntpd/ntpd.c


Changes:

=====================================
include/ntpd.h
=====================================
--- a/include/ntpd.h
+++ b/include/ntpd.h
@@ -100,6 +100,7 @@ typedef struct interface_info {
 
 typedef void	(*interface_receiver_t)	(void *, interface_info_t *);
 
+extern  bool listen_to_virtual_ips;
 extern	void	interface_enumerate	(interface_receiver_t, void *);
 extern	endpt *	getinterface		(sockaddr_u *, uint32_t);
 extern	endpt *	select_peerinterface	(struct peer *, sockaddr_u *,


=====================================
ntpd/ntp_io.c
=====================================
--- a/ntpd/ntp_io.c
+++ b/ntpd/ntp_io.c
@@ -50,7 +50,6 @@
  * #endif
  */
 
-extern int listen_to_virtual_ips;
 
 #ifndef IPTOS_DSCP_EF
 #define IPTOS_DSCP_EF 0xb8


=====================================
ntpd/ntp_proto.c
=====================================
--- a/ntpd/ntp_proto.c
+++ b/ntpd/ntp_proto.c
@@ -44,7 +44,7 @@ typedef struct peer_select_tag {
  * times are in seconds.
  */
 uint8_t	sys_leap;		/* system leap indicator */
-uint8_t	xmt_leap;		/* leap indicator sent in client requests */
+static uint8_t	xmt_leap;		/* leap indicator sent in client requests */
 uint8_t	sys_stratum;		/* system stratum */
 int8_t	sys_precision;		/* local clock precision (log2 s) */
 double	sys_rootdelay;		/* roundtrip delay to primary source */
@@ -84,7 +84,7 @@ static int leap_vote_del;	/* leap consensus for delete */
 keyid_t	sys_private;		/* private value for session seed */
 int	sys_manycastserver;	/* respond to manycast client pkts */
 int	peer_ntpdate;		/* active peers in ntpdate mode */
-int	sys_survivors;		/* truest of the truechimers */
+static int sys_survivors;		/* truest of the truechimers */
 
 /*
  * TOS and multicast mapping stuff
@@ -95,7 +95,7 @@ int	sys_minsane = 1;	/* minimum candidates */
 int	sys_minclock = NTP_MINCLOCK; /* minimum candidates */
 int	sys_maxclock = NTP_MAXCLOCK; /* maximum candidates */
 int	sys_orphan = STRATUM_UNSPEC + 1; /* orphan stratum */
-int	sys_orphwait = NTP_ORPHWAIT; /* orphan wait */
+static int sys_orphwait = NTP_ORPHWAIT; /* orphan wait */
 
 /*
  * Statistics counters - first the good, then the bad
@@ -192,7 +192,7 @@ is_control_packet(
    is achieved by making sure we use calloc() everywhere in
    parse_packet(), and then comparing to NULL before dereferencing.
 */
-void
+static void
 free_packet(
 	struct parsed_pkt *pkt
 	)
@@ -208,9 +208,9 @@ free_packet(
 		pkt->extensions = NULL;
 	}
 	free(pkt);
-};
+}
 
-struct parsed_pkt*
+static struct parsed_pkt*
 parse_packet(
 	struct recvbuf const* rbufp
 	)
@@ -277,7 +277,7 @@ parse_packet(
 			ext_count++;
 		}
 
-		pkt->num_extensions = ext_count;
+		pkt->num_extensions = (unsigned int)ext_count;
 		pkt->extensions = calloc(ext_count, sizeof (struct exten));
 		if(pkt->extensions == NULL) { goto fail; }
 
@@ -473,8 +473,8 @@ handle_fastxmit(
 	   (pkt->keyid_present &&
 	    authdecrypt(pkt->keyid,
 			(uint32_t*)rbufp->recv_space.X_recv_buffer,
-			rbufp->recv_length - (pkt->mac_len + 4),
-			pkt->mac_len + 4))) {
+			(int)(rbufp->recv_length - (pkt->mac_len + 4)),
+			(int)(pkt->mac_len + 4)))) {
 		xkeyid = pkt->keyid;
 	} else {
 		xkeyid = 0;
@@ -783,9 +783,9 @@ receive(
 			   have to do this screwy buffer-length
 			   arithmetic in order to call it. */
 			!authdecrypt(pkt->keyid,
-				     (uint32_t*)rbufp->recv_space.X_recv_buffer,
-				     rbufp->recv_length - (pkt->mac_len + 4),
-				     pkt->mac_len + 4)) {
+				 (uint32_t*)rbufp->recv_space.X_recv_buffer,
+				 (int)(rbufp->recv_length - (pkt->mac_len + 4)),
+				 (int)(pkt->mac_len + 4))) {
 
 			sys_badauth++;
 			if(peer != NULL) {
@@ -1253,7 +1253,7 @@ void
 peer_clear(
 	struct peer *peer,		/* peer structure */
 	const char *ident,		/* tally lights */
-	const bool initializing
+	const bool initializing1
 	)
 {
 	uint8_t	u;
@@ -1291,10 +1291,10 @@ peer_clear(
 	 * avoid implosion.
 	 */
 	peer->nextdate = peer->update = peer->outdate = current_time;
-	if (initializing) {
-		peer->nextdate += peer_associations;
+	if (initializing1) {
+		peer->nextdate += (unsigned long)peer_associations;
 	} else if (MODE_PASSIVE == peer->hmode) {
-		peer->nextdate += ntp_minpkt;
+		peer->nextdate += (unsigned long)ntp_minpkt;
 	} else {
 	    /*
 	     * Randomizing the next poll interval used to be done with
@@ -1478,7 +1478,7 @@ clock_filter(
 	 * packets.
 	 */
 	if (peer->filter_epoch[k] <= peer->epoch) {
-#if DEBUG
+#if defined(DEBUG) && DEBUG
 	if (debug > 1)
 		printf("clock_filter: old sample %lu\n", current_time -
 		    peer->filter_epoch[k]);
@@ -1563,9 +1563,10 @@ clock_select(void)
 	nlist = 1;
 	for (peer = peer_list; peer != NULL; peer = peer->p_link)
 		nlist++;
-	endpoint_size = ALIGNED_SIZE(nlist * 2 * sizeof(*endpoint));
-	peers_size = ALIGNED_SIZE(nlist * sizeof(*peers));
-	indx_size = ALIGNED_SIZE(nlist * 2 * sizeof(*indx));
+	endpoint_size = ALIGNED_SIZE(
+                             (unsigned long)(nlist * 2 * sizeof(*endpoint)));
+	peers_size = ALIGNED_SIZE((unsigned long)(nlist * sizeof(*peers)));
+	indx_size = ALIGNED_SIZE((unsigned long)(nlist * 2 * sizeof(*indx)));
 	octets = endpoint_size + peers_size + indx_size;
 	endpoint = erealloc(endpoint, octets);
 	peers = INC_ALIGNED_PTR(endpoint, endpoint_size);
@@ -2147,8 +2148,8 @@ peer_xmit(
 		get_systime(&xmt_tx);
 		peer->org = xmt_tx;
 		xpkt.xmt = htonl_fp(xmt_tx);
-		peer->t21_bytes = sendlen;
-		sendpkt(&peer->srcadr, peer->dstadr, &xpkt, sendlen);
+		peer->t21_bytes = (int)sendlen;
+		sendpkt(&peer->srcadr, peer->dstadr, &xpkt, (int)sendlen);
 		peer->sent++;
 		peer->outcount++;
 		peer->throttle += (1 << peer->minpoll) - 2;


=====================================
ntpd/ntp_scanner.c
=====================================
--- a/ntpd/ntp_scanner.c
+++ b/ntpd/ntp_scanner.c
@@ -36,7 +36,7 @@
  */
 
 #define MAX_LEXEME (1024 + 1)	/* The maximum size of a lexeme */
-char yytext[MAX_LEXEME];	/* Buffer for storing the input text/lexeme */
+static char yytext[MAX_LEXEME];	/* Buffer for storing the input text/lexeme */
 uint32_t conf_file_sum;		/* Simple sum of characters read */
 
 static struct FILE_INFO * lex_stack = NULL;
@@ -51,7 +51,7 @@ static struct FILE_INFO * lex_stack = NULL;
 /* SCANNER GLOBAL VARIABLES 
  * ------------------------
  */
-const char special_chars[] = "{}(),;|=";
+static const char special_chars[] = "{}(),;|=";
 
 
 /* FUNCTIONS
@@ -75,7 +75,7 @@ keyword(
 	size_t i;
 	const char *text;
 
-	i = token - LOWEST_KEYWORD_ID;
+	i = (size_t)(token - LOWEST_KEYWORD_ID);
 
 	if (i < COUNTOF(keyword_text))
 		text = keyword_text[i];
@@ -167,13 +167,13 @@ lex_getch(
 		ch = stream->backch;
 		stream->backch = EOF;
 		if (stream->fpi)
-			conf_file_sum += ch;
+			conf_file_sum += (unsigned int)ch;
 	} else if (stream->fpi) {
 		/* fetch next 7-bit ASCII char (or EOF) from file */
 		while ((ch = fgetc(stream->fpi)) != EOF && ch > SCHAR_MAX)
 			stream->curpos.ncol++;
 		if (EOF != ch) {
-			conf_file_sum += ch;
+			conf_file_sum += (unsigned int)ch;
 			stream->curpos.ncol++;
 		}
 	} else {
@@ -229,7 +229,7 @@ lex_ungetch(
 	/* keep for later reference and update checksum */
 	stream->backch = (uint8_t)ch;
 	if (stream->fpi)
-		conf_file_sum -= stream->backch;
+		conf_file_sum -= (unsigned int)stream->backch;
 
 	/* update position */
 	if (stream->backch == '\n') {
@@ -820,7 +820,8 @@ yylex(void)
 		} else if (is_integer(yytext)) {
 			yylval_was_set = true;
 			errno = 0;
-			if ((yylval.Integer = strtol(yytext, NULL, 10)) == 0
+			yylval.Integer = (int)strtol(yytext, NULL, 10);
+			if (yylval.Integer == 0
 			    && ((errno == EINVAL) || (errno == ERANGE))) {
 				msyslog(LOG_ERR, 
 					"Integer cannot be represented: %s",
@@ -838,7 +839,7 @@ yylex(void)
 		} else if (is_u_int(yytext)) {
 			yylval_was_set = true;
 			if ('0' == yytext[0] &&
-			    'x' == tolower((unsigned long)yytext[1]))
+			    'x' == tolower((int)yytext[1]))
 				converted = sscanf(&yytext[2], "%x",
 						   &yylval.U_int);
 			else


=====================================
ntpd/ntp_timer.c
=====================================
--- a/ntpd/ntp_timer.c
+++ b/ntpd/ntp_timer.c
@@ -72,7 +72,7 @@ typedef struct itimerspec intervaltimer;
 typedef struct itimerval intervaltimer;
 #define	itv_frac	tv_usec
 #endif
-intervaltimer itimer;
+static intervaltimer itimer;
 
 void	set_timer_or_die(const intervaltimer *);
 
@@ -299,7 +299,7 @@ timer(void)
 	 */
 	if (interface_interval && interface_timer <= current_time) {
 		timer_interfacetimeout(current_time +
-		    interface_interval);
+		    (unsigned long)interface_interval);
 		DPRINTF(2, ("timer: interface update\n"));
 		interface_update(NULL, NULL);
 	}
@@ -511,10 +511,10 @@ check_leapsec(
 			report_event(EVNT_LEAP, NULL, NULL);
 			lsprox  = LSPROX_NOWARN;
 			leapsec = LSPROX_NOWARN;
-			sys_tai = lsdata.tai_offs;
+			sys_tai = (u_int)lsdata.tai_offs;
 		} else {
 			lsprox  = lsdata.proximity;
-			sys_tai = lsdata.tai_offs;
+			sys_tai = (u_int)lsdata.tai_offs;
 		}
 	}
 


=====================================
ntpd/ntpd.c
=====================================
--- a/ntpd/ntpd.c
+++ b/ntpd/ntpd.c
@@ -36,7 +36,8 @@
 void catchQuit (int sig);
 static volatile int signo = 0;
 /* In an ideal world, 'finish_safe()' would declared as noreturn... */
-static	void		finish_safe	(int);
+static	void	finish_safe	(int)
+			__attribute__	((__noreturn__));
 
 #ifdef SIGDANGER
 # include <ulimit.h>
@@ -44,7 +45,7 @@ static	void		finish_safe	(int);
 
 #if defined(HAVE_DNS_SD_H) && defined(ENABLE_MDNS_REGISTRATION)
 # include <dns_sd.h>
-DNSServiceRef mdns;
+static DNSServiceRef mdns;
 #endif
 
 static void check_minsane(void);
@@ -71,7 +72,7 @@ static const char *driftfile, *pidfile;
  * attempt fails, then try again once per minute for up to 5
  * times. After all, we may be starting before mDNS.
  */
-bool mdnsreg = false;
+static bool mdnsreg = false;
 int mdnstries = 5;
 #endif  /* ENABLE_MDNS_REGISTRATION */
 
@@ -103,11 +104,12 @@ static	void	lessdebug	(int);
 static	void	no_debug	(int);
 # endif	/* !DEBUG */
 
-int	saved_argc;
-char **	saved_argv;
+static int	saved_argc;
+static char **	saved_argv;
 
 int		ntpdmain		(int, char **);
-static void	mainloop		(void);
+static void	mainloop		(void)
+			__attribute__	((__noreturn__));
 static void	set_process_priority	(void);
 static void	assertion_failed	(const char *, int,
 					 isc_assertiontype_t,
@@ -115,7 +117,8 @@ static void	assertion_failed	(const char *, int,
 			__attribute__	((__noreturn__));
 static void	library_fatal_error	(const char *, int,
 					 const char *, va_list)
-					ISC_FORMAT_PRINTF(3, 0);
+					ISC_FORMAT_PRINTF(3, 0)
+			__attribute__	((__noreturn__));
 static void	library_unexpected_error(const char *, int,
 					 const char *, va_list)
 					ISC_FORMAT_PRINTF(3, 0);
@@ -340,7 +343,7 @@ parse_cmdline_opts(
 			size_t	len;
 
 			*group++ = '\0'; /* get rid of the ':' */
-			len = group - user;
+			len = (size_t)(group - user);
 			group = estrdup(group);
 			user = erealloc(user, len);
 		}
@@ -351,7 +354,7 @@ parse_cmdline_opts(
 		    long val = atol(argv[ntp_optind]);
 
 		    if (val >= 0)
-			    interface_interval = val;
+			    interface_interval = (int)val;
 		    else {
 			    fprintf(stderr,
 				    "command line interface update interval %ld must not be negative\n",
@@ -367,7 +370,7 @@ parse_cmdline_opts(
 		printf("%s\n", ntpd_version());
 		exit(0);
 	    case 'w':
-		wait_sync = strtod(ntp_optarg, NULL);
+		wait_sync = (long)strtod(ntp_optarg, NULL);
 		break;
 	    case 'x':
 		/* defer */
@@ -530,7 +533,7 @@ ntpdmain(
 		cp += strlen(cp);
 
 		for (int i = 0; i < saved_argc ; ++i) {
-			snprintf(cp, sizeof(buf) - (cp - buf),
+			snprintf(cp, sizeof(buf) - (size_t)(cp - buf),
 				" %s", saved_argv[i]);
 			cp += strlen(cp);
 		}
@@ -701,14 +704,14 @@ ntpdmain(
 		break;
 	    case 't':
 		{
-		    u_long tkey = (int)atol(ntp_optarg);
+		    u_long tkey = (u_long)atol(ntp_optarg);
 		    if (tkey == 0 || tkey > NTP_MAXKEY) {
 			msyslog(LOG_ERR,
 				"command line trusted key %s is invalid",
 				ntp_optarg);
 			exit(0);
 		    } else {
-			authtrust(tkey, true);
+			authtrust((keyid_t)tkey, true);
 		    }
 	        }
 		break;
@@ -1008,7 +1011,7 @@ static void catchHUP(int sig)
 static int
 wait_child_sync_if(
 	int	pipe_read_fd,
-	long	wait_sync
+	long	wait_sync1
 	)
 {
 	int	rc;
@@ -1019,12 +1022,12 @@ wait_child_sync_if(
 	fd_set	readset;
 	struct timespec wtimeout;
 
-	if (0 == wait_sync)
+	if (0 == wait_sync1)
 		return 0;
 
 	/* waitsync_fd_to_close used solely by child */
 	close(waitsync_fd_to_close);
-	wait_end_time = time(NULL) + wait_sync;
+	wait_end_time = time(NULL) + wait_sync1;
 	do {
 		cur_time = time(NULL);
 		wait_rem = (wait_end_time > cur_time)
@@ -1066,7 +1069,7 @@ wait_child_sync_if(
 	} while (wait_rem > 0);
 
 	fprintf(stderr, "%s: -w/--wait-sync %ld timed out.\n",
-		progname, wait_sync);
+		progname, wait_sync1);
 	return ETIMEDOUT;
 }
 # endif	/* HAVE_WORKING_FORK */
@@ -1106,7 +1109,7 @@ static void check_minsane()
     else if (servers == 4)
         msyslog(LOG_ERR, "Found 4 servers, suggest minsane of 2");
 
-};
+}
 
 
 /*
@@ -1158,7 +1161,7 @@ library_fatal_error(
  * library_unexpected_error - Handle non fatal errors from our libraries.
  */
 # define MAX_UNEXPECTED_ERRORS 100
-int unexpected_error_cnt = 0;
+static int unexpected_error_cnt = 0;
 static void
 library_unexpected_error(
 	const char *file,



View it on GitLab: https://gitlab.com/NTPsec/ntpsec/compare/68f134ea69b12de82747360549e8df3e09d96fc9...18b6689d83652397f940899e1ef699e08ecb689e
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ntpsec.org/pipermail/vc/attachments/20170215/e0f59f1c/attachment.html>


More information about the vc mailing list