[Git][NTPsec/ntpsec][master] Change formal l_fp args from pointer to scalar...

Eric S. Raymond gitlab at mg.gitlab.com
Thu Jan 5 14:15:57 UTC 2017


Eric S. Raymond pushed to branch master at NTPsec / ntpsec


Commits:
35d5b333 by Eric S. Raymond at 2017-01-05T09:14:22-05:00
Change formal l_fp args from pointer to scalar...

...so the compiler and static-checking tools know nothing can propagate
out through them.

- - - - -


7 changed files:

- include/ntp_fp.h
- libntp/prettydate.c
- libntp/pymodule.c
- ntpd/refclock_gpsd.c
- ntpd/refclock_spectracom.c
- ntpd/refclock_trimble.c
- tests/libntp/prettydate.c


Changes:

=====================================
include/ntp_fp.h
=====================================
--- a/include/ntp_fp.h
+++ b/include/ntp_fp.h
@@ -217,10 +217,9 @@ extern	char *	fptoms		(s_fp, short);
 extern	bool	hextolfp	(const char *, l_fp *);
 extern  void	gpstolfp	(int, int, unsigned long, l_fp *);
 extern	bool	mstolfp		(const char *, l_fp *);
-extern	char *	prettydate	(l_fp *);
-extern	char *	gmprettydate	(l_fp *);
-extern	char *	gmprettydate	(l_fp *);
-extern	char *	rfc3339date	(l_fp *);
+extern	char *	prettydate	(const l_fp);
+extern	char *	gmprettydate	(const l_fp);
+extern	char *	rfc3339date	(const l_fp);
 extern  l_fp	mfp_mul		(l_fp, int32_t, uint32_t);
 
 extern	void	set_sys_fuzz	(double);


=====================================
libntp/prettydate.c
=====================================
--- a/libntp/prettydate.c
+++ b/libntp/prettydate.c
@@ -14,7 +14,7 @@
 # error sizeof(time_t) < 4 -- this will not work!
 #endif
 
-static char *common_prettydate(l_fp *, bool);
+static char *common_prettydate(const l_fp, bool);
 
 /* Helper function to handle possible wraparound of the ntp epoch.
  *
@@ -116,7 +116,7 @@ get_struct_tm(
 
 static char *
 common_prettydate(
-	l_fp *ts,
+	const l_fp ts,
 	bool local
 	)
 {
@@ -132,8 +132,8 @@ common_prettydate(
 	LIB_GETBUF(bp);
 
 	/* get & fix milliseconds */
