From 66585c3fe278c71ffa995c296a9a1e712482418e Mon Sep 17 00:00:00 2001 From: Adrian Chadd Date: Tue, 29 Dec 2020 09:50:49 -0800 Subject: [PATCH] [wlanwatch] fix compiler warnings-as-errors on gcc-6.4 mips * argc/argv are currently unused * msglen is currently unused * "default" is a const buffer, but char *cp isn't, so change default string to be a non-const global string variable * Make 'cp' private to each context that's using it, which fixes a "variable shadows previous declaration" warning and makes it easier to track where it was being leaked between address family sections --- tools/tools/net80211/wlanwatch/wlanwatch.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/tools/tools/net80211/wlanwatch/wlanwatch.c b/tools/tools/net80211/wlanwatch/wlanwatch.c index 254d3be24448..7ff81cc1253a 100644 --- a/tools/tools/net80211/wlanwatch/wlanwatch.c +++ b/tools/tools/net80211/wlanwatch/wlanwatch.c @@ -84,6 +84,9 @@ main(int argc, char *argv[]) int n, s; char msg[2048]; + (void) argc; /* UNUSED */ + (void) argv; /* UNUSED */ + s = socket(PF_ROUTE, SOCK_RAW, 0); if (s < 0) err(EX_OSERR, "socket"); @@ -135,16 +138,18 @@ char ifnetflags[] = char addrnames[] = "\1DST\2GATEWAY\3NETMASK\4GENMASK\5IFP\6IFA\7AUTHOR\010BRD"; +char defaultname[] = "default"; + static const char * routename(struct sockaddr *sa) { - char *cp; static char line[MAXHOSTNAMELEN + 1]; struct hostent *hp; static char domain[MAXHOSTNAMELEN + 1]; static int first = 1, n; if (first) { + char *cp = NULL; first = 0; if (gethostname(domain, MAXHOSTNAMELEN) == 0 && (cp = strchr(domain, '.'))) { @@ -160,12 +165,14 @@ routename(struct sockaddr *sa) case AF_INET: { struct in_addr in; + char *cp; + in = ((struct sockaddr_in *)sa)->sin_addr; - cp = 0; + cp = NULL; if (in.s_addr == INADDR_ANY || sa->sa_len < 4) - cp = "default"; - if (cp == 0 && !nflag) { + cp = defaultname; + if (cp == NULL && !nflag) { hp = gethostbyaddr((char *)&in, sizeof (struct in_addr), AF_INET); if (hp) { @@ -291,6 +298,8 @@ print_rtmsg(struct rt_msghdr *rtm, int msglen) time_t now = time(NULL); char *cnow = ctime(&now); + (void) msglen; /* UNUSED */ + if (rtm->rtm_version != RTM_VERSION) { (void) printf("routing message version %d not understood\n", rtm->rtm_version);