ACK: [PATCH] lib: fwts_hwinfo.c: Fix strict aliasing build failure on Lucid (LP: #1251587)
Alex Hung
alex.hung at canonical.com
Wed Nov 27 02:51:24 UTC 2013
On 11/15/2013 07:01 PM, Colin King wrote:
> From: Colin Ian King <colin.king at canonical.com>
>
> With gcc gcc version 4.4.3 (Ubuntu 4.4.3-4ubuntu5.1) we are getting strict
> aliasing warnings causing a build failure:
>
> fwts_hwinfo.c: In function 'fwts_hwinfo_get':
> fwts_hwinfo.c:418: error: dereferencing pointer '({anonymous})' does break strict-aliasing rules
> fwts_hwinfo.c:418: note: initialized from here
> make[5]: *** [fwts_hwinfo.lo] Error 1
>
> This patch works around this issue. Fromw what I understand, gcc 4.4.x was
> rather (too?) strict on this kind of warning.
>
> Signed-off-by: Colin Ian King <colin.king at canonical.com>
> ---
> src/lib/src/fwts_hwinfo.c | 5 ++++-
> 1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/src/lib/src/fwts_hwinfo.c b/src/lib/src/fwts_hwinfo.c
> index cb70f98..e3a9d2e 100644
> --- a/src/lib/src/fwts_hwinfo.c
> +++ b/src/lib/src/fwts_hwinfo.c
> @@ -382,6 +382,7 @@ static int fwts_hwinfo_net_get(
>
> while ((d = readdir(dp)) != NULL) {
> struct ifreq buf;
> + struct in_addr in_addr;
> fwts_net_config *net_config;
>
> if (d->d_name[0] == '.')
> @@ -415,7 +416,9 @@ static int fwts_hwinfo_net_get(
> if (errno != EADDRNOTAVAIL)
> fwts_log_error(fw, "Cannot get address for device %s.", d->d_name);
> }
> - net_config->addr = strdup(inet_ntoa(((struct sockaddr_in *)&buf.ifr_addr)->sin_addr));
> + /* GCC 4.4 is rather overly pedantic in strict aliasing warnings, this avoids it */
> + in_addr = (struct in_addr)((struct sockaddr_in *)&buf.ifr_addr)->sin_addr;
> + net_config->addr = strdup(inet_ntoa(in_addr));
> if (net_config->addr == NULL) {
> fwts_log_error(fw, "Cannot allocate net config H/W address.");
> fwts_hwinfo_net_free(net_config);
>
Acked-by: Alex Hung <alex.hung at canonical.com>
More information about the fwts-devel
mailing list