[Git][NTPsec/ntpsec][master] 5 commits: lfpinit(): simplify. Use better parm names.

Gary E. Miller gitlab at mg.gitlab.com
Sat Mar 11 00:47:19 UTC 2017


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


Commits:
bbd52947 by Gary E. Miller at 2017-03-10T16:07:40-08:00
lfpinit(): simplify.  Use better parm names.

- - - - -
ea737077 by Gary E. Miller at 2017-03-10T16:11:47-08:00
Add missing trivial cast to size_t.

- - - - -
466c6b35 by Gary E. Miller at 2017-03-10T16:25:38-08:00
Add lfpinit_u() and use it.  Removes a ton of sign warnings.

- - - - -
78d67088 by Gary E. Miller at 2017-03-10T16:31:27-08:00
Add mising trivial casts.

- - - - -
7c48838c by Gary E. Miller at 2017-03-10T16:46:08-08:00
If you want size_t, use size_t, not int.

- - - - -


4 changed files:

- include/mbg_gps166.h
- include/ntp_fp.h
- libntp/decodenetnum.c
- libparse/data_mbg.c


Changes:

=====================================
include/mbg_gps166.h
=====================================
--- a/include/mbg_gps166.h
+++ b/include/mbg_gps166.h
@@ -920,8 +920,8 @@ typedef struct
 
 
 
-void mbg_tm_str (char **, TM_GPS *, int, int);
-void mbg_tgps_str (char **, T_GPS *, int);
+void mbg_tm_str (char **, TM_GPS *, size_t, int);
+void mbg_tgps_str (char **, T_GPS *, size_t);
 void get_mbg_header (unsigned char **, GPS_MSG_HDR *);
 void put_mbg_header (unsigned char **, GPS_MSG_HDR *);
 void get_mbg_sw_rev (unsigned char **, SW_REV *);


=====================================
include/ntp_fp.h
=====================================
--- a/include/ntp_fp.h
+++ b/include/ntp_fp.h
@@ -57,11 +57,15 @@ typedef uint64_t l_fp;
 #define setlfpsint(n, v)        ((n)  = (lfptosint(v) | lfpfrac(n)))
 #define setlfpuint(n, v)        ((n)  = (lfptouint(v) | lfpfrac(n)))
 
-static inline l_fp lfpinit(int32_t hi, uint32_t lo)
+static inline l_fp lfpinit(int32_t sec, uint32_t frac)
 {
-    l_fp tmp = 0;
-    setlfpsint(tmp, hi);
-    setlfpfrac(tmp, lo);
+    l_fp tmp = lfptouint(sec) | lfpfrac(frac);
+    return tmp;
+}
+
+static inline l_fp lfpinit_u(uint32_t sec, uint32_t frac)
+{
+    l_fp tmp = lfptouint(sec) | lfpfrac(frac);
     return tmp;
 }
 
@@ -118,7 +122,7 @@ static inline l_fp_w htonl_fp(l_fp lfp) {
 }
 
 static inline l_fp ntohl_fp(l_fp_w lfpw) {
-    return lfpinit(ntohl(lfpw.l_ui), ntohl(lfpw.l_uf));
+    return lfpinit_u(ntohl(lfpw.l_ui), ntohl(lfpw.l_uf));
 }
 
 #define	M_ISNEG(v_i)			/* v < 0 */ \
@@ -165,7 +169,7 @@ static inline l_fp dtolfp(double d)
 	if (M_isneg) {
 		q_tmp = ~q_tmp + 1;
 	}
-	return lfpinit((uint32_t)(q_tmp >> 32) , (uint32_t)q_tmp);
+	return lfpinit_u(q_tmp >> 32, (uint32_t)q_tmp);
 }
 
 static inline double lfptod(l_fp r)


=====================================
libntp/decodenetnum.c
=====================================
--- a/libntp/decodenetnum.c
+++ b/libntp/decodenetnum.c
@@ -101,7 +101,7 @@ decodenetnum(
 	if(ip_end - ip_start + 1 > (int)sizeof(ip)) {
 		return false;
 	} else {
-		memcpy(ip, ip_start, ip_end - ip_start);
+		memcpy(ip, ip_start, (size_t)(ip_end - ip_start));
 		ip[ip_end - ip_start] = '\0';
 	}
 


=====================================
libparse/data_mbg.c
=====================================
--- a/libparse/data_mbg.c
+++ b/libparse/data_mbg.c
@@ -17,7 +17,7 @@
 #include "ieee754io.h"
 
 static void get_mbg_tzname (unsigned char **, char *);
-static void mbg_time_status_str (char **, unsigned int, int);
+static void mbg_time_status_str (char **, unsigned int, size_t);
 
 #if 0				/* no actual floats on Meinberg binary interface */
 static offsets_t mbg_float  = { 1, 0, 3, 2, 0, 0, 0, 0 }; /* byte order for meinberg floats */
@@ -180,7 +180,7 @@ static void
 mbg_time_status_str(
 	char **buffpp,
 	unsigned int status,
-	int size
+	size_t size
 	)
 {
 	static struct state
@@ -211,10 +211,12 @@ mbg_time_status_str(
 			{
 				if (p != *buffpp)
 				{
-					strlcpy(p, ", ", size - (p - start));
+					strlcpy(p, ", ",
+                                                size - (size_t)(p - start));
 					p += 2;
 				}
-				strlcpy(p, s->string, size - (p - start));
+				strlcpy(p, s->string,
+                                        size - (size_t)(p - start));
 				p += strlen(p);
 			}
 		}
@@ -226,7 +228,7 @@ void
 mbg_tm_str(
 	char **buffpp,
 	TM_GPS *tmp,
-	int size,
+	size_t size,
 	int print_status
 	)
 {
@@ -248,7 +250,7 @@ void
 mbg_tgps_str(
 	char **buffpp,
 	T_GPS *tgpsp,
-	int size
+	size_t size
 	)
 {
 	snprintf(*buffpp, size, "week %d + %ld days + %ld.%07ld sec",



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


More information about the vc mailing list