[ovs-dev] [PATCH 4/5] test-hash: Fix unaligned pointers.
Joe Stringer
joe at ovn.org
Thu May 25 20:18:21 UTC 2017
On 25 May 2017 at 10:42, Ben Pfaff <blp at ovn.org> wrote:
> On Tue, May 23, 2017 at 04:02:15PM -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;
>>
>> Rework the 128-bit hash test to have a separate function for setting
>> bits in the 32-bit offset u128 structure.
>>
>> Signed-off-by: Joe Stringer <joe at ovn.org>
>
> How about something like this, to reduce code duplication? I have not
> tested it with Clang 4.0.
>
> diff --git a/tests/test-hash.c b/tests/test-hash.c
> index d1beead36ed5..f02f0218c71f 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 "
Thanks, this looks like a much better approach and it satisfies clang
4.0. Will you propose this formally or shall I? The 256B version needs
a slight variation on this as well.
More information about the dev
mailing list