diff mbox

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

Message ID 20170526211131.12341-1-joe@ovn.org
State Accepted
Headers show

Commit Message

Joe Stringer May 26, 2017, 9:11 p.m. UTC
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@ovn.org>
Signed-off-by: Joe Stringer <joe@ovn.org>
---
 tests/test-hash.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

Comments

Ben Pfaff June 6, 2017, 11:13 p.m. UTC | #1
On Fri, May 26, 2017 at 02:11:31PM -0700, Joe Stringer wrote:
> 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@ovn.org>
> Signed-off-by: Joe Stringer <joe@ovn.org>

Thanks!

Acked-by: Ben Pfaff <blp@ovn.org>
Joe Stringer June 7, 2017, 10:36 p.m. UTC | #2
On 6 June 2017 at 16:13, Ben Pfaff <blp@ovn.org> wrote:
> On Fri, May 26, 2017 at 02:11:31PM -0700, Joe Stringer wrote:
>> 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@ovn.org>
>> Signed-off-by: Joe Stringer <joe@ovn.org>
>
> Thanks!
>
> Acked-by: Ben Pfaff <blp@ovn.org>

Thanks, applied.
diff mbox

Patch

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 "