On 05/17/2016 07:43 PM, Frediano Ziglio wrote:
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))); ? ChristopheMumble... 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.
In man cmsg examples I see they use a pointer: int *pi = (int*) CMSG_DATA(cmsg); *fd = *pi; (But also they use memcpy to copy several fds) Uri _______________________________________________ Spice-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/spice-devel
