netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH iproute2] ila: fix array overflow warning
@ 2023-10-04 17:02 Stephen Hemminger
  2023-10-05 10:16 ` Petr Machata
  2023-10-05 17:10 ` patchwork-bot+netdevbpf
  0 siblings, 2 replies; 3+ messages in thread
From: Stephen Hemminger @ 2023-10-04 17:02 UTC (permalink / raw)
  To: netdev; +Cc: Stephen Hemminger

Aliasing a 64 bit value seems to confuse Gcc 12.2.
ipila.c:57:32: warning: ‘addr’ may be used uninitialized [-Wmaybe-uninitialized]

Use a union instead.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 ip/ipila.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/ip/ipila.c b/ip/ipila.c
index 23b19a108862..f4387e039f97 100644
--- a/ip/ipila.c
+++ b/ip/ipila.c
@@ -47,14 +47,17 @@ static int genl_family = -1;
 
 static void print_addr64(__u64 addr, char *buff, size_t len)
 {
-	__u16 *words = (__u16 *)&addr;
+	union {
+		__u64 id64;
+		__u16 words[4];
+	} id = { .id64 = addr };
 	__u16 v;
 	int i, ret;
 	size_t written = 0;
 	char *sep = ":";
 
 	for (i = 0; i < 4; i++) {
-		v = ntohs(words[i]);
+		v = ntohs(id.words[i]);
 
 		if (i == 3)
 			sep = "";
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH iproute2] ila: fix array overflow warning
  2023-10-04 17:02 [PATCH iproute2] ila: fix array overflow warning Stephen Hemminger
@ 2023-10-05 10:16 ` Petr Machata
  2023-10-05 17:10 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: Petr Machata @ 2023-10-05 10:16 UTC (permalink / raw)
  To: Stephen Hemminger; +Cc: netdev


Stephen Hemminger <stephen@networkplumber.org> writes:

> Aliasing a 64 bit value seems to confuse Gcc 12.2.
> ipila.c:57:32: warning: ‘addr’ may be used uninitialized [-Wmaybe-uninitialized]
>
> Use a union instead.
>
> Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>

Reviewed-by: Petr Machata <petrm@nvidia.com>

> ---
>  ip/ipila.c | 7 +++++--
>  1 file changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/ip/ipila.c b/ip/ipila.c
> index 23b19a108862..f4387e039f97 100644
> --- a/ip/ipila.c
> +++ b/ip/ipila.c
> @@ -47,14 +47,17 @@ static int genl_family = -1;
>  
>  static void print_addr64(__u64 addr, char *buff, size_t len)
>  {
> -	__u16 *words = (__u16 *)&addr;
> +	union {
> +		__u64 id64;
> +		__u16 words[4];
> +	} id = { .id64 = addr };
>  	__u16 v;
>  	int i, ret;
>  	size_t written = 0;
>  	char *sep = ":";
>  
>  	for (i = 0; i < 4; i++) {
> -		v = ntohs(words[i]);
> +		v = ntohs(id.words[i]);
>  
>  		if (i == 3)
>  			sep = "";


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH iproute2] ila: fix array overflow warning
  2023-10-04 17:02 [PATCH iproute2] ila: fix array overflow warning Stephen Hemminger
  2023-10-05 10:16 ` Petr Machata
@ 2023-10-05 17:10 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2023-10-05 17:10 UTC (permalink / raw)
  To: Stephen Hemminger; +Cc: netdev

Hello:

This patch was applied to iproute2/iproute2.git (main)
by Stephen Hemminger <stephen@networkplumber.org>:

On Wed,  4 Oct 2023 10:02:58 -0700 you wrote:
> Aliasing a 64 bit value seems to confuse Gcc 12.2.
> ipila.c:57:32: warning: ‘addr’ may be used uninitialized [-Wmaybe-uninitialized]
> 
> Use a union instead.
> 
> Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
> 
> [...]

Here is the summary with links:
  - [iproute2] ila: fix array overflow warning
    https://git.kernel.org/pub/scm/network/iproute2/iproute2.git/commit/?id=beb5d379e19f

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-10-05 17:10 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-10-04 17:02 [PATCH iproute2] ila: fix array overflow warning Stephen Hemminger
2023-10-05 10:16 ` Petr Machata
2023-10-05 17:10 ` patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).