On Fri, Feb 13, 2009 at 11:54:10AM +0000, Mark McLoughlin wrote:
qemud.c: In function ???remoteListenTCP???:
qemud.c:675: error: dereferencing pointer ???sa.72??? does break strict-aliasing rules
qemud.c:675: note: initialized from here
qemud.c:678: error: dereferencing pointer ???sa.73??? does break strict-aliasing rules
qemud.c:678: note: initialized from here
Signed-off-by: Mark McLoughlin <markmc(a)redhat.com>
---
qemud/qemud.c | 21 ++++++++++++++-------
1 files changed, 14 insertions(+), 7 deletions(-)
diff --git a/qemud/qemud.c b/qemud/qemud.c
index ca6357c..6cbba21 100644
--- a/qemud/qemud.c
+++ b/qemud/qemud.c
@@ -649,9 +649,16 @@ remoteListenTCP (struct qemud_server *server,
return -1;
for (i = 0; i < nfds; ++i) {
- struct sockaddr_storage sa;
+ union {
+ struct sockaddr_storage sa_stor;
+ struct sockaddr sa;
+ struct sockaddr_in sa_in;
+#ifdef AF_INET6
+ struct sockaddr_in6 sa_in6;
+#endif
+ } s;
char ebuf[1024];
- socklen_t salen = sizeof(sa);
+ socklen_t salen = sizeof(s);
if (VIR_ALLOC(sock) < 0) {
VIR_ERROR(_("remoteListenTCP: calloc: %s"),
@@ -668,14 +675,14 @@ remoteListenTCP (struct qemud_server *server,
sock->type = type;
sock->auth = auth;
- if (getsockname(sock->fd, (struct sockaddr *)(&sa), &salen) < 0)
+ if (getsockname(sock->fd, &s.sa, &salen) < 0)
goto cleanup;
- if (sa.ss_family == AF_INET)
- sock->port = htons(((struct sockaddr_in*)&sa)->sin_port);
+ if (s.sa.sa_family == AF_INET) {
+ sock->port = htons(s.sa_in.sin_port);
#ifdef AF_INET6
- else if (sa.ss_family == AF_INET6)
- sock->port = htons(((struct sockaddr_in6*)&sa)->sin6_port);
+ } else if (s.sa.sa_family == AF_INET6)
+ sock->port = htons(s.sa_in6.sin6_port);
#endif
else
sock->port = -1;
--
ACK, though I'm wondering if our use of GNULIB means we can now drop the
#ifdef AF_INET6 conditional and rely on it always existing.
Daniel
--
|: Red Hat, Engineering, London -o-
http://people.redhat.com/berrange/ :|
|:
http://libvirt.org -o-
http://virt-manager.org -o-
http://ovirt.org :|
|:
http://autobuild.org -o-
http://search.cpan.org/~danberr/ :|
|: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|