[Spice-devel] [PATCH v2] remove a warning building a test
Frediano Ziglio
fziglio at redhat.com
Tue May 17 16:43:44 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
>
Mumble...
diff --git a/server/tests/stream-test.c b/server/tests/stream-test.c
index 6317796..623a394 100644
--- a/server/tests/stream-test.c
+++ b/server/tests/stream-test.c
@@ -63,7 +63,7 @@ sock_fd_read(int sock, void *buf, ssize_t bufsize, int *fd)
exit(1);
}
- *fd = *((int *) CMSG_DATA(cmsg));
+ memcpy(fd, CMSG_DATA(cmsg), sizeof(*fd));
} else
*fd = -1;
} else {
memcpy but without the additional variable.
Frediano
More information about the Spice-devel
mailing list