[ovs-dev] [PATCH] test-hash: Fix unaligned pointer value error.

Joe Stringer joe at ovn.org
Fri May 26 21:11:31 UTC 2017


Clang 4.0 complains:

../tests/test-hash.c:160:16: error: taking address of packed member 'b' of
class or structure 'offset_ovs_u128' may result in an unaligned pointer value
      [-Werror,-Waddress-of-packed-member]
        in0 = &in0_data.b;

Set the bit in the aligned u128 first then copy the contents into the
offset u128 so that we don't have to take the address of the non-aligned
u128 and pass it to set_bit128.

For the 256byte_hash, fix it up so that it's actually testing the 256B
hash inside a 32-bit offset u128 as well.

Suggested-by: Ben Pfaff <blp at ovn.org>
Signed-off-by: Joe Stringer <joe at ovn.org>
---
 tests/test-hash.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/tests/test-hash.c b/tests/test-hash.c
index d1beead36ed5..5d3f8ea43f65 100644
--- a/tests/test-hash.c
+++ b/tests/test-hash.c
@@ -153,14 +153,13 @@ check_hash_bytes128(void (*hash)(const void *, size_t, uint32_t, ovs_u128 *),
         OVS_PACKED(struct offset_ovs_u128 {
             uint32_t a;
             ovs_u128 b;
-        }) in0_data;
-        ovs_u128 *in0, in1;
+        }) in0;
+        ovs_u128 in1;
         ovs_u128 out0, out1;
 
-        in0 = &in0_data.b;
-        set_bit128(in0, i, n_bits);
         set_bit128(&in1, i, n_bits);
-        hash(in0, sizeof(ovs_u128), 0, &out0);
+        in0.b = in1;
+        hash(&in0.b, sizeof(ovs_u128), 0, &out0);
         hash(&in1, sizeof(ovs_u128), 0, &out1);
         if (!ovs_u128_equals(out0, out1)) {
             printf("%s hash not the same for non-64 aligned data "
@@ -205,14 +204,15 @@ check_256byte_hash(void (*hash)(const void *, size_t, uint32_t, ovs_u128 *),
         OVS_PACKED(struct offset_ovs_u128 {
             uint32_t a;
             ovs_u128 b[16];
-        }) in0_data;
-        ovs_u128 *in0, in1[16];
+        }) in0;
+        ovs_u128 in1[16];
         ovs_u128 out0, out1;
 
-        in0 = in0_data.b;
-        set_bit128(in0, i, n_bits);
         set_bit128(in1, i, n_bits);
-        hash(in0, sizeof(ovs_u128) * 16, 0, &out0);
+        for (j = 0; j < 16; j++) {
+            in0.b[j] = in1[j];
+        }
+        hash(&in0.b, sizeof(ovs_u128) * 16, 0, &out0);
         hash(in1, sizeof(ovs_u128) * 16, 0, &out1);
         if (!ovs_u128_equals(out0, out1)) {
             printf("%s hash not the same for non-64 aligned data "
-- 
2.11.1



More information about the dev mailing list