[Git][NTPsec/ntpsec][master] 7 commits: -Wsign-conversion is only for debug

Gary E. Miller gitlab at mg.gitlab.com
Sat Mar 11 03:52:55 UTC 2017


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


Commits:
91549e0b by Gary E. Miller at 2017-03-10T19:08:37-08:00
-Wsign-conversion is only for debug

- - - - -
4664a0be by Gary E. Miller at 2017-03-10T19:15:51-08:00
test/macencrypt: 2 missing size_t casts.

- - - - -
760eb6e7 by Gary E. Miller at 2017-03-10T19:28:08-08:00
refclock_jupiter: add two missing (size_t)

- - - - -
fcefd011 by Gary E. Miller at 2017-03-10T19:33:04-08:00
refclock_oncore: two size_t fixes.

- - - - -
a4ca4d1b by Gary E. Miller at 2017-03-10T19:40:06-08:00
refclock_nmea: add missing size_t casts.

- - - - -
dc8cee35 by Gary E. Miller at 2017-03-10T19:43:27-08:00
refclock_jupiter: add missing ssize_t cast.

- - - - -
9c8b6fb9 by Gary E. Miller at 2017-03-10T19:52:08-08:00
refclock_generic: add a bunch of missing casts.

- - - - -


6 changed files:

- ntpd/refclock_generic.c
- ntpd/refclock_jupiter.c
- ntpd/refclock_nmea.c
- ntpd/refclock_oncore.c
- tests/libntp/macencrypt.c
- wafhelpers/configure.py


Changes:

=====================================
ntpd/refclock_generic.c
=====================================
--- a/ntpd/refclock_generic.c
+++ b/ntpd/refclock_generic.c
@@ -1630,7 +1630,8 @@ mkreadable(
 				}
 				else
 				{
-					snprintf(buffer, blen, "\\x%02x", *src++);
+					snprintf(buffer, (size_t)blen,
+                                                 "\\x%02x", *src++);
 					blen   -= 4;
 					buffer += 4;
 				}
