[Git][NTPsec/ntpsec][master] 7 commits: binio: remove unused, and broken, get_msb_long().

Gary E. Miller gitlab at mg.gitlab.com
Sat May 13 01:31:25 UTC 2017


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


Commits:
cb08c3b2 by Gary E. Miller at 2017-05-12T17:40:37-07:00
binio: remove unused, and broken, get_msb_long().

Also remove the associated tests that showed it was broken.

- - - - -
c821210e by Gary E. Miller at 2017-05-12T17:44:20-07:00
binio: remove unused put_lsb_long()

- - - - -
41ecb6fc by Gary E. Miller at 2017-05-12T17:47:47-07:00
binio: remove unused put_msb_short().

- - - - -
6c8e648e by Gary E. Miller at 2017-05-12T17:49:43-07:00
binio: remove unused put_msb_long()

- - - - -
f5242d6f by Gary E. Miller at 2017-05-12T18:09:43-07:00
binio: rename get_lsb_short() to get_lsb_int16()

This gets rid of a macro and make the name better reflect the
function.

All tests pass.

- - - - -
aeb6e44d by Gary E. Miller at 2017-05-12T18:25:22-07:00
tests: add tests for get_lsb_uint16() and get_lsb_uint32().

- - - - -
9d31f8bf by Gary E. Miller at 2017-05-12T18:29:29-07:00
binio: simplify get_lsb_int16(), all tests pass.

Now that get_lsb_short() is get_lsb_int16() we don't need to be
carefull in case short is not 16 bits.

- - - - -


6 changed files:

- include/binio.h
- libparse/binio.c
- libparse/clk_meinberg.c
- libparse/data_mbg.c
- ntpd/refclock_generic.c
- tests/libparse/binio.c


Changes:

=====================================
include/binio.h
=====================================
--- a/include/binio.h
+++ b/include/binio.h
@@ -10,19 +10,14 @@
 
 #include "ntp_stdlib.h"
 
-long get_lsb_short (unsigned char **);
+int16_t get_lsb_int16 (unsigned char **);
 void put_lsb_short (unsigned char **, long);
 int32_t get_lsb_int32 (unsigned char **);
-void put_lsb_long (unsigned char **, long);
 
-#define get_lsb_int16( _x_ )   ((int16_t) get_lsb_short( _x_ ))
-#define get_lsb_uint16( _x_ )  ((uint16_t) get_lsb_short( _x_ ))
+#define get_lsb_uint16( _x_ )  ((uint16_t) get_lsb_int16( _x_ ))
 #define get_lsb_uint32( _x_ )  ((uint32_t) get_lsb_int32( _x_ ))
 
 long get_msb_short (unsigned char **);
