[klibc] [klibc:master] kinit: use an enum to silence a clang warning

klibc-bot for Bill Wendling morbo at google.com
Sat Dec 12 15:27:09 PST 2020

Commit-ID:  3340b7d699331f6285bbfafc52f3b0d6f7ce00f0
Gitweb:     http://git.kernel.org/?p=libs/klibc/klibc.git;a=commit;h=3340b7d699331f6285bbfafc52f3b0d6f7ce00f0
Author:     Bill Wendling <morbo at google.com>
AuthorDate: Mon, 9 Nov 2020 14:13:36 -0800
Committer:  Ben Hutchings <ben at decadent.org.uk>
CommitDate: Sat, 12 Dec 2020 22:46:28 +0100

[klibc] kinit: use an enum to silence a clang warning

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 <morbo at google.com>
[bwh: Correct the component in the subject line]
Signed-off-by: Ben Hutchings <ben at decadent.org.uk>

 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;

More information about the klibc mailing list