Sun Jan 29 18:33:07 2012 UTC ()
Allow using CMSG_NXTHDR with -Wcast-align.

If various checks are omitted, the CMSG_NXTHDR macro expands to
(struct cmsghdr *)((char *)(cmsg) + \
_ALIGN(((struct cmsghdr *)(cmsg))->cmsg_len))

Although there is no alignment problem (assuming cmsg is properly aligned
and _ALIGN is correct), this violates -Wcast-align on strict-alignment
architectures. Therefore an intermediate cast to void * is appropriate here.

There is no workaround other than not using -Wcast-align.

Taken from FreeBSD commit r220742 by jilles


(roy)
diff -r1.105 -r1.106 src/sys/sys/socket.h

cvs diff -r1.105 -r1.106 src/sys/sys/socket.h (expand / switch to context diff)
--- src/sys/sys/socket.h 2012/01/25 00:28:35 1.105
+++ src/sys/sys/socket.h 2012/01/29 18:33:07 1.106
@@ -1,4 +1,4 @@
-/*	$NetBSD: socket.h,v 1.105 2012/01/25 00:28:35 christos Exp $	*/
+/*	$NetBSD: socket.h,v 1.106 2012/01/29 18:33:07 roy Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -544,7 +544,7 @@
 			    __CMSG_ALIGN(sizeof(struct cmsghdr)) > \
 	    (((char *)(mhdr)->msg_control) + (mhdr)->msg_controllen)) ? \
 	    (struct cmsghdr *)0 : \
-	    (struct cmsghdr *)((char *)(cmsg) + \
+	    (struct cmsghdr *)(void *)((char *)(cmsg) + \
 	        __CMSG_ALIGN((cmsg)->cmsg_len)))
 
 /*