[Git][NTPsec/ntpsec][master] 4 commits: Remove unused function and macros: dofptoa(), ufptoa(), ufptoms()

Gary E. Miller gitlab at mg.gitlab.com
Tue Apr 4 20:28:43 UTC 2017


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


Commits:
8d4ab9bd by Gary E. Miller at 2017-04-04T12:34:05-07:00
Remove unused function and macros: dofptoa(), ufptoa(), ufptoms()

- - - - -
7f7e4280 by Gary E. Miller at 2017-04-04T12:46:45-07:00
ieee754io: fix unintialized l_fp return on NAN, +INF, -INF, etc.

- - - - -
e6cede53 by Gary E. Miller at 2017-04-04T13:26:36-07:00
tests/python: comment out tests that fail on clean hosts.

The tests need pylib installed first to run.  Not good.

- - - - -
71c66885 by Gary E. Miller at 2017-04-04T13:27:30-07:00
ieee754io: add tests for NAN, +INF and -INF.

- - - - -


6 changed files:

- include/ntp_fp.h
- − libntp/dofptoa.c
- libntp/wscript
- libparse/ieee754io.c
- tests/libparse/ieee754io.c
- tests/wscript


Changes:

=====================================
include/ntp_fp.h
=====================================
--- a/include/ntp_fp.h
+++ b/include/ntp_fp.h
@@ -181,7 +181,6 @@ static inline double lfptod(l_fp r)
 /*
  * Prototypes
  */
-extern	char *	dofptoa		(u_fp, bool, short, bool);
 extern	char *	dolfptoa	(l_fp, bool, short, bool);
 extern	char *	mfptoa		(l_fp, short);
 extern	char *	mfptoms		(l_fp, short);
