public inbox for netdev@vger.kernel.org 
 help / color / mirror / Atom feed
* [PATCH iproute2/net-next] ss: initialise variables outside of for loop
@ 2016-12-02 11:56 Simon Horman
  2016-12-02 22:18 ` Stephen Hemminger
  0 siblings, 1 reply; 3+ messages in thread
From: Simon Horman @ 2016-12-02 11:56 UTC (permalink / raw)
  To: Stephen Hemminger; +Cc: netdev, Simon Horman

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 | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/misc/ss.c b/misc/ss.c
index 839781ee29bc..ce0b9d3d993d 100644
--- a/misc/ss.c
+++ b/misc/ss.c
@@ -3124,10 +3124,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));
 	}
-- 
2.7.0.rc3.207.g0ac5344

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

end of thread, other threads:[~2016-12-03  8:37 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-12-02 11:56 [PATCH iproute2/net-next] ss: initialise variables outside of for loop Simon Horman
2016-12-02 22:18 ` Stephen Hemminger
2016-12-03  8:37   ` Simon Horman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox