diff mbox

lib: fwts_hwinfo: clean up type punning, fixes warning with gcc-6

Message ID 1452701360-31323-1-git-send-email-colin.king@canonical.com
State Accepted
Headers show

Commit Message

Colin Ian King Jan. 13, 2016, 4:09 p.m. UTC
From: Colin Ian King <colin.king@canonical.com>

Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 src/lib/src/fwts_hwinfo.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

Comments

Colin Ian King Jan. 15, 2016, 11:55 a.m. UTC | #1
On 13/01/16 16:09, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
> 
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>  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 6a0a9aa..e8f7c05 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 in_addr in_addr;
> +		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 */
> -		in_addr = (struct in_addr)((struct sockaddr_in *)&buf.ifr_addr)->sin_addr;
> -		net_config->addr = strdup(inet_ntoa(in_addr));
> +		sockaddr = (struct sockaddr_in *)&buf.ifr_addr;
> +		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);
> 
NACK, this produces warnings on other older compilers

Colin
Colin Ian King Jan. 15, 2016, 2:15 p.m. UTC | #2
On 15/01/16 11:55, Colin Ian King wrote:
> On 13/01/16 16:09, Colin King wrote:
>> From: Colin Ian King <colin.king@canonical.com>
>>
>> Signed-off-by: Colin Ian King <colin.king@canonical.com>
>> ---
>>  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 6a0a9aa..e8f7c05 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 in_addr in_addr;
>> +		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 */
>> -		in_addr = (struct in_addr)((struct sockaddr_in *)&buf.ifr_addr)->sin_addr;
>> -		net_config->addr = strdup(inet_ntoa(in_addr));
>> +		sockaddr = (struct sockaddr_in *)&buf.ifr_addr;
>> +		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);
>>
> NACK, this produces warnings on other older compilers
> 
> Colin
> 
Nope, I was being stupid and building my code w/o this patch.  Ignore my
NACK, tested with:

gcc 4.6.3
gcc 4.8.4
gcc 4.9.2
gcc 5.2.1
gcc 6.0.0

So this patch is OK for the current builds and for Xenial+1.  Ignore the
NACK.

Colin
Alex Hung Jan. 18, 2016, 6:57 a.m. UTC | #3
On 2016-01-14 12:09 AM, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
>
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>   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 6a0a9aa..e8f7c05 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 in_addr in_addr;
> +		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 */
> -		in_addr = (struct in_addr)((struct sockaddr_in *)&buf.ifr_addr)->sin_addr;
> -		net_config->addr = strdup(inet_ntoa(in_addr));
> +		sockaddr = (struct sockaddr_in *)&buf.ifr_addr;
> +		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);
>

Acked-by: Alex Hung <alex.hung@canonical.com>
Ivan Hu Jan. 19, 2016, 6:15 a.m. UTC | #4
On 2016年01月14日 00:09, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
>
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>   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 6a0a9aa..e8f7c05 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 in_addr in_addr;
> +		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 */
> -		in_addr = (struct in_addr)((struct sockaddr_in *)&buf.ifr_addr)->sin_addr;
> -		net_config->addr = strdup(inet_ntoa(in_addr));
> +		sockaddr = (struct sockaddr_in *)&buf.ifr_addr;
> +		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);

Acked-by: Ivan Hu <ivan.hu@canonical.com>
diff mbox

Patch

diff --git a/src/lib/src/fwts_hwinfo.c b/src/lib/src/fwts_hwinfo.c
index 6a0a9aa..e8f7c05 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 in_addr in_addr;
+		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 */
-		in_addr = (struct in_addr)((struct sockaddr_in *)&buf.ifr_addr)->sin_addr;
-		net_config->addr = strdup(inet_ntoa(in_addr));
+		sockaddr = (struct sockaddr_in *)&buf.ifr_addr;
+		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);