> > There is one somewhat scary warning during the build but it's not new:
> > 
> > imuxsock.c:1112:44: warning: cast from 'char *' to 'struct cmsghdr *' 
> > increases required
> >       alignment from 1 to 4 [-Wcast-align]
> >                         for(cm = CMSG_FIRSTHDR(&msgh); cm; cm = 
> > CMSG_NXTHDR(&msgh, cm)) {
> >                                                                 
> > ^~~~~~~~~~~~~~~~~~~~~~
> > /usr/include/sys/socket.h:499:6: note: expanded from macro 'CMSG_NXTHDR'
> >             (struct cmsghdr *)((char *)(cmsg) + _ALIGN((cmsg)->cmsg_len)))
> >             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> 
> I now looked into this one. It is actually not a warning for imuxsock.c but
> for OpenBSD's socket.h.
> 
> When adding -Wcast-align to CFLAGS for programs in base, I see many warnings
> (checked rad and ospfd). I think this is not something we need to worry
> about. But I might be wrong since I'm not an expert. ;-)

I see. Thanks for taking a look. It is indeed harmless - I should have
looked closer before pointing it out.

Assuming that cmsg is correctly aligned (cm is correctly aligned here),
this should be ok as it is.  The (char *) cast is there to make the
offset calculation as intended and _ALIGN() will result in a correctly
rounded offset.

FreeBSD and NetBSD (hidden under some cdefs.h macros) both insert an
intermediate (void *) cast before casting to (struct cmsghdr *), FreeBSD
explicitly did this to silence the -Wcast-align warning:

https://github.com/freebsd/freebsd/commit/933648d638b9e6ad349de688d2137a3353d4ef9c

Reply via email to