[Git][NTPsec/ntpsec][master] 5 commits: Add two trivial missing size_t casts.

Gary E. Miller gitlab at mg.gitlab.com
Sat Mar 11 02:37:57 UTC 2017


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


Commits:
82e9fc97 by Gary E. Miller at 2017-03-10T16:54:24-08:00
Add two trivial missing size_t casts.

- - - - -
0dc17c52 by Gary E. Miller at 2017-03-10T17:13:28-08:00
More missing size_t

- - - - -
868974a5 by Gary E. Miller at 2017-03-10T17:13:53-08:00
Add missing s-ze_t, and a size_t to an int.

- - - - -
ad565585 by Gary E. Miller at 2017-03-10T17:53:50-08:00
More trivial zie_t fixups.

- - - - -
a9b821e4 by Gary E. Miller at 2017-03-10T18:37:02-08:00
ntp_control.c: A bunch of size_t related changes.

This file is a mess, but I'll move forward on size_t elsewhere.

- - - - -


11 changed files:

- libntp/dolfptoa.c
- libntp/msyslog.c
- libntp/statestr.c
- libntp/strl_obsd.c
- ntpd/ntp_control.c
- ntpd/refclock_gpsd.c
- ntpd/refclock_hpgps.c
- ntpd/refclock_trimble.c
- ntpd/refclock_truetime.c
- ntpd/refclock_zyfer.c
- wafhelpers/configure.py


Changes:

=====================================
libntp/dolfptoa.c
=====================================
--- a/libntp/dolfptoa.c
+++ b/libntp/dolfptoa.c
@@ -67,8 +67,8 @@ dolfptoa(
 		dec   += 3;
 		cpdec += 3;
 	}
-	if ((size_t)dec > sizeof(cbuf) - (cpend - cbuf))
-		dec = sizeof(cbuf) - (cpend - cbuf);
+	if ((size_t)dec > sizeof(cbuf) - (size_t)(cpend - cbuf))
+		dec = sizeof(cbuf) - (size_t)(cpend - cbuf);
 	
 	/*
 	 * If there's a fraction to deal with, do so.


=====================================
libntp/msyslog.c
=====================================
--- a/libntp/msyslog.c
+++ b/libntp/msyslog.c
@@ -287,7 +287,7 @@ msnprintf(
 	)
 {
 	va_list	ap;
-	size_t	rc;
+	int	rc;
 
 	va_start(ap, fmt);
 	rc = mvsnprintf(buf, bufsiz, fmt, ap);


=====================================
libntp/statestr.c
=====================================
--- a/libntp/statestr.c
+++ b/libntp/statestr.c
@@ -327,7 +327,7 @@ decode_bitflags(
 
 	for (b = 0; b < tab_ct; b++) {
 		if (tab[b].code & bits) {
-			rc = snprintf(pch, (lim - pch), "%s%s", sep,
+			rc = snprintf(pch, (size_t)(lim - pch), "%s%s", sep,
 				      tab[b].string);
 			if (rc < 0)
 				goto toosmall;
@@ -433,9 +433,9 @@ statustoa(
 			 getevents(CTL_PEER_NEVNT(st)));
 		if (CTL_PEER_EVENT(st) != EVNT_UNSPEC) {
 			cc = cb + strlen(cb);
-			snprintf(cc, LIB_BUFLENGTH - (cc - cb), ", %s",
-				 getcode(CTL_PEER_EVENT(st),
-					 peer_codes));
+			snprintf(cc, (size_t)(LIB_BUFLENGTH - (cc - cb)),
+                                 ", %s",
+				 getcode(CTL_PEER_EVENT(st), peer_codes));
 		}
 		break;
 	


=====================================
libntp/strl_obsd.c
=====================================
--- a/libntp/strl_obsd.c
+++ b/libntp/strl_obsd.c
@@ -46,7 +46,7 @@ strlcpy(char *dst, const char *src, size_t siz)
 			;
 	}
 
-	return(s - src - 1);	/* count does not include NUL */
+	return((size_t)(s - src - 1));	/* count does not include NUL */
 }
 #endif				/* + */
 
@@ -73,7 +73,7 @@ strlcat(char *dst, const char *src, size_t siz)
 	/* Find the end of dst and adjust bytes left but don't go past end */
 	while (n-- != 0 && *d != '\0')
 		d++;
-	dlen = d - dst;
+	dlen = (size_t)(d - dst);
 	n = siz - dlen;
 
 	if (n == 0)
@@ -87,6 +87,6 @@ strlcat(char *dst, const char *src, size_t siz)
 	}
 	*d = '\0';
 
-	return(dlen + (s - src));	/* count does not include NUL */
+	return(dlen + (size_t)(s - src));	/* count does not include NUL */
 }
 #endif				/* + */


