[Git][NTPsec/ntpsec][pep8fix] 5 commits: jupiter: Convert implicit casts to explicit.

Ian Bruene gitlab at mg.gitlab.com
Tue Apr 4 04:57:35 UTC 2017


Ian Bruene pushed to branch pep8fix at NTPsec / ntpsec


Commits:
46a83e8a by Gary E. Miller at 2017-04-03T14:47:29-07:00
jupiter: Convert implicit casts to explicit.

- - - - -
d98bfea7 by Gary E. Miller at 2017-04-03T16:15:17-07:00
oncore: Change implicit casts to explicit.

- - - - -
db33765f by Gary E. Miller at 2017-04-03T17:36:43-07:00
tests: pylib tests now get run.

Their output still does not get into test.log...

- - - - -
5b70d40d by Ian Bruene at 2017-04-04T03:57:55+00:00
Fixed tests and functions where appropriate.

- - - - -
da4354c1 by Ian Bruene at 2017-04-04T04:57:22+00:00
Merge branch 'master' into 'pep8fix'

# Conflicts:
#   tests/pylib/test_util.py
- - - - -


5 changed files:

- ntpd/refclock_jupiter.c
- ntpd/refclock_oncore.c
- tests/pylib/test_statfiles.py
- tests/pylib/test_util.py
- tests/wscript


Changes:

=====================================
ntpd/refclock_jupiter.c
=====================================
--- a/ntpd/refclock_jupiter.c
+++ b/ntpd/refclock_jupiter.c
@@ -766,8 +766,8 @@ jupiter_receive(struct recvbuf *rbufp)
 	bpcnt = rbufp->recv_length;
 
 	/* This shouldn't happen */
-	if (bpcnt > sizeof(instance->sbuf) - instance->ssize)
-		bpcnt = sizeof(instance->sbuf) - instance->ssize;
+	if (bpcnt > sizeof(instance->sbuf) - (size_t)instance->ssize)
+		bpcnt = sizeof(instance->sbuf) - (size_t)instance->ssize;
 
 	/* Append to input buffer */
 	memcpy((uint8_t *)instance->sbuf + instance->ssize, bp, bpcnt);
@@ -780,7 +780,7 @@ jupiter_receive(struct recvbuf *rbufp)
 		tstamp = rbufp->recv_time;
 		hp = (struct jheader *)instance->sbuf;
 		sp = (u_short *)(hp + 1);
