]> git.ipfire.org Git - thirdparty/iproute2.git/commitdiff
ss: initialise variables outside of for loop
authorSimon Horman <simon.horman@netronome.com>
Fri, 2 Dec 2016 11:56:05 +0000 (12:56 +0100)
committerStephen Hemminger <stephen@networkplumber.org>
Fri, 2 Dec 2016 22:17:09 +0000 (14:17 -0800)
Initialise for loops outside of for loops. GCC flags this as being
out of spec unless C99 or C11 mode is used.

With this change the entire tree appears to compile cleanly with -Wall.

$ gcc --version
gcc (Debian 4.9.2-10) 4.9.2
...
$ make
...
ss.c: In function ‘unix_show_sock’:
ss.c:3128:4: error: ‘for’ loop initial declarations are only allowed in C99 or C11 mode
...

Signed-off-by: Simon Horman <simon.horman@netronome.com>
misc/ss.c

index 07dcd8c209c049c81d20a32d4f4d2b3a79018eeb..20b71f55235bf868a38cbd0c80d1f8e33309ceec 100644 (file)
--- a/misc/ss.c
+++ b/misc/ss.c
@@ -3081,10 +3081,12 @@ static int unix_show_sock(const struct sockaddr_nl *addr, struct nlmsghdr *nlh,
 
                memcpy(name, RTA_DATA(tb[UNIX_DIAG_NAME]), len);
                name[len] = '\0';
-               if (name[0] == '\0')
-                       for (int i = 0; i < len; i++)
+               if (name[0] == '\0') {
+                       int i;
+                       for (i = 0; i < len; i++)
                                if (name[i] == '\0')
                                        name[i] = '@';
+               }
                stat.name = &name[0];
                memcpy(stat.local.data, &stat.name, sizeof(stat.name));
        }