From morbo at google.com Mon Nov 9 14:13:33 2020 From: morbo at google.com (Bill Wendling) Date: Mon, 9 Nov 2020 14:13:33 -0800 Subject: [klibc] [[PATCH v1 0/3] Fix clang build warnings Message-ID: <20201109221336.1534572-1-morbo@google.com> New clangs emit some warnings. The code isn't wrong, but should be updated to prevent warning creep. Bill Wendling (3): [klibc] dash: shell: Fix clang warnings [klibc] dash: shell: Fix clang warnings about format string [klibc] Kbuild: use an enum to silence a clang warning usr/dash/eval.c | 6 +++--- usr/dash/jobs.c | 2 +- usr/kinit/nfsmount/dummypmap.c | 3 ++- 3 files changed, 6 insertions(+), 5 deletions(-) -- 2.29.2.222.g5d2a92d10f8-goog From morbo at google.com Mon Nov 9 14:13:34 2020 From: morbo at google.com (Bill Wendling) Date: Mon, 9 Nov 2020 14:13:34 -0800 Subject: [klibc] [PATCH v1 1/3] dash: shell: Fix clang warnings In-Reply-To: <20201109221336.1534572-1-morbo@google.com> References: <20201109221336.1534572-1-morbo@google.com> Message-ID: <20201109221336.1534572-2-morbo@google.com> A couple of warnings from clang about old-style field designators and a logical "not" used in an unconventional way and needs parentheses. ----------------------------------------------------------------------- usr/dash/eval.c:106:2: warning: use of GNU old-style field designator extension [-Wgnu-designator] name: nullstr, ^~~~~ .name = usr/dash/eval.c:107:2: warning: use of GNU old-style field designator extension [-Wgnu-designator] builtin: bltincmd ^~~~~~~~ .builtin = usr/dash/eval.c:277:7: warning: logical not is only applied to the left hand side of this comparison [-Wlogical-not-parentheses] if (!exitstatus == isor) ^ ~~ usr/dash/eval.c:277:7: note: add parentheses after the '!' to evaluate the comparison first if (!exitstatus == isor) ^ ( ) usr/dash/eval.c:277:7: note: add parentheses around left hand side expression to silence this warning if (!exitstatus == isor) ^ ( ) ----------------------------------------------------------------------- Signed-off-by: Bill Wendling --- usr/dash/eval.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/usr/dash/eval.c b/usr/dash/eval.c index dd144948..145e0b46 100644 --- a/usr/dash/eval.c +++ b/usr/dash/eval.c @@ -103,8 +103,8 @@ STATIC int bltincmd(int, char **); STATIC const struct builtincmd bltin = { - name: nullstr, - builtin: bltincmd + .name = nullstr, + .builtin = bltincmd }; @@ -274,7 +274,7 @@ checkexit: n->nbinary.ch1, (flags | ((isor >> 1) - 1)) & EV_TESTED ); - if (!exitstatus == isor) + if ((!exitstatus) == isor) break; if (!evalskip) { n = n->nbinary.ch2; -- 2.29.2.222.g5d2a92d10f8-goog From morbo at google.com Mon Nov 9 14:13:35 2020 From: morbo at google.com (Bill Wendling) Date: Mon, 9 Nov 2020 14:13:35 -0800 Subject: [klibc] [PATCH v1 2/3] dash: shell: Fix clang warnings about format string In-Reply-To: <20201109221336.1534572-1-morbo@google.com> References: <20201109221336.1534572-1-morbo@google.com> Message-ID: <20201109221336.1534572-3-morbo@google.com> Build with clang results in some warnings about using a non-string literal for a format string. ----------------------------------------------------------------------- usr/dash/jobs.c:429:23: warning: format string is not a string literal (potentially insecure) [-Wformat-security] col = fmtstr(s, 32, strsignal(st)); ^~~~~~~~~~~~~ usr/dash/jobs.c:429:23: note: treat the string as an argument to avoid this col = fmtstr(s, 32, strsignal(st)); ^ "%s", ----------------------------------------------------------------------- Signed-off-by: Bill Wendling --- usr/dash/jobs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/usr/dash/jobs.c b/usr/dash/jobs.c index b9ff1402..f027cc10 100644 --- a/usr/dash/jobs.c +++ b/usr/dash/jobs.c @@ -426,7 +426,7 @@ sprint_status(char *s, int status, int sigonly) goto out; #endif } - col = fmtstr(s, 32, strsignal(st)); + col = fmtstr(s, 32, "%s", strsignal(st)); #ifdef WCOREDUMP if (WCOREDUMP(status)) { col += fmtstr(s + col, 16, " (core dumped)"); -- 2.29.2.222.g5d2a92d10f8-goog From morbo at google.com Mon Nov 9 14:13:36 2020 From: morbo at google.com (Bill Wendling) Date: Mon, 9 Nov 2020 14:13:36 -0800 Subject: [klibc] [PATCH v1 3/3] Kbuild: use an enum to silence a clang warning In-Reply-To: <20201109221336.1534572-1-morbo@google.com> References: <20201109221336.1534572-1-morbo@google.com> Message-ID: <20201109221336.1534572-4-morbo@google.com> Clang emits a warning when constant forlding variable length arrays: usr/kinit/nfsmount/dummypmap.c:156:8: warning: variable length array folded to constant array as an extension [-Werror,-Wgnu-folding-constant] char payload[MAX_UDP_PACKET + offsetof(struct rpc_header, udp)]; ^ 1 error generated. Using an enum bypasses the constant folding issue. Signed-off-by: Bill Wendling --- usr/kinit/nfsmount/dummypmap.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/usr/kinit/nfsmount/dummypmap.c b/usr/kinit/nfsmount/dummypmap.c index a4e80147..07210c56 100644 --- a/usr/kinit/nfsmount/dummypmap.c +++ b/usr/kinit/nfsmount/dummypmap.c @@ -148,12 +148,13 @@ static int check_vrf(struct rpc_auth *vrf) static int dummy_portmap(int sock, FILE *portmap_file) { + enum { PAYLOAD_SIZE = MAX_UDP_PACKET + offsetof(struct rpc_header, udp) }; struct sockaddr_in sin; int pktlen, addrlen; union { struct rpc_call rpc; /* Max UDP packet size + unused TCP fragment size */ - char payload[MAX_UDP_PACKET + offsetof(struct rpc_header, udp)]; + char payload[PAYLOAD_SIZE]; } pkt; struct rpc_call *rpc = &pkt.rpc; struct rpc_auth *cred; -- 2.29.2.222.g5d2a92d10f8-goog