-	ntps = lfpuint(*ts);
-	msec = lfpfrac(*ts) / 4294967;	/* fract / (2 ** 32 / 1000) */
+	ntps = lfpuint(ts);
+	msec = lfpfrac(ts) / 4294967;	/* fract / (2 ** 32 / 1000) */
 	if (msec >= 1000u) {
 		msec -= 1000u;
 		ntps++;
@@ -148,13 +148,13 @@ common_prettydate(
 		struct calendar jd;
 		ntpcal_time_to_date(&jd, sec);
 		snprintf(bp, LIB_BUFLENGTH, pfmt,
-			 (u_long)lfpuint(*ts), (u_long)lfpfrac(*ts),
+			 (u_long)lfpuint(ts), (u_long)lfpfrac(ts),
 			 jd.year, jd.month, jd.monthday,
 			 jd.hour, jd.minute, jd.second, msec);
 		strncat(bp, "Z",  LIB_BUFLENGTH);
 	} else {
 		snprintf(bp, LIB_BUFLENGTH, pfmt,
-			 (u_long)lfpuint(*ts), (u_long)lfpfrac(*ts),
+			 (u_long)lfpuint(ts), (u_long)lfpfrac(ts),
 			 1900 + tm->tm_year, tm->tm_mon+1, tm->tm_mday,
 			 tm->tm_hour, tm->tm_min, tm->tm_sec, msec);
 		if (!local)
@@ -166,7 +166,7 @@ common_prettydate(
 
 char *
 prettydate(
-	l_fp *ts
+	const l_fp ts
 	)
 {
 	return common_prettydate(ts, true);
@@ -175,7 +175,7 @@ prettydate(
 
 char *
 rfc3339date(
-	l_fp *ts
+	const l_fp ts
 	)
 {
 	return common_prettydate(ts, false) + 18; /* skip past hex time */
@@ -184,7 +184,7 @@ rfc3339date(
 
 char *
 gmprettydate(
-	l_fp *ts
+	const l_fp ts
 	)
 {
 	return common_prettydate(ts, false);


=====================================
libntp/pymodule.c
=====================================
--- a/libntp/pymodule.c
+++ b/libntp/pymodule.c
@@ -78,7 +78,7 @@ ntpc_prettydate(PyObject *self, PyObject *args)
     if (!PyArg_ParseTuple(args, "s", &s))
 	return NULL;
     if (hextolfp(s+2, &ts))
-	return Py_BuildValue("s", prettydate(&ts));
+	return Py_BuildValue("s", prettydate(ts));
     else {
 	PyErr_SetString(PyExc_ValueError, "ill-formed hex date");
 	return NULL;


=====================================
ntpd/refclock_gpsd.c
=====================================
--- a/ntpd/refclock_gpsd.c
+++ b/ntpd/refclock_gpsd.c
@@ -1555,8 +1555,8 @@ process_tpv(
 			DPRINTF(2, ("%s: process_tpv, stamp='%s',"
 				    " recvt='%s' mode=%u\n",
 				    up->logname,
-				    gmprettydate(&up->ibt_stamp),
-				    gmprettydate(&up->ibt_recvt),
+				    gmprettydate(up->ibt_stamp),
+				    gmprettydate(up->ibt_recvt),
 				    gps_mode));
 
 			/* have to use local receive time as substitute
@@ -1652,13 +1652,12 @@ process_pps(
 	setlfpfrac(up->pps_stamp, 0);
 
 	if (NULL != up->pps_peer)
-		save_ltc(up->pps_peer->procptr,
-			 gmprettydate(&up->pps_stamp2));
+		save_ltc(up->pps_peer->procptr, gmprettydate(up->pps_stamp2));
 	DPRINTF(2, ("%s: PPS record processed,"
 		    " stamp='%s', recvt='%s'\n",
 		    up->logname,
-		    gmprettydate(&up->pps_stamp2),
-		    gmprettydate(&up->pps_recvt2)));
+		    gmprettydate(up->pps_stamp2),
+		    gmprettydate(up->pps_recvt2)));
 	
 	up->fl_pps  = (0 != (pp->sloppyclockflag & CLK_FLAG2)) - 1;
 	up->fl_pps2 = -1;
@@ -1700,12 +1699,12 @@ process_toff(
 	up->ibt_local = *rtime;
 	up->fl_ibt    = -1;
 
-	save_ltc(pp, gmprettydate(&up->ibt_stamp));
+	save_ltc(pp, gmprettydate(up->ibt_stamp));
 	DPRINTF(2, ("%s: TOFF record processed,"
 		    " stamp='%s', recvt='%s'\n",
 		    up->logname,
-		    gmprettydate(&up->ibt_stamp),
-		    gmprettydate(&up->ibt_recvt)));
+		    gmprettydate(up->ibt_stamp),
+		    gmprettydate(up->ibt_recvt)));
 	return;
 
   fail:


=====================================
ntpd/refclock_spectracom.c
=====================================
--- a/ntpd/refclock_spectracom.c
+++ b/ntpd/refclock_spectracom.c
@@ -282,12 +282,10 @@ spectracom_receive(
 	 */
 	if (temp == 0) {
 		if (up->prev_eol_cr) {
-			DPRINTF(2, ("wwvb: <LF> @ %s\n",
-				    prettydate(&trtmp)));
+			DPRINTF(2, ("wwvb: <LF> @ %s\n", prettydate(trtmp)));
 		} else {
 			up->laststamp = trtmp;
-			DPRINTF(2, ("wwvb: <CR> @ %s\n", 
-				    prettydate(&trtmp)));
+			DPRINTF(2, ("wwvb: <CR> @ %s\n", prettydate(trtmp)));
 		}
 		up->prev_eol_cr = !up->prev_eol_cr;
 		return;
@@ -298,7 +296,7 @@ spectracom_receive(
 	up->prev_eol_cr = true;
 	DPRINTF(2, ("wwvb: code @ %s\n"
 		    "       using %s minus one char\n",
-		    prettydate(&trtmp), prettydate(&pp->lastrec)));
+		    prettydate(trtmp), prettydate(pp->lastrec)));
 	if (pp->lastrec == 0)
 		return;
 
@@ -469,7 +467,7 @@ spectracom_timer(
 #ifdef DEBUG
 	get_systime(&now);
 	if (debug)
-		printf("%c poll at %s\n", pollchar, prettydate(&now));
+		printf("%c poll at %s\n", pollchar, prettydate(now));
 #endif
 #ifdef HAVE_PPSAPI
 	if (up->ppsapi_lit &&


=====================================
ntpd/refclock_trimble.c
=====================================
--- a/ntpd/refclock_trimble.c
+++ b/ntpd/refclock_trimble.c
@@ -1057,7 +1057,7 @@ trimble_receive (
 #ifdef DEBUG
 	if (debug)
 		printf("trimble_receive: unit %d: %s\n",
-		       up->unit, prettydate(&pp->lastrec));
+		       up->unit, prettydate(pp->lastrec));
 #endif
 	pp->lastref = pp->lastrec;
 	refclock_receive(peer);


=====================================
tests/libntp/prettydate.c
=====================================
--- a/tests/libntp/prettydate.c
+++ b/tests/libntp/prettydate.c
@@ -18,7 +18,7 @@ static const u_int32_t HALF = 2147483648UL;
 TEST(prettydate, ConstantDate) {
     l_fp time = lfpinit(3485080800UL, HALF); // 2010-06-09 14:00:00.5
 
-	TEST_ASSERT_EQUAL_STRING("cfba1ce0.80000000 2010-06-09T14:00:00.500Z", gmprettydate(&time));
+	TEST_ASSERT_EQUAL_STRING("cfba1ce0.80000000 2010-06-09T14:00:00.500Z", gmprettydate(time));
 }
 
 TEST_GROUP_RUNNER(prettydate) {



View it on GitLab: https://gitlab.com/NTPsec/ntpsec/commit/35d5b333bfc8a78f9c74781b6b289d96feab4553
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ntpsec.org/pipermail/vc/attachments/20170105/3b788136/attachment.html>


More information about the vc mailing list