summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoe Stringer <joe@ovn.org>2017-05-26 14:11:31 -0700
committerBen Pfaff <blp@ovn.org>2018-10-16 15:12:17 -0700
commit84b0df9ab18c381e53040eb64c14edf992b6ddeb (patch)
tree64a3b197475e1de6afc05b9d045aa43a96cece54
parentea74b10c0838f156a98bac8c43ee79628b8fc0ce (diff)
downloadopenvswitch-84b0df9ab18c381e53040eb64c14edf992b6ddeb.tar.gz
test-hash: Fix unaligned pointer value error.
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> Acked-by: Ben Pfaff <blp@ovn.org>
-rw-r--r--tests/test-hash.c20
1 files changed, 10 insertions, 10 deletions
diff --git a/tests/test-hash.c b/tests/test-hash.c
index 67a1f6c89..cf90dbf3a 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 "