diff mbox series

[iproute2] ila: fix array overflow warning

Message ID 20231004170258.25575-1-stephen@networkplumber.org (mailing list archive)
State Accepted
Commit beb5d379e19f88440012586ae1bc91d6d63a2594
Delegated to: David Ahern
Headers show
Series [iproute2] ila: fix array overflow warning | expand

Checks

Context Check Description
netdev/tree_selection success Not a local patch

Commit Message

Stephen Hemminger Oct. 4, 2023, 5:02 p.m. UTC
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(-)

Comments

Petr Machata Oct. 5, 2023, 10:16 a.m. UTC | #1
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 = "";
patchwork-bot+netdevbpf@kernel.org Oct. 5, 2023, 5:10 p.m. UTC | #2
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!
diff mbox series

Patch

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 = "";