-		size = cc - sizeof(*hp);
+		size = cc - (int)sizeof(*hp);
 		switch (getshort(hp->id)) {
 
 		case JUPITER_O_PULSE:
@@ -803,7 +803,8 @@ jupiter_receive(struct recvbuf *rbufp)
 			 * this one.
 			 */
 			laststime = instance->stime;
-			instance->stime = DS2UI(((struct jpulse *)sp)->stime);
+			instance->stime =
+                                (uint32_t)DS2UI(((struct jpulse *)sp)->stime);
 			if (laststime != 0 && instance->stime - laststime <= 21) {
 				jupiter_debug(peer, __func__,
 				"avoided firmware bug (stime %.2f, laststime %.2f)",
@@ -839,7 +840,7 @@ jupiter_receive(struct recvbuf *rbufp)
 				break;
 
 			/* Add the new sample to a median filter */
-			tstamp = lfpinit(JAN_1970 + (uint32_t)last_timecode, 0);
+			tstamp = lfpinit(JAN_1970 + last_timecode, 0);
 
 			refclock_process_offset(pp, tstamp, pp->lastrec, pp->fudgetime1);
 
@@ -948,7 +949,7 @@ jupiter_parse_t(struct instance *instance, u_short *sp)
 	jp = (struct jpulse *)sp;
 
 	/* The timecode is presented as seconds into the current GPS week */
-	sweek = DS2UI(jp->sweek) % WEEKSECS;
+	sweek = (u_int)DS2UI(jp->sweek) % WEEKSECS;
 
 	/*
 	 * If we don't know the current GPS week, calculate it from the
@@ -1080,7 +1081,7 @@ jupiter_parse_gpos(struct instance *instance, u_short *sp)
 	}
 
 	instance->gpos_gweek = jg->gweek;
-	instance->gpos_sweek = DS2UI(jg->sweek);
+	instance->gpos_sweek = (u_int)DS2UI(jg->sweek);
 	/* coverity[tainted_data] */
 	while(instance->gpos_sweek >= WEEKSECS) {
 		instance->gpos_sweek -= WEEKSECS;
@@ -1321,7 +1322,7 @@ jupiter_recv(struct instance *instance)
 			return (0);
 	}
 
-	if (jupiter_cksum(sp, (cc / sizeof(u_short) - 1)) !=
+	if (jupiter_cksum(sp, ((u_int)cc / sizeof(u_short) - 1U)) !=
 	    getshort(hp->hsum)) {
 	    jupiter_debug(instance->peer, __func__, "bad header checksum!");
 		/* This is drastic but checksum errors should be rare */
@@ -1332,14 +1333,14 @@ jupiter_recv(struct instance *instance)
 	/* Check for a payload */
 	len = getshort(hp->len);
 	if (len > 0) {
-		n = (len + 1) * sizeof(u_short);
+		n = (len + 1) * (int)sizeof(u_short);
 		/* Not enough data yet */
 		if (size < cc + n)
 			return (0);
 
 		/* Check payload checksum */
 		sp = (u_short *)(hp + 1);
-		if (jupiter_cksum(sp, len) != getshort(sp[len])) {
+		if (jupiter_cksum(sp, (u_int)len) != getshort(sp[len])) {
 			jupiter_debug(instance->peer,
 			    __func__, "bad payload checksum!");
 			/* This is drastic but checksum errors should be rare */


=====================================
ntpd/refclock_oncore.c
=====================================
--- a/ntpd/refclock_oncore.c
+++ b/ntpd/refclock_oncore.c
@@ -558,7 +558,7 @@ static uint8_t oncore_cmd_Ia[]  = { 'I', 'a' };					    /* 12	Self Test				*/
 
 	/* to buffer, int w, uint8_t *buf */
 #define w32_buf(buf,w)	{ u_int i_tmp;			   \
-			  i_tmp = (w<0) ? (~(-w)+1) : (w); \
+			  i_tmp = (u_int)((w<0) ? (~(-w)+1) : (w)); \
 			  (buf)[0] = (i_tmp >> 24) & 0xff; \
 			  (buf)[1] = (i_tmp >> 16) & 0xff; \
 			  (buf)[2] = (i_tmp >>	8) & 0xff; \
@@ -663,7 +663,7 @@ oncore_start(
 	}
 
 	if (stat(device2, &stat2)) {
-		stat2.st_dev = stat2.st_ino = -2;
+		stat2.st_dev = stat2.st_ino = (unsigned long)-2;
 		oncore_log_f(instance, LOG_ERR, "Can't stat fd2 (%s) %d %m",
 			     device2, errno);
 	}
@@ -1508,7 +1508,7 @@ oncore_consume(
 			continue;
 		}
 
-		l = oncore_messages[m].len;
+		l = (unsigned int)oncore_messages[m].len;
 #ifdef ONCORE_VERBOSE_CONSUME
 		if (debug > 3)
 			oncore_log_f(instance, LOG_DEBUG,
@@ -1529,13 +1529,14 @@ oncore_consume(
 				oncore_log(instance, LOG_DEBUG, "NO <CR><LF> at end of message");
 #endif
 		} else {	/* check the CheckSum */
-			if (oncore_checksum_ok(rcvbuf, l)) {
+			if (oncore_checksum_ok(rcvbuf, (int)l)) {
 				if (instance->shmem != NULL) {
 					instance->shmem[oncore_messages[m].shmem + 2]++;
 					memcpy(instance->shmem + oncore_messages[m].shmem + 3,
 					    rcvbuf, (size_t) l);
 				}
-				oncore_msg_any(instance, rcvbuf, (size_t) (l-3), m);
+				oncore_msg_any(instance, rcvbuf,
+                                               (size_t)(l-3), (int)m);
 				if (oncore_messages[m].handler)
 					oncore_messages[m].handler(instance, rcvbuf, (size_t) (l-3));
 			}
@@ -2025,7 +2026,7 @@ oncore_msg_Ay(
 
 	instance->saw_Ay = 1;
 
-	instance->offset = buf_w32(&buf[4]);
+	instance->offset = (u_long)buf_w32(&buf[4]);
 
 	oncore_log_f(instance, LOG_INFO, "PPS Offset is set to %ld ns",
 		     instance->offset);
@@ -2051,7 +2052,7 @@ oncore_msg_Az(
 
 	instance->saw_Az = 1;
 
-	instance->delay = buf_w32(&buf[4]);
+	instance->delay = (u_long)buf_w32(&buf[4]);
 
 	oncore_log_f(instance, LOG_INFO, "Cable delay is set to %ld ns",
 		     instance->delay);
@@ -2095,7 +2096,7 @@ oncore_msg_BaEaHa(
 		instance->count3 = 0;
 
 		if (instance->chan_in != -1)	/* set in Input */
-			instance->chan = instance->chan_in;
+			instance->chan = (uint8_t)instance->chan_in;
 		else				/* set from test */
 			instance->chan = instance->chan_ck;
 
@@ -2750,8 +2751,9 @@ oncore_msg_Cb(
 	}
 
 	i *= 36;
-	instance->shmem[instance->shmem_Cb + i + 2]++;
-	memcpy(instance->shmem + instance->shmem_Cb + i + 3, buf, (size_t) (len + 3));
+	instance->shmem[(int)instance->shmem_Cb + i + 2]++;
+	memcpy(instance->shmem + instance->shmem_Cb + i + 3, buf,
+               (size_t)(len + 3));
 
 #ifdef ONCORE_VERBOSE_MSG_CB
 	oncore_log_f(instance, LOG_DEBUG, "See Cb [%d,%d]", buf[4],
@@ -2883,8 +2885,8 @@ oncore_msg_Cj_id(
 
 	/* next, the Firmware Version and Revision numbers */
 
-	instance->version  = atoi((char *) &instance->Cj[83]);
-	instance->revision = atoi((char *) &instance->Cj[111]);
+	instance->version  = (u_int)atoi((char *) &instance->Cj[83]);
+	instance->revision = (u_int)atoi((char *) &instance->Cj[111]);
 
 	/* from model number decide which Oncore this is,
 		and then the number of channels */
@@ -3068,7 +3070,8 @@ oncore_msg_Cj_init(
 		oncore_sendmsg(instance, oncore_cmd_Ea0, sizeof(oncore_cmd_Ea0));
 		oncore_sendmsg(instance, oncore_cmd_En0, sizeof(oncore_cmd_En0));
 		oncore_sendmsg(instance, oncore_cmd_Ha, sizeof(oncore_cmd_Ha ));
-		oncore_cmd_Gc[2] = (instance->pps_control < 0) ? 1 : instance->pps_control;
+		oncore_cmd_Gc[2] = (uint8_t)((instance->pps_control < 0) ?
+                                    1 : instance->pps_control);
 		oncore_sendmsg(instance, oncore_cmd_Gc, sizeof(oncore_cmd_Gc)); /* PPS off/continuous/Tracking 1+sat/TRAIM */
 	}
 
@@ -3840,7 +3843,7 @@ oncore_set_traim(
 	if (instance->traim_in != -1)	/* set in Input */
 		instance->traim = instance->traim_in;
 	else
-		instance->traim = instance->traim_ck;
+		instance->traim = (int8_t)instance->traim_ck;
 
 	oncore_log_f(instance, LOG_INFO, "Input   says TRAIM = %d",
 		     instance->traim_in);


=====================================
tests/pylib/test_statfiles.py
=====================================
--- a/tests/pylib/test_statfiles.py
+++ b/tests/pylib/test_statfiles.py
@@ -1,3 +1,6 @@
+#!/usr/bin/env python
+# coding: utf-8
+
 import unittest
 import ntp.statfiles
 


=====================================
tests/pylib/test_util.py
=====================================
--- a/tests/pylib/test_util.py
+++ b/tests/pylib/test_util.py
@@ -1,3 +1,6 @@
+#!/usr/bin/env python
+# coding: utf-8
+
 import unittest
 import ntp.util
 
@@ -150,4 +153,4 @@ class TestPylibUtilMethods(unittest.TestCase):
                          "10000.1ks")  # Value outside of unit ranges
 
 if __name__ == '__main__':
-    unittest.main()
+    unittest.main()
\ No newline at end of file


=====================================
tests/wscript
=====================================
--- a/tests/wscript
+++ b/tests/wscript
@@ -75,7 +75,7 @@ def build(ctx):
         includes=["%s/tests/unity/" % srcnode,
                   "%s/ntpd/" % srcnode,
                   "%s/tests/libntp/" % srcnode,
-                  "%s/tests/common/" % srcnode
+                  "%s/tests/common/" % srcnode,
                   ],
         install_path=None,
         source=ntpd_source,
@@ -83,3 +83,6 @@ def build(ctx):
         use="ntpd_lib libntpd_obj unity ntp isc "
             "M PTHREAD CRYPTO RT SOCKET NSL",
     )
+
+    ctx.exec_command("%s/tests/pylib/test_statfiles.py" % srcnode)
+    ctx.exec_command("%s/tests/pylib/test_util.py" % srcnode)



View it on GitLab: https://gitlab.com/NTPsec/ntpsec/compare/4e23aee29c48174830e7a0684112bb8f533b00a5...da4354c1fa87910106745d07f6e1637a02a654be
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ntpsec.org/pipermail/vc/attachments/20170404/f5a73b25/attachment.html>


More information about the vc mailing list