]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Add more static asserts, and byte order inverions for floats
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Tue, 16 May 2017 01:59:16 +0000 (21:59 -0400)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Tue, 16 May 2017 01:59:16 +0000 (21:59 -0400)
src/lib/util/value.c

index 1c20bab203b592590ed657155f95c53b14f8277c..5bf7293c7de388ca3de536590d19191060913e93 100644 (file)
@@ -103,6 +103,7 @@ static_assert(SIZEOF_MEMBER(fr_value_box_t, datum.ifid) == 8,
              "datum.ifid has unexpected length");
 static_assert(SIZEOF_MEMBER(fr_value_box_t, datum.ether) == 6,
              "datum.ether has unexpected length");
+
 static_assert(SIZEOF_MEMBER(fr_value_box_t, datum.boolean) == 1,
              "datum.boolean has unexpected length");
 static_assert(SIZEOF_MEMBER(fr_value_box_t, datum.uint8) == 1,
@@ -113,9 +114,20 @@ static_assert(SIZEOF_MEMBER(fr_value_box_t, datum.uint32) == 4,
              "datum.uint32 has unexpected length");
 static_assert(SIZEOF_MEMBER(fr_value_box_t, datum.uint64) == 8,
              "datum.uint64 has unexpected length");
+
+static_assert(SIZEOF_MEMBER(fr_value_box_t, datum.int8) == 1,
+             "datum.int16 has unexpected length");
+static_assert(SIZEOF_MEMBER(fr_value_box_t, datum.int16) == 2,
+             "datum.int16 has unexpected length");
 static_assert(SIZEOF_MEMBER(fr_value_box_t, datum.int32) == 4,
              "datum.int32 has unexpected length");
+static_assert(SIZEOF_MEMBER(fr_value_box_t, datum.int64) == 8,
+             "datum.int64 has unexpected length");
 
+static_assert(SIZEOF_MEMBER(fr_value_box_t, datum.float32) == 4,
+             "datum.float32 has unexpected length");
+static_assert(SIZEOF_MEMBER(fr_value_box_t, datum.float64) == 8,
+             "datum.float64 has unexpected length");
 
 /** How many uint8s wide each of the value data fields are
  *
@@ -855,7 +867,6 @@ int fr_value_box_hton(fr_value_box_t *dst, fr_value_box_t const *src)
 {
        if (!fr_cond_assert(src->type != FR_TYPE_INVALID)) return -1;
 
-
        switch (src->type) {
        /* 2 uint8 uint32s */
        case FR_TYPE_UINT16:
@@ -873,15 +884,23 @@ int fr_value_box_hton(fr_value_box_t *dst, fr_value_box_t const *src)
                break;
 
        case FR_TYPE_INT16:
-               dst->datum.int16 = htons((uint16_t) src->datum.int16);
+               dst->datum.uint16 = htons(src->datum.uint16);   /* Not a typo, uses the union to avoid memcpy */
                break;
 
        case FR_TYPE_INT32:
-               dst->datum.int32 = htonl((uint32_t) src->datum.int32);
+               dst->datum.uint32 = htonl(src->datum.uint32);   /* Not a typo, uses the union to avoid memcpy */
                break;
 
        case FR_TYPE_INT64:
-               dst->datum.int64 = htonll((uint64_t) src->datum.int64);
+               dst->datum.uint64 = htonll(src->datum.uint64);  /* Not a typo, uses the union to avoid memcpy */
+               break;
+
+       case FR_TYPE_FLOAT32:
+               dst->datum.uint32 = htonl(dst->datum.uint32);   /* Not a typo, uses the union to avoid memcpy */
+               break;
+
+       case FR_TYPE_FLOAT64:
+               dst->datum.uint64 = htonll(dst->datum.uint64);  /* Not a typo, uses the union to avoid memcpy */
                break;
 
        case FR_TYPE_DATE: