From patchwork Fri May 26 21:11:31 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joe Stringer X-Patchwork-Id: 767565 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from mail.linuxfoundation.org (mail.linuxfoundation.org [140.211.169.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3wZJkY458fz9rxm for ; Sat, 27 May 2017 07:12:53 +1000 (AEST) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 0B9C1C0C; Fri, 26 May 2017 21:12:35 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@mail.linuxfoundation.org Received: from smtp1.linuxfoundation.org (smtp1.linux-foundation.org [172.17.192.35]) by mail.linuxfoundation.org (Postfix) with ESMTPS id 9970CBED for ; Fri, 26 May 2017 21:12:33 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net [217.70.183.197]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 7BD241D7 for ; Fri, 26 May 2017 21:12:32 +0000 (UTC) Received: from mfilter17-d.gandi.net (mfilter17-d.gandi.net [217.70.178.145]) by relay5-d.mail.gandi.net (Postfix) with ESMTP id 4833B41C086; Fri, 26 May 2017 23:12:31 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at mfilter17-d.gandi.net Received: from relay5-d.mail.gandi.net ([IPv6:::ffff:217.70.183.197]) by mfilter17-d.gandi.net (mfilter17-d.gandi.net [::ffff:10.0.15.180]) (amavisd-new, port 10024) with ESMTP id XganO0g3h4ew; Fri, 26 May 2017 23:12:29 +0200 (CEST) X-Originating-IP: 208.91.1.34 Received: from carno.eng.vmware.com (unknown [208.91.1.34]) (Authenticated sender: joe@ovn.org) by relay5-d.mail.gandi.net (Postfix) with ESMTPSA id 198A441C07C; Fri, 26 May 2017 23:12:28 +0200 (CEST) From: Joe Stringer To: dev@openvswitch.org Date: Fri, 26 May 2017 14:11:31 -0700 Message-Id: <20170526211131.12341-1-joe@ovn.org> X-Mailer: git-send-email 2.11.1 X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Subject: [ovs-dev] [PATCH] test-hash: Fix unaligned pointer value error. X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: ovs-dev-bounces@openvswitch.org Errors-To: ovs-dev-bounces@openvswitch.org 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 Signed-off-by: Joe Stringer Acked-by: Ben Pfaff --- 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 "