[PATCH 12/59] sunrpc: Suppress clang -Wgnu-variable-sized-type-not-at-end warning on struct cmessage

Sam James sam@gentoo.org
Mon Oct 20 19:42:49 GMT 2025


Adhemerval Zanella <adhemerval.zanella@linaro.org> writes:

> clang issues:
>
> svc_unix.c:318:18: error: field 'cmsg' with variable sized type 'struct cmsghdr' not at the end of a struct or class is a GNU extension [-Werror,-Wgnu-variable-sized-type-not-at-end]
>   318 |   struct cmsghdr cmsg;
>       |                  ^
>
> The __msgread explicitly expects that 'struct ucred' is after the 'cmsg',
> so suppress the warning.

Reviewed-by: Sam James <sam@gentoo.org>

> ---
>  sunrpc/svc_unix.c | 7 +++++++
>  1 file changed, 7 insertions(+)
>
> diff --git a/sunrpc/svc_unix.c b/sunrpc/svc_unix.c
> index 2743c1419a..c97880c012 100644
> --- a/sunrpc/svc_unix.c
> +++ b/sunrpc/svc_unix.c
> @@ -65,6 +65,7 @@
>  #include <libintl.h>
>  #include <wchar.h>
>  #include <shlib-compat.h>
> +#include <libc-diag.h>
>  
>  /*
>   * Ops vector for AF_UNIX based rpc service handle
> @@ -308,12 +309,18 @@ svcunix_destroy (SVCXPRT *xprt)
>  }
>  
>  #ifdef SCM_CREDENTIALS
> +/* clang complains if a flexible array member (struct cmsghdr) is not a the
> +   end of the struct (it is a GNU extension).  The __msgread explicitly
> +   expects that 'struct ucred' is after the 'cmsg', so disable the warning.  */
> +DIAG_PUSH_NEEDS_COMMENT_CLANG;
> +DIAG_IGNORE_NEEDS_COMMENT_CLANG (18, "-Wgnu-variable-sized-type-not-at-end");
>  struct cmessage {
>    struct cmsghdr cmsg;
>    struct ucred cmcred;
>    /* hack to make sure we have enough memory */
>    char dummy[(CMSG_ALIGN (sizeof (struct ucred)) - sizeof (struct ucred) + sizeof (long))];
>  };
> +DIAG_POP_NEEDS_COMMENT_CLANG;
>  
>  /* XXX This is not thread safe, but since the main functions in svc.c
>     and the rpcgen generated *_svc functions for the daemon are also not


More information about the Libc-alpha mailing list