]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
selftest: af_unix: Silence -Wflex-array-member-not-at-end warning for scm_rights.c.
authorKuniyuki Iwashima <kuniyu@google.com>
Mon, 11 Aug 2025 21:53:06 +0000 (21:53 +0000)
committerJakub Kicinski <kuba@kernel.org>
Wed, 13 Aug 2025 01:01:53 +0000 (18:01 -0700)
scm_rights.c has no problem in functionality, but when compiled with
-Wflex-array-member-not-at-end, it shows this warning:

scm_rights.c: In function ‘__send_fd’:
scm_rights.c:275:32: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]
  275 |                 struct cmsghdr cmsghdr;
      |                                ^~~~~~~

Let's silence it.

Signed-off-by: Kuniyuki Iwashima <kuniyu@google.com>
Link: https://patch.msgid.link/20250811215432.3379570-4-kuniyu@google.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
tools/testing/selftests/net/af_unix/scm_rights.c

index 8b015f16c03d3c9a685d7827becebabac35606ae..914f99d153ce7e14639d0a78c9b30ac822abccaa 100644 (file)
@@ -271,20 +271,11 @@ void __send_fd(struct __test_metadata *_metadata,
 {
 #define MSG "x"
 #define MSGLEN 1
-       struct {
-               struct cmsghdr cmsghdr;
-               int fd[2];
-       } cmsg = {
-               .cmsghdr = {
-                       .cmsg_len = CMSG_LEN(sizeof(cmsg.fd)),
-                       .cmsg_level = SOL_SOCKET,
-                       .cmsg_type = SCM_RIGHTS,
-               },
-               .fd = {
-                       self->fd[inflight * 2],
-                       self->fd[inflight * 2],
-               },
+       int fds[2] = {
+               self->fd[inflight * 2],
+               self->fd[inflight * 2],
        };
+       char cmsg_buf[CMSG_SPACE(sizeof(fds))];
        struct iovec iov = {
                .iov_base = MSG,
                .iov_len = MSGLEN,
@@ -294,11 +285,18 @@ void __send_fd(struct __test_metadata *_metadata,
                .msg_namelen = 0,
                .msg_iov = &iov,
                .msg_iovlen = 1,
-               .msg_control = &cmsg,
-               .msg_controllen = CMSG_SPACE(sizeof(cmsg.fd)),
+               .msg_control = cmsg_buf,
+               .msg_controllen = sizeof(cmsg_buf),
        };
+       struct cmsghdr *cmsg;
        int ret;
 
+       cmsg = CMSG_FIRSTHDR(&msg);
+       cmsg->cmsg_level = SOL_SOCKET;
+       cmsg->cmsg_type = SCM_RIGHTS;
+       cmsg->cmsg_len = CMSG_LEN(sizeof(fds));
+       memcpy(CMSG_DATA(cmsg), fds, sizeof(fds));
+
        ret = sendmsg(self->fd[receiver * 2 + 1], &msg, variant->flags);
 
        if (variant->disabled) {