@@ -2018,7 +2019,7 @@ ap(char *buffer, size_t len, char *pos, const char *fmt, ...)
 {
 	va_list va;
 	int l;
-	size_t rem = len - (pos - buffer);
+	size_t rem = len - (size_t)(pos - buffer);
 
 	if (rem == 0)
 		return pos;
@@ -2093,8 +2094,9 @@ parsestate(
 		if (flagstrings[i].bit & lstate)
 		{
 			if (s != t)
-				t = ap(buffer, size, t, "; ");
-			t = ap(buffer, size, t, "%s", flagstrings[i].name);
+				t = ap(buffer, (size_t)size, t, "; ");
+			t = ap(buffer, (size_t)size, t, "%s",
+                               flagstrings[i].name);
 		}
 		i++;
 	}
@@ -2102,9 +2104,9 @@ parsestate(
 	if (lstate & (PARSEB_S_LEAP|PARSEB_S_CALLBIT|PARSEB_S_PPS|PARSEB_S_POSITION))
 	{
 		if (s != t)
-			t = ap(buffer, size, t, "; ");
+			t = ap(buffer, (size_t)size, t, "; ");
 
-		t = ap(buffer, size, t, "(");
+		t = ap(buffer, (size_t)size, t, "(");
 
 		s = t;
 
@@ -2115,15 +2117,15 @@ parsestate(
 			{
 				if (t != s)
 				{
-					t = ap(buffer, size, t, "; ");
+					t = ap(buffer, (size_t)size, t, "; ");
 				}
 
-				t = ap(buffer, size, t, "%s",
+				t = ap(buffer, (size_t)size, t, "%s",
 				    sflagstrings[i].name);
 			}
 			i++;
 		}
-		ap(buffer, size, t, ")");
+		ap(buffer, (size_t)size, t, ")");
 	}
 	return buffer;
 }
@@ -2165,8 +2167,9 @@ parsestatus(
 		if (flagstrings[i].bit & lstate)
 		{
 			if (t != buffer)
-				t = ap(buffer, size, t, "; ");
-			t = ap(buffer, size, t, "%s", flagstrings[i].name);
+				t = ap(buffer, (size_t)size, t, "; ");
+			t = ap(buffer, (size_t)size, t, "%s",
+                               flagstrings[i].name);
 		}
 		i++;
 	}
@@ -3749,17 +3752,22 @@ mk_utcinfo(
 		tm = gmtime_r( &t_ls, &tmbuf );
 		if (tm == NULL)  // gmtime_r() failed
 		{
-			snprintf( t, size, "** (gmtime_r() failed in mk_utcinfo())" );
+			snprintf( t, (size_t)size,
+                                 "** (gmtime_r() failed in mk_utcinfo())" );
 			return;
 		}
 
-		n += snprintf( t, size, "UTC offset transition from %is to %is due to leap second %s",
-				dtls, dtlsf, ( dtls < dtlsf ) ? "insertion" : "deletion" );
-		n += snprintf( t + n, size - n, " at UTC midnight at the end of %04i-%02i-%02i",
-				tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday );
+		n += snprintf( t, (size_t)size,
+                  "UTC offset transition from %is to %is due to leap second %s",
+		  dtls, dtlsf, ( dtls < dtlsf ) ? "insertion" : "deletion" );
+		n += snprintf(t + n, (size_t)(size - n),
+                              " at UTC midnight at the end of %04i-%02i-%02i",
+			      tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday);
 	}
 	else
-		snprintf( t, size, "UTC offset parameter: %is, no leap second announced.\n", dtls );
+		snprintf( t, (size_t)size,
+                    "UTC offset parameter: %is, no leap second announced.\n",
+                    dtls );
 
 }
 
@@ -4261,7 +4269,7 @@ poll_dpoll(
 	const char *ps = ((poll_info_t *)parse->parse_type->cl_data)->string;
 	long ct = ((poll_info_t *)parse->parse_type->cl_data)->count;
 
-	rtc = write(parse->generic->io.fd, ps, ct);
+	rtc = write(parse->generic->io.fd, ps, (size_t)ct);
 	if (rtc < 0)
 	{
 		ERR(ERR_BADIO)


=====================================
ntpd/refclock_jupiter.c
=====================================
--- a/ntpd/refclock_jupiter.c
+++ b/ntpd/refclock_jupiter.c
@@ -770,7 +770,7 @@ jupiter_receive(struct recvbuf *rbufp)
 
 	/* Append to input buffer */
 	memcpy((uint8_t *)instance->sbuf + instance->ssize, bp, bpcnt);
-	instance->ssize += bpcnt;
+	instance->ssize += (ssize_t)bpcnt;
 
 	/* While there's at least a header and we parse an intact message */
 	while (instance->ssize > (int)sizeof(*hp) && (cc = jupiter_recv(instance)) > 0) {
@@ -929,7 +929,8 @@ jupiter_receive(struct recvbuf *rbufp)
 			fprintf(stderr, "jupiter_recv: negative ssize!\n");
 			abort();
 		} else if (instance->ssize > 0)
-			memcpy(instance->sbuf, (uint8_t *)instance->sbuf + cc, instance->ssize);
+			memcpy(instance->sbuf, (uint8_t *)instance->sbuf + cc,
+                               (size_t) instance->ssize);
 	}
 }
 
@@ -1312,7 +1313,7 @@ jupiter_recv(struct instance *instance)
 		*/
 		/* Shuffle data to front of input buffer */
 		if (n > 0)
-			memcpy(sp, bp, n);
+			memcpy(sp, bp, (size_t)n);
 		size = n;
 		instance->ssize = size;
 		if (size < cc || hp->sync != JUPITER_SYNC)


=====================================
ntpd/refclock_nmea.c
=====================================
--- a/ntpd/refclock_nmea.c
+++ b/ntpd/refclock_nmea.c
@@ -558,7 +558,8 @@ nmea_control(
 	/* Light up the PPSAPI interface if not yet attempted. */
 	if ((CLK_FLAG1 & pp->sloppyclockflag) && !up->ppsapi_tried) {
 		up->ppsapi_tried = true;
-		devlen = snprintf(device, sizeof(device), PPSDEV, unit);
+                /* FIXME: snprintf() can return negative on error */
+		devlen = (size_t)snprintf(device, sizeof(device), PPSDEV, unit);
 		if (devlen < sizeof(device)) {
 		    up->ppsapi_fd = open(peer->ppspath ? peer->ppspath : device,
 					 PPSOPENMODE, S_IRUSR | S_IWUSR);
@@ -1007,7 +1008,7 @@ nmea_receive(
 		checkres = -1;
 
 	if (checkres != -1) {
-		save_ltc(pp, rd_lastcode, rd_lencode);
+		save_ltc(pp, rd_lastcode, (size_t)rd_lencode);
 		refclock_report(peer, checkres);
 		return;
 	}
@@ -1044,7 +1045,7 @@ nmea_receive(
 
 	/* Data will be accepted. Update stats & log data. */
 	up->tally.accepted++;
-	save_ltc(pp, rd_lastcode, rd_lencode);
+	save_ltc(pp, rd_lastcode, (size_t)rd_lencode);
 	pp->lastrec = rd_timestamp;
 
 #ifdef HAVE_PPSAPI


=====================================
ntpd/refclock_oncore.c
=====================================
--- a/ntpd/refclock_oncore.c
+++ b/ntpd/refclock_oncore.c
@@ -2302,7 +2302,7 @@ oncore_msg_BaEaHa(
 	/* copy the record to the (extra) location in SHMEM */
 
 	if (instance->shmem) {
-		int	i;
+		size_t	i;
 		uint8_t	*smp;	 /* pointer to start of shared mem for Ba/Ea/Ha */
 
 		switch(instance->chan) {
@@ -3520,7 +3520,7 @@ oncore_load_almanac(
 		if (!strncmp((char *) cp, "@@Cb", 4) &&
 		    oncore_checksum_ok(cp, 33) &&
 		    (*(cp+4) == 4 || *(cp+4) == 5)) {
-			IGNORE(write(instance->ttyfd, cp, n));
+			IGNORE(write(instance->ttyfd, cp, (size_t)n));
 			oncore_print_Cb(instance, cp);
 		}
 	}


=====================================
tests/libntp/macencrypt.c
=====================================
--- a/tests/libntp/macencrypt.c
+++ b/tests/libntp/macencrypt.c
@@ -29,12 +29,13 @@ const char *expectedPacket = "ijklmnopqrstuvwx\0\0\0\0\x0c\x0e\x84\xcf\x0b\xb7\x
 
 TEST(macencrypt, Encrypt) {
 	char *packetPtr[totalLength];
-	memset(packetPtr+packetLength, 0, keyIdLength);
-	memcpy(packetPtr, packet, packetLength);
+	memset(packetPtr+packetLength, 0, (size_t)keyIdLength);
+	memcpy(packetPtr, packet, (size_t)packetLength);
 
 	cache_secretsize = keyLength;
 
-	int length =  mac_authencrypt(keytype, (u_char*)key, (uint32_t*)packetPtr, packetLength);
+	int length = mac_authencrypt(keytype, (u_char*)key,
+                                     (uint32_t*)packetPtr, packetLength);
 
 	TEST_ASSERT_TRUE(mac_authdecrypt(keytype, (u_char*)key, (uint32_t*)packetPtr, packetLength, length));
 


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



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


More information about the vc mailing list