-void put_msb_short (unsigned char **, long);
-long get_msb_long (unsigned char **);
-void put_msb_long (unsigned char **, long);
 
 #endif
 /*


=====================================
libparse/binio.c
=====================================
--- a/libparse/binio.c
+++ b/libparse/binio.c
@@ -9,17 +9,17 @@
 #include "config.h"
 #include "binio.h"
 
-long
-get_lsb_short(
+int16_t
+get_lsb_int16(
 	unsigned char **bufpp
 	)
 {
-  long retval;
+  int16_t retval;
 
   retval  = *((*bufpp)++);
   retval |= *((*bufpp)++) << 8;
 
-  return (retval & 0x8000) ? (~0xFFFF | retval) : retval;
+  return retval;
 }
 
 void
@@ -47,18 +47,6 @@ get_lsb_int32(
   return retval;
 }
 
-void
-put_lsb_long(
-	unsigned char **bufpp,
-	long val
-	)
-{
-  *((*bufpp)++) = (unsigned char)(val         & 0xFF);
-  *((*bufpp)++) = (unsigned char)((val >> 8)  & 0xFF);
-  *((*bufpp)++) = (unsigned char)((val >> 16) & 0xFF);
-  *((*bufpp)++) = (unsigned char)((val >> 24) & 0xFF);
-}
-
 long
 get_msb_short(
 	unsigned char **bufpp
@@ -72,43 +60,6 @@ get_msb_short(
   return (retval & 0x8000) ? (~0xFFFF | retval) : retval;
 }
 
-void
-put_msb_short(
-	unsigned char **bufpp,
-	long val
-	)
-{
-  *((*bufpp)++) = (unsigned char)((val >> 8) & 0xFF);
-  *((*bufpp)++) = (unsigned char)( val       & 0xFF);
-}
-
-long
-get_msb_long(
-	unsigned char **bufpp
-	)
-{
-  long retval;
-
-  retval  = (long)*((*bufpp)++) << 24;
-  retval |= *((*bufpp)++) << 16;
-  retval |= *((*bufpp)++) << 8;
-  retval |= *((*bufpp)++);
-
-  return retval;
-}
-
-void
-put_msb_long(
-	unsigned char **bufpp,
-	long val
-	)
-{
-  *((*bufpp)++) = (unsigned char)((val >> 24) & 0xFF);
-  *((*bufpp)++) = (unsigned char)((val >> 16) & 0xFF);
-  *((*bufpp)++) = (unsigned char)((val >> 8 ) & 0xFF);
-  *((*bufpp)++) = (unsigned char)( val        & 0xFF);
-}
-
 /*
  * binio.c,v
  * Revision 4.2  1999/02/21 12:17:34  kardel


=====================================
libparse/clk_meinberg.c
=====================================
--- a/libparse/clk_meinberg.c
+++ b/libparse/clk_meinberg.c
@@ -136,10 +136,10 @@ get_mbg_header(
 	       GPS_MSG_HDR *headerp
 	       )
 {
-  headerp->cmd = (GPS_CMD) get_lsb_short(bufpp);
+  headerp->cmd = (GPS_CMD) get_lsb_uint16(bufpp);
   headerp->len = get_lsb_uint16(bufpp);
-  headerp->data_csum = (CSUM) get_lsb_short(bufpp);
-  headerp->hdr_csum  = (CSUM) get_lsb_short(bufpp);
+  headerp->data_csum = (CSUM) get_lsb_uint16(bufpp);
+  headerp->hdr_csum  = (CSUM) get_lsb_uint16(bufpp);
 }
 
 static struct format meinberg_fmt[] =


=====================================
libparse/data_mbg.c
=====================================
--- a/libparse/data_mbg.c
+++ b/libparse/data_mbg.c
@@ -55,7 +55,7 @@ get_mbg_ascii_msg(
 	ASCII_MSG *ascii_msgp
 	)
 {
-  ascii_msgp->csum  = (CSUM) get_lsb_short(bufpp);
+  ascii_msgp->csum  = (CSUM) get_lsb_uint16(bufpp);
   ascii_msgp->valid = get_lsb_int16(bufpp);
   memcpy(ascii_msgp->s, *bufpp, sizeof(ascii_msgp->s));
   *bufpp += sizeof(ascii_msgp->s);
@@ -67,7 +67,7 @@ get_mbg_svno(
 	SVNO *svnop
 	)
 {
-  *svnop = (SVNO) get_lsb_short(bufpp);
+  *svnop = (SVNO) get_lsb_uint16(bufpp);
 }
 
 void
@@ -76,7 +76,7 @@ get_mbg_health(
 	HEALTH *healthp
 	)
 {
-  *healthp = (HEALTH) get_lsb_short(bufpp);
+  *healthp = (HEALTH) get_lsb_uint16(bufpp);
 }
 
 void
@@ -85,7 +85,7 @@ get_mbg_cfg(
 	CFG *cfgp
 	)
 {
-  *cfgp = (CFG) get_lsb_short(bufpp);
+  *cfgp = (CFG) get_lsb_uint16(bufpp);
 }
 
 void
@@ -268,7 +268,7 @@ get_mbg_cfgh(
 {
   int i;
 
-  cfghp->csum = (CSUM) get_lsb_short(buffpp);
+  cfghp->csum = (CSUM) get_lsb_uint16(buffpp);
   cfghp->valid = get_lsb_int16(buffpp);
   get_mbg_tgps(buffpp, &cfghp->tot_51);
   get_mbg_tgps(buffpp, &cfghp->tot_63);
@@ -291,7 +291,7 @@ get_mbg_utc(
 	UTC *utcp
 	)
 {
-  utcp->csum  = (CSUM) get_lsb_short(buffpp);
+  utcp->csum  = (CSUM) get_lsb_uint16(buffpp);
   utcp->valid = get_lsb_int16(buffpp);
 
   get_mbg_tgps(buffpp, &utcp->t0t);
@@ -393,13 +393,13 @@ get_mbg_eph(
 	EPH *ephp
 	)
 {
-  ephp->csum   = (CSUM) get_lsb_short(buffpp);
+  ephp->csum   = (CSUM) get_lsb_uint16(buffpp);
   ephp->valid  = get_lsb_int16(buffpp);
 
-  ephp->health = (HEALTH) get_lsb_short(buffpp);
-  ephp->IODC   = (IOD) get_lsb_short(buffpp);
-  ephp->IODE2  = (IOD) get_lsb_short(buffpp);
-  ephp->IODE3  = (IOD) get_lsb_short(buffpp);
+  ephp->health = (HEALTH) get_lsb_uint16(buffpp);
+  ephp->IODC   = (IOD) get_lsb_uint16(buffpp);
+  ephp->IODE2  = (IOD) get_lsb_uint16(buffpp);
+  ephp->IODE3  = (IOD) get_lsb_uint16(buffpp);
 
   get_mbg_tgps(buffpp, &ephp->tt);
   get_mbg_tgps(buffpp, &ephp->t0c);
@@ -438,10 +438,10 @@ get_mbg_alm(
 	ALM *almp
 	)
 {
-  almp->csum   = (CSUM) get_lsb_short(buffpp);
+  almp->csum   = (CSUM) get_lsb_uint16(buffpp);
   almp->valid  = get_lsb_int16(buffpp);
 
-  almp->health = (HEALTH) get_lsb_short(buffpp);
+  almp->health = (HEALTH) get_lsb_uint16(buffpp);
   get_mbg_tgps(buffpp, &almp->t0a);
 
 
@@ -463,7 +463,7 @@ get_mbg_iono(
 	IONO *ionop
 	)
 {
-  ionop->csum   = (CSUM) get_lsb_short(buffpp);
+  ionop->csum   = (CSUM) get_lsb_uint16(buffpp);
   ionop->valid  = get_lsb_int16(buffpp);
 
   FETCH_DOUBLE(buffpp, &ionop->alpha_0);


=====================================
ntpd/refclock_generic.c
=====================================
--- a/ntpd/refclock_generic.c
+++ b/ntpd/refclock_generic.c
@@ -3867,7 +3867,7 @@ gps16x_message(
 					char buffer[512];
 					char *p, *b;
 
-					status = (BVAR_STAT) get_lsb_short(&bufp);
+					status = (BVAR_STAT)get_lsb_uint16(&bufp);
 					p = b = buffer;
 					p = ap(buffer, sizeof(buffer), p,
 					    "meinberg_gps_status=\"[0x%04x] ",


=====================================
tests/libparse/binio.c
=====================================
--- a/tests/libparse/binio.c
+++ b/tests/libparse/binio.c
@@ -17,54 +17,54 @@ TEST_SETUP(binio) {}
 
 TEST_TEAR_DOWN(binio) {}
 
-/* LSB tests */
+/* LSB int tests */
 
