[Spice-devel] [PATCH v2] remove a warning building a test

Frediano Ziglio fziglio at redhat.com
Tue May 17 16:42:22 UTC 2016


> 
> On Tue, May 17, 2016 at 04:44:04PM +0100, Frediano Ziglio wrote:
> > With my compile switches (which are mostly derived from RedHat spec
> > file) I'm getting this warning:
> > 
> > stream-test.c: In function 'sock_fd_read':
> > stream-test.c:66:43: warning: dereferencing type-punned pointer will
> > break strict-aliasing rules [-Wstrict-aliasing]
> >              *fd = *((int *) CMSG_DATA(cmsg));
> >                                            ^
> > 
> > memcpy could decrease performance but as this is a test it's not
> > an issue.
> 
> Can you avoid the warning with an additional (void *) cast?
> *fd = *((int *) (void *) CMSG_DATA(cmsg))); ?
> 
> Christophe
> 

Nope...

Tried also to add a volatile... nope...

Let me see the macro...

struct cmsghdr {
    size_t cmsg_len;
    int cmsg_level;
    int cmsg_type;
    __extension__ unsigned char __cmsg_data [];
};
...
struct msghdr msg;
...
struct cmsghdr *cmsg;
...
cmsg = ((size_t) (&msg)->msg_controllen >= sizeof (struct cmsghdr) ? (struct cmsghdr *) (&msg)->msg_control : (struct cmsghdr *) 0);
...
*fd = *((int *) (( cmsg)->__cmsg_data));

No (simple solutions). I know the may_alias attribute but after checking for __GNUC__ and other stuff
looks like memcpy looks better.

Frediano


More information about the Spice-devel mailing list