]> git.ipfire.org Git - thirdparty/iproute2.git/commitdiff
ila: fix array overflow warning
authorStephen Hemminger <stephen@networkplumber.org>
Wed, 4 Oct 2023 17:00:19 +0000 (10:00 -0700)
committerStephen Hemminger <stephen@networkplumber.org>
Wed, 4 Oct 2023 17:00:19 +0000 (10:00 -0700)
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

index 23b19a108862a02c61c201c5bc267fab237b3fcc..f4387e039f97623cd54ffe47f5074176aff05b4f 100644 (file)
@@ -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 = "";