@@ -204,8 +203,6 @@ extern	bool	adj_systime	(double, int (*adjtime)(const struct timeval *, struct t
 #define	lfptoa(fpv, ndec)	mfptoa((fpv), (ndec))
 #define	lfptoms(fpv, ndec)	mfptoms((fpv), (ndec))
 
-#define	ufptoa(fpv, ndec)	dofptoa((fpv), false, (ndec), false)
-#define	ufptoms(fpv, ndec)	dofptoa((fpv), false, (ndec), true)
 #define	ulfptoa(fpv, ndec)	dolfptoa((fpv), false, (ndec), false)
 #define	ulfptoms(fpv, ndec)	dolfptoa((fpv), false, (ndec), true)
 #define	umfptoa(lfp, ndec)	dolfptoa((lfp), false, (ndec), false)


=====================================
libntp/dofptoa.c deleted
=====================================
--- a/libntp/dofptoa.c
+++ /dev/null
@@ -1,119 +0,0 @@
-/*
- * dofptoa - do the grunge work to convert an fp number to ascii
- */
-#include "config.h"
-#include <stdio.h>
-#include <string.h>
-
-#include "ntp_fp.h"
-#include "lib_strbuf.h"
-#include "ntp_stdlib.h"
-
-char *
-dofptoa(
-	u_fp fpv,
-	bool neg,
-	short ndec,
-	bool msec
-	)
-{
-	register uint8_t *cp, *cpend;
-	register unsigned long val;
-	register short dec;
-	uint8_t cbuf[12];
-	uint8_t *cpdec;
-	char *buf;
-	char *bp;
-
-	/*
-	 * Get a string buffer before starting
-	 */
-	LIB_GETBUF(buf);
-
-	/*
-	 * Zero out the buffer
-	 */
-	ZERO(cbuf);
-
-	/*
-	 * Set the pointers to point at the first
-	 * decimal place.  Get a local copy of the value.
-	 */
-	cp = cpend = &cbuf[5];
-	val = fpv;
-
-	/*
-	 * If we have to, decode the integral part
-	 */
-	if (!(val & 0xffff0000))
-	    cp--;
-	else {
-		register u_short sv = (u_short)(val >> 16);
-		register u_short tmp;
-		register u_short ten = 10;
-
-		do {
-			tmp = sv;
-			sv = (u_short) (sv/ten);
-			*(--cp) = (uint8_t)(tmp - ((sv<<3) + (sv<<1)));
-		} while (sv != 0);
-	}
-
-	/*
-	 * Figure out how much of the fraction to do
-	 */
-	if (msec) {
-		dec = (short)(ndec + 3);
-		if (dec < 3)
-		    dec = 3;
-		cpdec = &cbuf[8];
-	} else {
-		dec = ndec;
-		cpdec = cpend;
-	}
-
-	if (dec > 6)
-	    dec = 6;
-	
-	if (dec > 0) {
-		do {
-			val &= 0xffff;
-			val = (val << 3) + (val << 1);
-			*cpend++ = (uint8_t)(val >> 16);
-		} while (--dec > 0);
-	}
-
-	if (val & 0x8000) {
-		register uint8_t *tp;
-		/*
-		 * Round it. Ick.
-		 */
-		tp = cpend;
-		*(--tp) += 1;
-		while (*tp >= 10) {
-			*tp = 0;
-			*(--tp) += 1;
-		}
-	}
-
-	/*
-	 * Remove leading zeroes if necessary
-	 */
-	while (cp < (cpdec -1) && *cp == 0)
-	    cp++;
-	
-	/*
-	 * Copy it into the buffer, asciizing as we go.
-	 */
-	bp = buf;
-	if (neg)
-	    *bp++ = '-';
-	
-	while (cp < cpend) {
-		if (cp == cpdec)
-		    *bp++ = '.';
-		*bp++ = (char)(*cp++ + '0');
-	}
-	*bp = '\0';
-	return buf;
-}


=====================================
libntp/wscript
=====================================
--- a/libntp/wscript
+++ b/libntp/wscript
@@ -7,7 +7,6 @@ def build(ctx):
         "authreadkeys.c",
         "clocktime.c",
         "decodenetnum.c",
-        "dofptoa.c",
         "dolfptoa.c",
         "getopt.c",
         "initnetwork.c",


=====================================
libparse/ieee754io.c
=====================================
--- a/libparse/ieee754io.c
+++ b/libparse/ieee754io.c
@@ -155,6 +155,9 @@ fetch_ieee754(
   unsigned char val;
   int fieldindex = 0;
   
+
+  *lfpp = 0;           /* return zero for all errors: NAN, +INF, -INF, etc. */
+
   switch (size)
     {
     case IEEE_DOUBLE:
@@ -279,8 +282,6 @@ fetch_ieee754(
        * collect real numbers
        */
 
-      *lfpp = 0;
-
       /*
        * check for overflows
        */


=====================================
tests/libparse/ieee754io.c
=====================================
--- a/tests/libparse/ieee754io.c
+++ b/tests/libparse/ieee754io.c
@@ -62,15 +62,37 @@ TEST(ieee754io, test_negone64) {
 
 TEST(ieee754io, test_nan64) {
         int ret;
-        unsigned char negone[8] = { 0x7f, 0xf0, 0, 0, 0, 0, 0, 0 };
-	unsigned char *bp = &negone[0];
+        unsigned char buf[8] = { 0x7f, 0xF0, 0, 0, 0, 0, 0, 0 };
+	unsigned char *bp = &buf[0];
         l_fp fp;
 
+        /* +INF */
 	ret = fetch_ieee754( &bp, IEEE_DOUBLE, &fp, native_off);
 
-        printf("%d\n", ret);
 	TEST_ASSERT( IEEE_POSINFINITY == ret);
-	// TEST_ASSERT_EQUAL_INT64( 0x7FFFFFFFFFFFFFFFLL, (long)fp );
+        /* not IEEE754, but check for 0 anyway */
+	TEST_ASSERT_EQUAL_INT64( 0, (long)fp );
+
+        /* -INF */
+        buf[0] = 0xff;
+	bp = &buf[0];
+	ret = fetch_ieee754( &bp, IEEE_DOUBLE, &fp, native_off);
+
+        printf("\n%d\n", ret);
+	TEST_ASSERT( IEEE_NEGINFINITY == ret);
+        /* not IEEE754, but check for 0 anyway */
+	TEST_ASSERT_EQUAL_INT64( 0, (long)fp );
+
+        /* NAN */
+        buf[0] = 0x7f;
+        buf[1] = 0xf8;
+	bp = &buf[0];
+	ret = fetch_ieee754( &bp, IEEE_DOUBLE, &fp, native_off);
+
+        printf("\n%d\n", ret);
+	TEST_ASSERT( IEEE_NAN == ret);
+        /* not IEEE754, but check for 0 anyway */
+	TEST_ASSERT_EQUAL_INT64( 0, (long)fp );
 }
 
 TEST_GROUP_RUNNER(ieee754io) {


=====================================
tests/wscript
=====================================
--- a/tests/wscript
+++ b/tests/wscript
@@ -107,5 +107,5 @@ def build(ctx):
             "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)
+    # 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/947849ef6230e0ee01d8b947dc67b74e37a7197e...71c668856bc4c62676e046d83dc1e8d5248cd43c
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ntpsec.org/pipermail/vc/attachments/20170404/63d7accd/attachment.html>


More information about the vc mailing list