=====================================
ntpd/ntp_control.c
=====================================
--- a/ntpd/ntp_control.c
+++ b/ntpd/ntp_control.c
@@ -218,7 +218,7 @@ static const struct ctl_proc control_codes[] = {
 #define CS_MRU_OLDEST_AGE	95
 #define	CS_LEAPSMEARINTV	96
 #define	CS_LEAPSMEAROFFS	97
-#define	CS_TICK                 98
+#define	CS_TICK                 98U
 #define	CS_MAXCODE		CS_TICK
 
 /*
@@ -291,7 +291,7 @@ static const struct ctl_proc control_codes[] = {
 #define	CC_FUDGEVAL2	10
 #define	CC_FLAGS	11
 #define	CC_DEVICE	12
-#define	CC_VARLIST	13
+#define	CC_VARLIST	13U
 #define	CC_MAXCODE	CC_VARLIST
 
 /*
@@ -815,7 +815,7 @@ process_control(
 	/* round up proper len to a 8 octet boundary */
 
 	properlen = (properlen + 7) & ~7;
-	maclen = rbufp->recv_length - properlen;
+	maclen = rbufp->recv_length - (size_t)properlen;
 	if ((rbufp->recv_length & 3) == 0 &&
 	    maclen >= MIN_MAC_LEN && maclen <= MAX_MAC_LEN) {
 		res_authenticate = true;
@@ -967,7 +967,7 @@ ctl_flushpkt(
 	 * which means Python mode 6 clients might actually see the trailing
 	 * garbage.
 	 */
-	memset(rpkt.data + sendlen, '\0', sizeof(rpkt.data) - sendlen);
+	memset(rpkt.data + sendlen, '\0', sizeof(rpkt.data) - (size_t)sendlen);
 	
 	/*
 	 * Pad to a multiple of 32 bits
@@ -1161,7 +1161,8 @@ ctl_putdblf(
 		*cp++ = *cq++;
 	*cp++ = '=';
 	NTP_INSIST((size_t)(cp - buffer) < sizeof(buffer));
-	snprintf(cp, sizeof(buffer) - (cp - buffer), use_f ? "%.*f" : "%.*g",
+	snprintf(cp, sizeof(buffer) - (size_t)(cp - buffer),
+                 use_f ? "%.*f" : "%.*g",
 	    precision, d);
 	cp += strlen(cp);
 	ctl_putdata(buffer, (unsigned)(cp - buffer), false);
@@ -1187,7 +1188,7 @@ ctl_putuint(
 
 	*cp++ = '=';
 	NTP_INSIST((cp - buffer) < (int)sizeof(buffer));
-	snprintf(cp, sizeof(buffer) - (cp - buffer), "%lu", uval);
+	snprintf(cp, sizeof(buffer) - (size_t)(cp - buffer), "%lu", uval);
 	cp += strlen(cp);
 	ctl_putdata(buffer, (unsigned)( cp - buffer ), false);
 }
@@ -1221,7 +1222,7 @@ ctl_putfs(
 	if (NULL ==  tm)
 		return;
 	NTP_INSIST((cp - buffer) < (int)sizeof(buffer));
-	snprintf(cp, sizeof(buffer) - (cp - buffer),
+	snprintf(cp, sizeof(buffer) - (size_t)(cp - buffer),
 		 "%04d%02d%02d%02d%02d", tm->tm_year + 1900,
 		 tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, tm->tm_min);
 	cp += strlen(cp);
@@ -1250,7 +1251,7 @@ ctl_puthex(
 
 	*cp++ = '=';
 	NTP_INSIST((cp - buffer) < (int)sizeof(buffer));
-	snprintf(cp, sizeof(buffer) - (cp - buffer), "0x%lx", uval);
+	snprintf(cp, sizeof(buffer) - (size_t)(cp - buffer), "0x%lx", uval);
 	cp += strlen(cp);
 	ctl_putdata(buffer,(unsigned)( cp - buffer ), false);
 }
@@ -1276,7 +1277,7 @@ ctl_putint(
 
 	*cp++ = '=';
 	NTP_INSIST((cp - buffer) < (int)sizeof(buffer));
-	snprintf(cp, sizeof(buffer) - (cp - buffer), "%ld", ival);
+	snprintf(cp, sizeof(buffer) - (size_t)(cp - buffer), "%ld", ival);
 	cp += strlen(cp);
 	ctl_putdata(buffer, (unsigned)( cp - buffer ), false);
 }
@@ -1302,7 +1303,7 @@ ctl_putts(
 
 	*cp++ = '=';
 	NTP_INSIST((size_t)(cp - buffer) < sizeof(buffer));
-	snprintf(cp, sizeof(buffer) - (cp - buffer), "0x%08x.%08x",
+	snprintf(cp, sizeof(buffer) - (size_t)(cp - buffer), "0x%08x.%08x",
 		 (u_int)lfpuint(*ts), (u_int)lfpfrac(*ts));
 	cp += strlen(cp);
 	ctl_putdata(buffer, (unsigned)( cp - buffer ), false);
@@ -1334,7 +1335,7 @@ ctl_putadr(
 	else
 		cq = socktoa(addr);
 	NTP_INSIST((cp - buffer) < (int)sizeof(buffer));
-	snprintf(cp, sizeof(buffer) - (cp - buffer), "%s", cq);
+	snprintf(cp, sizeof(buffer) - (size_t)(cp - buffer), "%s", cq);
 	cp += strlen(cp);
 	ctl_putdata(buffer, (unsigned)(cp - buffer), false);
 }
@@ -1405,7 +1406,7 @@ ctl_putarray(
 			i = NTP_SHIFT;
 		i--;
 		NTP_INSIST((cp - buffer) < (int)sizeof(buffer));
-		snprintf(cp, sizeof(buffer) - (cp - buffer),
+		snprintf(cp, sizeof(buffer) - (size_t)(cp - buffer),
 			 " %.2f", arr[i] * 1e3);
 		cp += strlen(cp);
 	} while (i != start);
@@ -1558,7 +1559,7 @@ ctl_putsys(
 		char *buffp, *buffend;
 		bool firstVarName;
 		const char *ss1;
-		int len;
+		size_t len;
 		const struct ctl_var *k;
 
 		buffp = buf;
@@ -1592,14 +1593,14 @@ ctl_putsys(
 			if (NULL == ss1)
 				len = strlen(k->text);
 			else
-				len = ss1 - k->text;
+				len = (size_t)(ss1 - k->text);
 			if (buffp + len + 1 >= buffend)
 				break;
 			if (firstVarName) {
 				*buffp++ = ',';
 				firstVarName = false;
 			}
-			memcpy(buffp, k->text,(unsigned)len);
+			memcpy(buffp, k->text, len);
 			buffp += len;
 		}
 		if (buffp + 2 >= buffend)
@@ -2052,7 +2053,7 @@ ctl_putpeer(
 	char *s;
 	char *t;
 	char *be;
-	int i;
+	size_t sz;
 	const struct ctl_var *k;
 
 	switch (id) {
@@ -2271,13 +2272,13 @@ ctl_putpeer(
 		for (k = peer_var; !(EOV & k->flags); k++) {
 			if (PADDING & k->flags)
 				continue;
-			i = strlen(k->text);
-			if (s + i + 1 >= be)
+			sz = strlen(k->text);
+			if (s + sz + 1 >= be)
 				break;
 			if (s != t)
 				*s++ = ',';
-			memcpy(s, k->text, i);
-			s += i;
+			memcpy(s, k->text, sz);
+			s += sz;
 		}
 		if (s + 2 < be) {
 			*s++ = '"';
@@ -2340,7 +2341,7 @@ ctl_putclock(
 	char buf[CTL_MAX_DATA_LEN];
 	char *s, *t, *be;
 	const char *ss;
-	int i;
+	size_t sz;
 	const struct ctl_var *k;
 
 	switch (id) {
@@ -2444,14 +2445,14 @@ ctl_putclock(
 			if (PADDING & k->flags)
 				continue;
 
-			i = strlen(k->text);
-			if (s + i + 1 >= be)
+			sz = strlen(k->text);
+			if (s + sz + 1 >= be)
 				break;
 
 			if (s != t)
 				*s++ = ',';
-			memcpy(s, k->text, i);
-			s += i;
+			memcpy(s, k->text, sz);
+			s += sz;
 		}
 
 		for (k = pcs->kv_list; k && !(EOV & k->flags); k++) {
@@ -2464,14 +2465,14 @@ ctl_putclock(
 
 			while (*ss && *ss != '=')
 				ss++;
-			i = ss - k->text;
-			if (s + i + 1 >= be)
+			sz = (size_t)(ss - k->text);
+			if (s + sz + 1 >= be)
 				break;
 
 			if (s != t)
 				*s++ = ',';
-			memcpy(s, k->text, (unsigned)i);
-			s += i;
+			memcpy(s, k->text, sz);
+			s += sz;
 			*s = '\0';
 		}
 		if (s + 2 >= be)
@@ -2952,7 +2953,7 @@ static void configure(
 	}
 
 	/* Initialize the remote config buffer */
-	data_count = reqend - reqpt;
+	data_count = (size_t)(reqend - reqpt);
 
 	if (data_count > sizeof(remote_config.buffer) - 2) {
 		snprintf(remote_config.err_msg,


=====================================
ntpd/refclock_gpsd.c
=====================================
--- a/ntpd/refclock_gpsd.c
+++ b/ntpd/refclock_gpsd.c
@@ -827,7 +827,7 @@ timer_primary(
 			DPRINTF(2, ("%s: timer livecheck: '%s'\n",
 				    up->logname, s_req_version));
 			log_data(peer, "send", s_req_version, rlen);
-			rc = write(pp->io.fd, s_req_version, (int)rlen);
+			rc = write(pp->io.fd, s_req_version, rlen);
 			(void)rc;
 		} else if (-1 != up->fdt) {
 			gpsd_test_socket(peer);
@@ -1443,7 +1443,8 @@ process_version(
 	clockprocT * const pp = peer->procptr;
 	gpsd_unitT * const up = (gpsd_unitT *)pp->unitptr;
 
-	int len;
+	size_t len;
+	ssize_t ret;
 	char * buf;
 	const char *revision;
 	const char *release;
@@ -1505,8 +1506,9 @@ process_version(
 		 s_req_watch[up->pf_toff != 0], up->device);
 	buf = up->buffer;
 	len = strlen(buf);
-	log_data(peer, "send", buf, (size_t)len);
-	if (len != write(pp->io.fd, buf, len) && (syslogok(pp, up))) {
+	log_data(peer, "send", buf, len);
+	ret = write(pp->io.fd, buf, len);
+	if ( (ret < 0 || (size_t)ret != len) && (syslogok(pp, up))) {
 		/* Note: if the server fails to read our request, the
 		 * resulting data timeout will take care of the
 		 * connection!


=====================================
ntpd/refclock_hpgps.c
=====================================
--- a/ntpd/refclock_hpgps.c
+++ b/ntpd/refclock_hpgps.c
@@ -303,7 +303,7 @@ hpgps_receive(
 	if (up->linecnt-- > 0) {
 		if ((int)(pp->lencode + 2) <= (SMAX - (up->lastptr - up->statscrn))) {
 			*up->lastptr++ = '\n';
-			memcpy(up->lastptr, pp->a_lastcode, pp->lencode);
+			memcpy(up->lastptr, pp->a_lastcode, (size_t)pp->lencode);
 			up->lastptr += pp->lencode;
 		}
 		if (up->linecnt == 0) 


=====================================
ntpd/refclock_trimble.c
=====================================
--- a/ntpd/refclock_trimble.c
+++ b/ntpd/refclock_trimble.c
@@ -1118,7 +1118,7 @@ praecis_parse (
 	)
 {
 	static char buf[100];
-	static int p = 0;
+	static size_t p = 0;
 	struct refclockproc *pp;
 
 	pp = peer->procptr;


=====================================
ntpd/refclock_truetime.c
=====================================
--- a/ntpd/refclock_truetime.c
+++ b/ntpd/refclock_truetime.c
@@ -580,10 +580,12 @@ true_send(
 
 	pp = peer->procptr;
 	if (!(pp->sloppyclockflag & CLK_FLAG1)) {
-		ssize_t len = strlen(cmd);
+                ssize_t ret;
+		size_t len = strlen(cmd);
 
 		true_debug(peer, "Send '%s'\n", cmd);
-		if (write(pp->io.fd, cmd, len) != len)
+		ret = write(pp->io.fd, cmd, len);
+		if (ret < 0 || (size_t)ret != len)
 			refclock_report(peer, CEVNT_FAULT);
 		else
 			pp->polls++;


=====================================
ntpd/refclock_zyfer.c
=====================================
--- a/ntpd/refclock_zyfer.c
+++ b/ntpd/refclock_zyfer.c
@@ -237,7 +237,7 @@ zyfer_receive(
 			return;
 	} else {
 		memcpy(pp->a_lastcode + pp->lencode, p, rbufp->recv_length);
-		pp->lencode += rbufp->recv_length;
+		pp->lencode += (int)rbufp->recv_length;
 		pp->a_lastcode[pp->lencode] = '\0';
 	}
 


=====================================
wafhelpers/configure.py
=====================================
--- a/wafhelpers/configure.py
+++ b/wafhelpers/configure.py
@@ -246,6 +246,7 @@ def cmd_configure(ctx, config):
         "-O1",
         "-Wall",
         "-Wextra",
+        "-Wsign-conversion",
         "-Wstrict-prototypes",
         "-Wunused",
         ]



View it on GitLab: https://gitlab.com/NTPsec/ntpsec/compare/7c48838ce0479b58101c02d41b18844d097e2f2d...a9b821e4f645091598f322074c34ddf7f54c5436
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ntpsec.org/pipermail/vc/attachments/20170311/88ed59a1/attachment.html>


More information about the vc mailing list