[Git][NTPsec/ntpsec][master] C99 allows inline declaration in for loops

Matt Selsky gitlab at mg.gitlab.com
Sat Dec 2 05:12:28 UTC 2017


Matt Selsky pushed to branch master at NTPsec / ntpsec


Commits:
f030489e by NHOrus at 2017-12-02T05:12:19+00:00
C99 allows inline declaration in for loops

- - - - -


5 changed files:

- libntp/macencrypt.c
- ntpd/ntp_io.c
- ntpd/ntp_proto.c
- ntpd/refclock_neoclock.c
- ntpd/refclock_oncore.c


Changes:

=====================================
libntp/macencrypt.c
=====================================
--- a/libntp/macencrypt.c
+++ b/libntp/macencrypt.c
@@ -28,9 +28,8 @@ static bool ctmemeq(const void *s1, const void *s2, size_t n) {
 	const uint8_t *a = s1;
 	const uint8_t *b = s2;
 	uint8_t accum = 0;
-        size_t i;
 
-	for(i=0; i<n; i++) {
+	for(size_t i = 0; i < n; i++) {
 		accum |= a[i] ^ b[i];
 	}
 


=====================================
ntpd/ntp_io.c
=====================================
--- a/ntpd/ntp_io.c
+++ b/ntpd/ntp_io.c
@@ -461,12 +461,11 @@ sockaddr_dump(const sockaddr_u *psau)
 	/* Limit the size of the sockaddr_in6 hex dump */
 	const int maxsize = min(32, sizeof(psau->sa6));
 	const uint8_t *	cp;
-	int		i;
 
 	/* XXX: Should we limit maxsize based on psau->saX.sin_family? */
 	cp = (const void *)&psau->sa6;
 
-	for(i = 0; i < maxsize; i++) {
+	for(int i = 0; i < maxsize; i++) {
 		printf("%02x", *cp++);
 		if (!((i + 1) % 4))
 			printf(" ");


=====================================
ntpd/ntp_proto.c
=====================================
--- a/ntpd/ntp_proto.c
+++ b/ntpd/ntp_proto.c
@@ -246,10 +246,9 @@ free_packet(
 	struct parsed_pkt *pkt
 	)
 {
-	size_t i;
 	if(pkt == NULL) { return; };
 	if(pkt->extensions != NULL) {
-		for(i = 0; i < pkt->num_extensions; i++) {
+		for(size_t i = 0; i < pkt->num_extensions; i++) {
 			free(pkt->extensions[i].body);
 			pkt->extensions[i].body = NULL;
 		}
@@ -309,7 +308,6 @@ parse_packet(
 		/* Count and validate extensions */
 		size_t ext_count = 0;
 		size_t extlen = 0;
-		size_t i;
 		while(bufptr <= recv_buf + recv_length - 28) {
 			extlen = ntp_be16dec(bufptr + 2);
 			if(extlen % 4 != 0 || extlen < 16) {
@@ -331,7 +329,7 @@ parse_packet(
 
 		/* Copy extensions */
 		bufptr = recv_buf + LEN_PKT_NOMAC;
-		for(i = 0; i < ext_count; i++) {
+		for(size_t i = 0; i < ext_count; i++) {
 			pkt->extensions[i].type = ntp_be16dec(bufptr);
 			pkt->extensions[i].len = ntp_be16dec(bufptr + 2) - 4;
 			pkt->extensions[i].body =


=====================================
ntpd/refclock_neoclock.c
=====================================
--- a/ntpd/refclock_neoclock.c
+++ b/ntpd/refclock_neoclock.c
@@ -137,9 +137,6 @@ neoclock4x_start(int unit,
   char dev[20];
   int sl232;
   struct termios termsettings;
-#if !defined(NEOCLOCK4X_FIRMWARE)
-  int tries;
-#endif
 
   (void) snprintf(dev, sizeof(dev)-1, "/dev/neoclock4x-%d", unit);
 
@@ -293,7 +290,7 @@ neoclock4x_start(int unit,
   return false;
 #endif
 #else
-  for(tries=0; tries < 5; tries++)
+  for(int tries = 0; tries < 5; tries++)
     {
       NLOG(NLOG_CLOCKINFO)
 	msyslog(LOG_INFO, "REFCLOCK: NeoClock4X(%d): checking NeoClock4X firmware version (%d/5)", unit, tries);
@@ -389,7 +386,6 @@ neoclock4x_receive(struct recvbuf *rbufp)
   unsigned long calc_utc;
   int day;
   int month;	/* ddd conversion */
-  int c;
   int dsec;
   unsigned char calc_chksum;
   int recv_chksum;
@@ -422,7 +418,7 @@ neoclock4x_receive(struct recvbuf *rbufp)
 
   /* calculate checksum */
   calc_chksum = 0;
-  for(c=0; c < NEOCLOCK4X_OFFSET_CRC; c++)
+  for(int c = 0; c < NEOCLOCK4X_OFFSET_CRC; c++)
     {
       calc_chksum += pp->a_lastcode[c];
     }
@@ -725,10 +721,9 @@ neol_hexatoi_len(const char str[],
 		 int maxlen)
 {
   int hexdigit;
-  int i;
   int n = 0;
 
-  for(i=0; isxdigit((unsigned char)str[i]) && i < maxlen; i++)
+  for(int i = 0; isxdigit((unsigned char)str[i]) && i < maxlen; i++)
     {
       hexdigit = isdigit((unsigned char)str[i]) ? toupper((unsigned char)str[i]) - '0' : toupper((unsigned char)str[i]) - 'A' + 10;
       n = 16 * n + hexdigit;
@@ -743,10 +738,9 @@ neol_atoi_len(const char str[],
 		  int maxlen)
 {
   int digit;
-  int i;
   int n = 0;
 
-  for(i=0; isdigit((unsigned char)str[i]) && i < maxlen; i++)
+  for(int i = 0; isdigit((unsigned char)str[i]) && i < maxlen; i++)
     {
       digit = str[i] - '0';
       n = 10 * n + digit;


=====================================
ntpd/refclock_oncore.c
=====================================
--- a/ntpd/refclock_oncore.c
+++ b/ntpd/refclock_oncore.c
@@ -1497,7 +1497,7 @@ oncore_consume(
 
 		/* Ok, we have a header now */
 		l = sizeof(oncore_messages)/sizeof(oncore_messages[0]) -1;
-		for(m=0; m<l; m++)
+		for(m = 0; m < l; m++)
 			if (!strncmp(oncore_messages[m].flag, (char *)(rcvbuf+2), (size_t) 2))
 				break;
 		if (m == l) {
@@ -1883,7 +1883,6 @@ oncore_msg_any(
 	UNUSED_ARG(len);
 	UNUSED_ARG(idx);
 #else
-	int i;
 	const char *fmt = oncore_messages[idx].fmt;
 	const char *p;
 	char *q;
@@ -1899,7 +1898,7 @@ oncore_msg_any(
 		if (!*fmt) {
 			snprintf(Msg, sizeof(Msg), ">>@@%c%c ", buf[2],
 				 buf[3]);
-			for(i = 2; i < len && i < 2400 ; i++) {
+			for(int i = 2; i < len && i < 2400 ; i++) {
 				snprintf(Msg2, sizeof(Msg2), "%02x",
 					 buf[i]);
 				strlcat(Msg, Msg2, sizeof(Msg));



View it on GitLab: https://gitlab.com/NTPsec/ntpsec/commit/f030489e167d4bd2df968fb24a40cf136bbcb456

---
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/commit/f030489e167d4bd2df968fb24a40cf136bbcb456
You're receiving this email because of your account on gitlab.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ntpsec.org/pipermail/vc/attachments/20171202/b1b253a9/attachment.html>


More information about the vc mailing list