Re: Two skalibs compiler warnings on RHEL 7

From: J. Lewis Muir <>
Date: Mon, 2 Dec 2019 16:58:49 -0600

On 12/02, Laurent Bercot wrote:
> > src/libunixonacid/textclient_server_init_fromsocket.c:56:3: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
> > *(int *)CMSG_DATA(c) = fd[1] ;
> > ^
> Yeah, some compilers actually print that warning.
> It's annoying, because this is the official way, and really the only way,
> of using CMSG_DATA(). It breaks strict aliasing, but it's okay, because
> in the case of SCM_RIGHTS transmission, nothing ever uses CMSG_DATA(c) as
> an array of unsigned char; it's always written and read as an array of
> ints, and holds file descriptors.
> Honestly, the spec of CMSG_DATA() is to blame: it should be void *, or
> at the very least, char *. Making it unsigned char * was really
> short-sighted, and the root cause for the strict aliasing violation.
> I don't want to "fix" this in my code, because the code as it is written
> is as clear as can be. A "fix" would imply a double cast through void *,
> which would decrease readability - not a good trade for two spurious
> compiler warnings.

OK, sounds good! Thanks!

Received on Mon Dec 02 2019 - 22:58:49 UTC

This archive was generated by hypermail 2.3.0 : Sun May 09 2021 - 19:38:49 UTC