Re: Two skalibs compiler warnings on RHEL 7

From: Laurent Bercot <ska-skaware_at_skarnet.org>
Date: Mon, 02 Dec 2019 22:56:14 +0000

>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.

--
  Laurent
Received on Mon Dec 02 2019 - 22:56:14 UTC

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