-TEST(binio, get_lsb_short0) {
+TEST(binio, get_lsb_int160) {
         long ret;
         unsigned char zero[2] = { 0, 0};
         unsigned char *bp = &zero[0];
 
-        ret = get_lsb_short( &bp);
+        ret = get_lsb_int16( &bp);
 
         TEST_ASSERT_EQUAL_INT64( 0, ret );
 }
 
-TEST(binio, get_lsb_short1) {
+TEST(binio, get_lsb_int161) {
         long ret;
         unsigned char zero[2] = { 1, 2};
         unsigned char *bp = &zero[0];
 
-        ret = get_lsb_short( &bp);
+        ret = get_lsb_int16( &bp);
 
         TEST_ASSERT_EQUAL_HEX64( 0x0201UL, ret );
 }
 
-TEST(binio, get_lsb_short2) {
+TEST(binio, get_lsb_int162) {
         long ret;
         unsigned char zero[2] = { 2, 1};
         unsigned char *bp = &zero[0];
 
-        ret = get_lsb_short( &bp);
+        ret = get_lsb_int16( &bp);
 
         TEST_ASSERT_EQUAL_HEX64( 0x0102UL, ret );
 }
 
-TEST(binio, get_lsb_short3) {
+TEST(binio, get_lsb_int163) {
         long ret;
         unsigned char zero[2] = { 0xff, 0xff};
         unsigned char *bp = &zero[0];
 
-        ret = get_lsb_short( &bp);
+        ret = get_lsb_int16( &bp);
 
         TEST_ASSERT_EQUAL_HEX64( -1L, ret );
 }
 
-TEST(binio, get_lsb_short4) {
+TEST(binio, get_lsb_int164) {
         long ret;
         unsigned char zero[2] = { 0, 0x80};
         unsigned char *bp = &zero[0];
 
-        ret = get_lsb_short( &bp);
+        ret = get_lsb_int16( &bp);
 
         TEST_ASSERT_EQUAL_HEX64( -0x8000L, ret );
 }
@@ -124,120 +124,172 @@ TEST(binio, get_lsb_int324) {
         TEST_ASSERT_EQUAL_HEX32( 0x080000000UL, ret );
 }
 
-/* MSB tests */
+/* LSB uint tests */
 
-TEST(binio, get_msb_short0) {
+TEST(binio, get_lsb_uint160) {
         long ret;
         unsigned char zero[2] = { 0, 0};
         unsigned char *bp = &zero[0];
 
-        ret = get_msb_short( &bp);
+        ret = get_lsb_uint16( &bp);
 
         TEST_ASSERT_EQUAL_INT64( 0, ret );
 }
 
-TEST(binio, get_msb_short1) {
+TEST(binio, get_lsb_uint161) {
         long ret;
-        unsigned char zero[2] = { 2, 1};
+        unsigned char zero[2] = { 1, 2};
         unsigned char *bp = &zero[0];
 
-        ret = get_msb_short( &bp);
+        ret = get_lsb_uint16( &bp);
 
         TEST_ASSERT_EQUAL_HEX64( 0x0201UL, ret );
 }
 
-TEST(binio, get_msb_short2) {
+TEST(binio, get_lsb_uint162) {
         long ret;
-        unsigned char zero[2] = { 1, 2};
+        unsigned char zero[2] = { 2, 1};
         unsigned char *bp = &zero[0];
 
-        ret = get_msb_short( &bp);
+        ret = get_lsb_uint16( &bp);
 
         TEST_ASSERT_EQUAL_HEX64( 0x0102UL, ret );
 }
 
-TEST(binio, get_msb_short3) {
+TEST(binio, get_lsb_uint163) {
         long ret;
         unsigned char zero[2] = { 0xff, 0xff};
         unsigned char *bp = &zero[0];
 
-        ret = get_msb_short( &bp);
+        ret = get_lsb_uint16( &bp);
 
-        TEST_ASSERT_EQUAL_HEX64( -1L, ret );
+        TEST_ASSERT_EQUAL_HEX64( 0x0ffffUL, ret );
 }
 
-TEST(binio, get_msb_short4) {
+TEST(binio, get_lsb_uint164) {
         long ret;
-        unsigned char zero[2] = { 0x80, 0};
+        unsigned char zero[2] = { 0, 0x80};
         unsigned char *bp = &zero[0];
 
-        ret = get_msb_short( &bp);
+        ret = get_lsb_uint16( &bp);
 
-        TEST_ASSERT_EQUAL_HEX64( -0x8000L, ret );
+        TEST_ASSERT_EQUAL_HEX64( 0x8000L, ret );
 }
 
 
-TEST(binio, get_msb_long0) {
-        long ret;
+TEST(binio, get_lsb_uint320) {
+        uint32_t ret;
         unsigned char zero[4] = { 0, 0, 0, 0};
         unsigned char *bp = &zero[0];
 
-        ret = get_msb_long( &bp);
+        ret = get_lsb_uint32( &bp);
 
-        TEST_ASSERT_EQUAL_UINT64( 0, ret );
+        TEST_ASSERT_EQUAL_UINT32( 0, ret );
 }
 
 
-TEST(binio, get_msb_long1) {
-        long ret;
+TEST(binio, get_lsb_uint321) {
+        uint32_t ret;
+        unsigned char zero[4] = { 1, 2, 3, 4};
+        unsigned char *bp = &zero[0];
+
+        ret = get_lsb_uint32( &bp);
+
+        TEST_ASSERT_EQUAL_HEX32( 0x04030201UL, ret );
+}
+
+
+TEST(binio, get_lsb_uint322) {
+        uint32_t ret;
         unsigned char zero[4] = { 4, 3, 2, 1};
         unsigned char *bp = &zero[0];
 
-        ret = get_msb_long( &bp);
+        ret = get_lsb_uint32( &bp);
 
-        TEST_ASSERT_EQUAL_HEX64( 0x04030201UL, ret );
+        TEST_ASSERT_EQUAL_HEX32( 0x01020304UL, ret );
 }
 
 
-TEST(binio, get_msb_long2) {
+TEST(binio, get_lsb_uint323) {
+        uint32_t ret;
+        unsigned char zero[4] = { 0xff, 0xff, 0xff, 0xff};
+        unsigned char *bp = &zero[0];
+
+        ret = get_lsb_uint32( &bp);
+
+        TEST_ASSERT_EQUAL_HEX32( 0x0FFFFFFFFUL, ret );
+}
+
+
+TEST(binio, get_lsb_uint324) {
+        uint32_t ret;
+        unsigned char zero[4] = { 0, 0, 0, 0x80};
+        unsigned char *bp = &zero[0];
+
+        ret = get_lsb_uint32( &bp);
+
+        TEST_ASSERT_EQUAL_HEX32( 0x080000000UL, ret );
+}
+
+/* MSB tests */
+
+TEST(binio, get_msb_short0) {
         long ret;
-        unsigned char zero[4] = { 1, 2, 3, 4};
+        unsigned char zero[2] = { 0, 0};
         unsigned char *bp = &zero[0];
 
-        ret = get_msb_long( &bp);
+        ret = get_msb_short( &bp);
 
-        TEST_ASSERT_EQUAL_HEX64( 0x01020304UL, ret );
+        TEST_ASSERT_EQUAL_INT64( 0, ret );
 }
 
+TEST(binio, get_msb_short1) {
+        long ret;
+        unsigned char zero[2] = { 2, 1};
+        unsigned char *bp = &zero[0];
+
+        ret = get_msb_short( &bp);
 
-TEST(binio, get_msb_long3) {
+        TEST_ASSERT_EQUAL_HEX64( 0x0201UL, ret );
+}
+
+TEST(binio, get_msb_short2) {
         long ret;
-        unsigned char zero[4] = { 0xff, 0xff, 0xff, 0xff};
+        unsigned char zero[2] = { 1, 2};
         unsigned char *bp = &zero[0];
 
-        ret = get_msb_long( &bp);
+        ret = get_msb_short( &bp);
 
-        TEST_ASSERT_EQUAL_HEX64( -1L, ret );
+        TEST_ASSERT_EQUAL_HEX64( 0x0102UL, ret );
 }
 
+TEST(binio, get_msb_short3) {
+        long ret;
+        unsigned char zero[2] = { 0xff, 0xff};
+        unsigned char *bp = &zero[0];
+
+        ret = get_msb_short( &bp);
+
+        TEST_ASSERT_EQUAL_HEX64( -1L, ret );
+}
 
-TEST(binio, get_msb_long4) {
+TEST(binio, get_msb_short4) {
         long ret;
-        unsigned char zero[4] = { 0x80, 0, 0, 0};
+        unsigned char zero[2] = { 0x80, 0};
         unsigned char *bp = &zero[0];
 
-        ret = get_msb_long( &bp);
+        ret = get_msb_short( &bp);
 
-        TEST_ASSERT_EQUAL_HEX64( -0x080000000L, ret );
+        TEST_ASSERT_EQUAL_HEX64( -0x8000L, ret );
 }
 
 TEST_GROUP_RUNNER(binio) {
-        /* LSB tests */
-        RUN_TEST_CASE(binio, get_lsb_short0);
-        RUN_TEST_CASE(binio, get_lsb_short1);
-        RUN_TEST_CASE(binio, get_lsb_short2);
-        RUN_TEST_CASE(binio, get_lsb_short3);
-        RUN_TEST_CASE(binio, get_lsb_short4);
+        /* LSB int tests */
+        RUN_TEST_CASE(binio, get_lsb_int160);
+        RUN_TEST_CASE(binio, get_lsb_int161);
+        RUN_TEST_CASE(binio, get_lsb_int162);
+        RUN_TEST_CASE(binio, get_lsb_int163);
+        RUN_TEST_CASE(binio, get_lsb_int164);
 
         RUN_TEST_CASE(binio, get_lsb_int320);
         RUN_TEST_CASE(binio, get_lsb_int321);
@@ -245,18 +297,23 @@ TEST_GROUP_RUNNER(binio) {
         RUN_TEST_CASE(binio, get_lsb_int323);
         RUN_TEST_CASE(binio, get_lsb_int324);
 
+        /* LSB uint tests */
+        RUN_TEST_CASE(binio, get_lsb_uint160);
+        RUN_TEST_CASE(binio, get_lsb_uint161);
+        RUN_TEST_CASE(binio, get_lsb_uint162);
+        RUN_TEST_CASE(binio, get_lsb_uint163);
+        RUN_TEST_CASE(binio, get_lsb_uint164);
+
+        RUN_TEST_CASE(binio, get_lsb_uint320);
+        RUN_TEST_CASE(binio, get_lsb_uint321);
+        RUN_TEST_CASE(binio, get_lsb_uint322);
+        RUN_TEST_CASE(binio, get_lsb_uint323);
+        RUN_TEST_CASE(binio, get_lsb_uint324);
+
         /* MSB tests */
         RUN_TEST_CASE(binio, get_msb_short0);
         RUN_TEST_CASE(binio, get_msb_short1);
         RUN_TEST_CASE(binio, get_msb_short2);
         RUN_TEST_CASE(binio, get_msb_short3);
         RUN_TEST_CASE(binio, get_msb_short4);
-
-        RUN_TEST_CASE(binio, get_msb_long0);
-        RUN_TEST_CASE(binio, get_msb_long1);
-        RUN_TEST_CASE(binio, get_msb_long2);
-        /* next two tests are good, but the code they test is bad
-        RUN_TEST_CASE(binio, get_msb_long3);
-        RUN_TEST_CASE(binio, get_msb_long4);
-        */
 }



View it on GitLab: https://gitlab.com/NTPsec/ntpsec/compare/a88032ec1272a904eb3837a5875d44d7fe0e3abe...9d31f8bf9097063c2b447d4e6a17a6d6857130bb

---
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/compare/a88032ec1272a904eb3837a5875d44d7fe0e3abe...9d31f8bf9097063c2b447d4e6a17a6d6857130bb
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/20170513/5f63b2e1/attachment.html>


More information about the vc mailing list