From patchwork Tue Nov 1 13:07:48 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Erico Nunes X-Patchwork-Id: 689895 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) by ozlabs.org (Postfix) with ESMTP id 3t7WkR0K03z9t0q; Wed, 2 Nov 2016 00:08:15 +1100 (AEDT) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.76) (envelope-from ) id 1c1YnV-0001py-3b; Tue, 01 Nov 2016 13:08:13 +0000 Received: from mx1.redhat.com ([209.132.183.28]) by huckleberry.canonical.com with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.76) (envelope-from ) id 1c1YnL-0001oF-8i for fwts-devel@lists.ubuntu.com; Tue, 01 Nov 2016 13:08:03 +0000 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 066A361E5F for ; Tue, 1 Nov 2016 13:08:02 +0000 (UTC) Received: from ernunes.brq.redhat.com (dhcp-30-128.brq.redhat.com [10.34.30.128]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id uA1D7xVZ025828; Tue, 1 Nov 2016 09:08:01 -0400 From: Erico Nunes To: fwts-devel@lists.ubuntu.com Subject: [PATCH 2/3] fwts_hwinfo.c: fix strict-aliasing error with old gcc Date: Tue, 1 Nov 2016 14:07:48 +0100 Message-Id: <1478005669-3752-2-git-send-email-ernunes@redhat.com> In-Reply-To: <1478005669-3752-1-git-send-email-ernunes@redhat.com> References: <1478005669-3752-1-git-send-email-ernunes@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Tue, 01 Nov 2016 13:08:02 +0000 (UTC) X-BeenThere: fwts-devel@lists.ubuntu.com X-Mailman-Version: 2.1.14 Precedence: list List-Id: Firmware Test Suite Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: fwts-devel-bounces@lists.ubuntu.com Sender: fwts-devel-bounces@lists.ubuntu.com When building the current fwts release with an older gcc 4.4, we get the following error due to breaking strict-aliasing rules, despite the comment in the code which states there has been an attempt to solve this in the past: fwts_hwinfo.c: In function ‘fwts_hwinfo_get’: fwts_hwinfo.c:420: error: dereferencing pointer ‘sockaddr’ does break strict-aliasing rules fwts_hwinfo.c:419: note: initialized from here This new attempt to fix it just makes a copy of the whole "buf.ifr_addr" to into sockaddr to avoid running into any strict-aliasing problems. As there are still supported systems with older gcc versions, such as RHEL6, it is interesting to have this fixed. This has been built and tested with gcc 6.2.1, gcc 4.8.5 and gcc 4.4.7. Signed-off-by: Erico Nunes Acked-by: Colin Ian King Acked-by: Alex Hung --- src/lib/src/fwts_hwinfo.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/lib/src/fwts_hwinfo.c b/src/lib/src/fwts_hwinfo.c index 083b94d..d749cf2 100644 --- a/src/lib/src/fwts_hwinfo.c +++ b/src/lib/src/fwts_hwinfo.c @@ -381,7 +381,7 @@ static int fwts_hwinfo_net_get( while ((d = readdir(dp)) != NULL) { struct ifreq buf; - struct sockaddr_in *sockaddr; + struct sockaddr_in sockaddr; fwts_net_config *net_config; if (d->d_name[0] == '.') @@ -416,8 +416,8 @@ static int fwts_hwinfo_net_get( fwts_log_error(fw, "Cannot get address for device %s.", d->d_name); } /* GCC 4.4 is rather overly pedantic in strict aliasing warnings, this avoids it */ - sockaddr = (struct sockaddr_in *)&buf.ifr_addr; - net_config->addr = strdup(inet_ntoa((struct in_addr)sockaddr->sin_addr)); + memcpy(&sockaddr, &buf.ifr_addr, sizeof(sockaddr)); + net_config->addr = strdup(inet_ntoa((struct in_addr)sockaddr.sin_addr)); if (net_config->addr == NULL) { fwts_log_error(fw, "Cannot allocate net config H/W address."); fwts_hwinfo_net_free(net_config);