[libvirt] [PATCH 0/3] Fix aliasing rules warnings with gcc-4.4

Hi, It seems gcc's strict aliasing rules got stricter with gcc-4.4. The basic rule is that two pointers of different types can't be used to reference the same address in memory. One exception is using a char* and another is when different types are members of a union. I've used unions to fix all the warnings I see with current CVS HEAD. I can't say I like the solution all that much, so if anyone has better ideas ... Cheers, Mark.

bridge.c: In function 'brSetInetAddr': bridge.c:665: error: dereferencing pointer '({anonymous})' does break strict-aliasing rules bridge.c:665: note: initialized from here bridge.c:666: error: dereferencing pointer '({anonymous})' does break strict-aliasing rules bridge.c:666: note: initialized from here Signed-off-by: Mark McLoughlin <markmc@redhat.com> --- src/bridge.c | 10 ++++++++-- 1 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/bridge.c b/src/bridge.c index 990a567..fc11429 100644 --- a/src/bridge.c +++ b/src/bridge.c @@ -642,6 +642,10 @@ brSetInetAddr(brControl *ctl, int cmd, const char *addr) { + union { + struct sockaddr sa; + struct sockaddr_in sa_in; + } s; struct ifreq ifr; struct in_addr inaddr; int len, ret; @@ -662,8 +666,10 @@ brSetInetAddr(brControl *ctl, else if (ret == 0) return EINVAL; - ((struct sockaddr_in *)&ifr.ifr_data)->sin_family = AF_INET; - ((struct sockaddr_in *)&ifr.ifr_data)->sin_addr = inaddr; + s.sa_in.sin_family = AF_INET; + s.sa_in.sin_addr = inaddr; + + ifr.ifr_addr = s.sa; if (ioctl(ctl->fd, cmd, &ifr) < 0) return errno; -- 1.6.0.6

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@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; -- 1.6.0.6

libvirt_proxy.c: In function 'proxyReadClientSocket': libvirt_proxy.c:659: error: dereferencing pointer 'req' does break strict-aliasing rules libvirt_proxy.c:657: error: dereferencing pointer 'req' does break strict-aliasing rules libvirt_proxy.c:655: error: dereferencing pointer 'req' does break strict-aliasing rules libvirt_proxy.c:654: error: dereferencing pointer 'req' does break strict-aliasing rules libvirt_proxy.c:650: error: dereferencing pointer 'req' does break strict-aliasing rules libvirt_proxy.c:649: error: dereferencing pointer 'req' does break strict-aliasing rules libvirt_proxy.c:644: error: dereferencing pointer 'req' does break strict-aliasing rules libvirt_proxy.c:636: error: dereferencing pointer 'req' does break strict-aliasing rules libvirt_proxy.c:634: error: dereferencing pointer 'req' does break strict-aliasing rules libvirt_proxy.c:632: error: dereferencing pointer 'req' does break strict-aliasing rules libvirt_proxy.c:631: error: dereferencing pointer 'req' does break strict-aliasing rules libvirt_proxy.c:627: error: dereferencing pointer 'req' does break strict-aliasing rules libvirt_proxy.c:626: error: dereferencing pointer 'req' does break strict-aliasing rules libvirt_proxy.c:622: error: dereferencing pointer 'req' does break strict-aliasing rules libvirt_proxy.c:621: error: dereferencing pointer 'req' does break strict-aliasing rules libvirt_proxy.c:610: error: dereferencing pointer 'req' does break strict-aliasing rules libvirt_proxy.c:603: error: dereferencing pointer 'req' does break strict-aliasing rules libvirt_proxy.c:601: error: dereferencing pointer 'req' does break strict-aliasing rules libvirt_proxy.c:599: error: dereferencing pointer 'req' does break strict-aliasing rules libvirt_proxy.c:598: error: dereferencing pointer 'req' does break strict-aliasing rules libvirt_proxy.c:594: error: dereferencing pointer 'req' does break strict-aliasing rules libvirt_proxy.c:593: error: dereferencing pointer 'req' does break strict-aliasing rules libvirt_proxy.c:588: error: dereferencing pointer 'req' does break strict-aliasing rules libvirt_proxy.c:583: error: dereferencing pointer 'req' does break strict-aliasing rules libvirt_proxy.c:582: error: dereferencing pointer 'req' does break strict-aliasing rules libvirt_proxy.c:580: error: dereferencing pointer 'req' does break strict-aliasing rules libvirt_proxy.c:579: error: dereferencing pointer 'req' does break strict-aliasing rules libvirt_proxy.c:569: error: dereferencing pointer 'req' does break strict-aliasing rules libvirt_proxy.c:562: error: dereferencing pointer 'req' does break strict-aliasing rules libvirt_proxy.c:560: error: dereferencing pointer 'req' does break strict-aliasing rules libvirt_proxy.c:559: error: dereferencing pointer 'req' does break strict-aliasing rules libvirt_proxy.c:552: error: dereferencing pointer 'req' does break strict-aliasing rules libvirt_proxy.c:543: error: dereferencing pointer 'req' does break strict-aliasing rules libvirt_proxy.c:541: error: dereferencing pointer 'req' does break strict-aliasing rules libvirt_proxy.c:534: error: dereferencing pointer 'req' does break strict-aliasing rules libvirt_proxy.c:533: error: dereferencing pointer 'req' does break strict-aliasing rules libvirt_proxy.c:511: error: dereferencing pointer 'req' does break strict-aliasing rules libvirt_proxy.c:497: error: dereferencing pointer 'req' does break strict-aliasing rules libvirt_proxy.c:497: error: dereferencing pointer 'req' does break strict-aliasing rules libvirt_proxy.c:490: error: dereferencing pointer 'req' does break strict-aliasing rules libvirt_proxy.c:489: error: dereferencing pointer 'req' does break strict-aliasing rules libvirt_proxy.c:486: error: dereferencing pointer 'req' does break strict-aliasing rules libvirt_proxy.c:478: error: dereferencing pointer 'req' does break strict-aliasing rules libvirt_proxy.c:478: error: dereferencing pointer 'req' does break strict-aliasing rules libvirt_proxy.c:476: error: dereferencing pointer 'req' does break strict-aliasing rules libvirt_proxy.c:473: error: dereferencing pointer 'req' does break strict-aliasing rules libvirt_proxy.c:470: error: dereferencing pointer 'req' does break strict-aliasing rules libvirt_proxy.c:467: error: dereferencing pointer 'req' does break strict-aliasing rules libvirt_proxy.c:467: error: dereferencing pointer 'req' does break strict-aliasing rules libvirt_proxy.c:465: error: dereferencing pointer 'req' does break strict-aliasing rules libvirt_proxy.c:462: error: dereferencing pointer 'req' does break strict-aliasing rules libvirt_proxy.c:460: error: dereferencing pointer 'req' does break strict-aliasing rules libvirt_proxy.c:454: error: dereferencing pointer 'req' does break strict-aliasing rules libvirt_proxy.c:452: error: dereferencing pointer 'req' does break strict-aliasing rules libvirt_proxy.c:451: error: dereferencing pointer 'req' does break strict-aliasing rules libvirt_proxy.c:445: error: dereferencing pointer 'req' does break strict-aliasing rules libvirt_proxy.c:440: error: dereferencing pointer 'req' does break strict-aliasing rules libvirt_proxy.c:438: error: dereferencing pointer 'req' does break strict-aliasing rules libvirt_proxy.c:434: error: dereferencing pointer 'req' does break strict-aliasing rules libvirt_proxy.c:432: error: dereferencing pointer 'req' does break strict-aliasing rules libvirt_proxy.c:399: error: dereferencing pointer 'req' does break strict-aliasing rules libvirt_proxy.c:393: error: dereferencing pointer 'req' does break strict-aliasing rules libvirt_proxy.c:388: error: dereferencing pointer 'req' does break strict-aliasing rules libvirt_proxy.c:387: error: dereferencing pointer 'req' does break strict-aliasing rules libvirt_proxy.c:386: error: dereferencing pointer 'req' does break strict-aliasing rules libvirt_proxy.c:455: error: dereferencing pointer 'req' does break strict-aliasing rules libvirt_proxy.c:564: error: dereferencing pointer 'req' does break strict-aliasing rules libvirt_proxy.c:310: error: dereferencing pointer 'req' does break strict-aliasing rules libvirt_proxy.c:311: error: dereferencing pointer 'req' does break strict-aliasing rules libvirt_proxy.c:318: error: dereferencing pointer 'req' does break strict-aliasing rules libvirt_proxy.c:321: error: dereferencing pointer 'req' does break strict-aliasing rules libvirt_proxy.c:333: error: dereferencing pointer 'req' does break strict-aliasing rules libvirt_proxy.c:335: error: dereferencing pointer 'req' does break strict-aliasing rules libvirt_proxy.c:404: error: dereferencing pointer 'req' does break strict-aliasing rules libvirt_proxy.c:405: error: dereferencing pointer 'req' does break strict-aliasing rules libvirt_proxy.c:355: note: initialized from here cc1: error: dereferencing pointer 'req' does break strict-aliasing rules libvirt_proxy.c:355: note: initialized from here Signed-off-by: Mark McLoughlin <markmc@redhat.com> --- proxy/libvirt_proxy.c | 47 +++++++++++++++++++++++++---------------------- 1 files changed, 25 insertions(+), 22 deletions(-) diff --git a/proxy/libvirt_proxy.c b/proxy/libvirt_proxy.c index 863dc32..9e2efbf 100644 --- a/proxy/libvirt_proxy.c +++ b/proxy/libvirt_proxy.c @@ -351,8 +351,11 @@ proxyWriteClientSocket(int nr, virProxyPacketPtr req) { static int proxyReadClientSocket(int nr) { virDomainDefPtr def; - virProxyFullPacket request; - virProxyPacketPtr req = (virProxyPacketPtr) &request; + union { + virProxyFullPacket full_request; + virProxyPacket request; + } r; + virProxyPacketPtr req = &r.request; int ret; char *xml, *ostype; @@ -398,7 +401,7 @@ retry: */ if (req->len > ret) { int total, extra; - char *base = (char *) &request; + char *base = (char *) &r; total = ret; while (total < req->len) { @@ -444,8 +447,8 @@ retry2: if (req->len != sizeof(virProxyPacket)) goto comm_error; - maxids = sizeof(request.extra.arg) / sizeof(int); - ret = xenHypervisorListDomains(conn, &request.extra.arg[0], + maxids = sizeof(r.full_request.extra.arg) / sizeof(int); + ret = xenHypervisorListDomains(conn, &r.full_request.extra.arg[0], maxids); if (ret < 0) { req->len = sizeof(virProxyPacket); @@ -469,9 +472,9 @@ retry2: case VIR_PROXY_DOMAIN_INFO: if (req->len != sizeof(virProxyPacket)) goto comm_error; - memset(&request.extra.dinfo, 0, sizeof(virDomainInfo)); + memset(&r.full_request.extra.dinfo, 0, sizeof(virDomainInfo)); ret = xenHypervisorGetDomInfo(conn, req->data.arg, - &request.extra.dinfo); + &r.full_request.extra.dinfo); if (ret < 0) { req->data.arg = -1; } else { @@ -495,8 +498,8 @@ retry2: name[1000] = 0; } req->len += VIR_UUID_BUFLEN + len + 1; - memcpy(&request.extra.str[0], uuid, VIR_UUID_BUFLEN); - strcpy(&request.extra.str[VIR_UUID_BUFLEN], name); + memcpy(&r.full_request.extra.str[0], uuid, VIR_UUID_BUFLEN); + strcpy(&r.full_request.extra.str[VIR_UUID_BUFLEN], name); } free(name); break; @@ -521,7 +524,7 @@ retry2: if (names != NULL) { while (*tmp != NULL) { ident = xenDaemonDomainLookupByName_ids(conn, *tmp, &uuid[0]); - if (!memcmp(uuid, &request.extra.str[0], VIR_UUID_BUFLEN)) { + if (!memcmp(uuid, &r.full_request.extra.str[0], VIR_UUID_BUFLEN)) { name = *tmp; break; } @@ -539,7 +542,7 @@ retry2: name[1000] = 0; } req->len = sizeof(virProxyPacket) + len + 1; - strcpy(&request.extra.str[0], name); + strcpy(&r.full_request.extra.str[0], name); req->data.arg = ident; } free(names); @@ -553,14 +556,14 @@ retry2: goto comm_error; ident = xenDaemonDomainLookupByName_ids(conn, - &request.extra.str[0], &uuid[0]); + &r.full_request.extra.str[0], &uuid[0]); if (ident < 0) { /* not found */ req->data.arg = -1; req->len = sizeof(virProxyPacket); } else { req->len = sizeof(virProxyPacket) + VIR_UUID_BUFLEN; - memcpy(&request.extra.str[0], uuid, VIR_UUID_BUFLEN); + memcpy(&r.full_request.extra.str[0], uuid, VIR_UUID_BUFLEN); req->data.arg = ident; } break; @@ -574,7 +577,7 @@ retry2: * cache them ? Since it's probably an unfrequent call better * not make assumption and do the xend RPC each call. */ - ret = xenDaemonNodeGetInfo(conn, &request.extra.ninfo); + ret = xenDaemonNodeGetInfo(conn, &r.full_request.extra.ninfo); if (ret < 0) { req->data.arg = -1; req->len = sizeof(virProxyPacket); @@ -594,12 +597,12 @@ retry2: req->len = sizeof (virProxyPacket); } else { int xmllen = strlen (xml); - if (xmllen > (int) sizeof (request.extra.str)) { + if (xmllen > (int) sizeof (r.full_request.extra.str)) { req->data.arg = -2; req->len = sizeof (virProxyPacket); } else { req->data.arg = 0; - memmove (request.extra.str, xml, xmllen); + memmove (r.full_request.extra.str, xml, xmllen); req->len = sizeof (virProxyPacket) + xmllen; } free (xml); @@ -616,7 +619,7 @@ retry2: * rather hard to get from that code path. So proxy * users won't see CPU pinning (last NULL arg) */ - def = xenDaemonDomainFetch(conn, request.data.arg, NULL, NULL); + def = xenDaemonDomainFetch(conn, r.full_request.data.arg, NULL, NULL); if (!def) { req->data.arg = -1; req->len = sizeof(virProxyPacket); @@ -627,12 +630,12 @@ retry2: req->len = sizeof(virProxyPacket); } else { int xmllen = strlen(xml); - if (xmllen > (int) sizeof(request.extra.str)) { + if (xmllen > (int) sizeof(r.full_request.extra.str)) { req->data.arg = -2; req->len = sizeof(virProxyPacket); } else { req->data.arg = 0; - memmove(&request.extra.str[0], xml, xmllen); + memmove(&r.full_request.extra.str[0], xml, xmllen); req->len = sizeof(virProxyPacket) + xmllen; } free(xml); @@ -644,18 +647,18 @@ retry2: if (req->len != sizeof(virProxyPacket)) goto comm_error; - ostype = xenStoreDomainGetOSTypeID(conn, request.data.arg); + ostype = xenStoreDomainGetOSTypeID(conn, r.full_request.data.arg); if (!ostype) { req->data.arg = -1; req->len = sizeof(virProxyPacket); } else { int ostypelen = strlen(ostype); - if (ostypelen > (int) sizeof(request.extra.str)) { + if (ostypelen > (int) sizeof(r.full_request.extra.str)) { req->data.arg = -2; req->len = sizeof(virProxyPacket); } else { req->data.arg = 0; - memmove(&request.extra.str[0], ostype, ostypelen); + memmove(&r.full_request.extra.str[0], ostype, ostypelen); req->len = sizeof(virProxyPacket) + ostypelen; } free(ostype); -- 1.6.0.6

On Fri, Feb 13, 2009 at 11:54:11AM +0000, Mark McLoughlin wrote:
libvirt_proxy.c: In function 'proxyReadClientSocket': libvirt_proxy.c:659: error: dereferencing pointer 'req' does break strict-aliasing rules libvirt_proxy.c:657: error: dereferencing pointer 'req' does break strict-aliasing rules [snip] libvirt_proxy.c:405: error: dereferencing pointer 'req' does break strict-aliasing rules libvirt_proxy.c:355: note: initialized from here cc1: error: dereferencing pointer 'req' does break strict-aliasing rules libvirt_proxy.c:355: note: initialized from here
Signed-off-by: Mark McLoughlin <markmc@redhat.com> --- proxy/libvirt_proxy.c | 47 +++++++++++++++++++++++++---------------------- 1 files changed, 25 insertions(+), 22 deletions(-)
diff --git a/proxy/libvirt_proxy.c b/proxy/libvirt_proxy.c index 863dc32..9e2efbf 100644 --- a/proxy/libvirt_proxy.c +++ b/proxy/libvirt_proxy.c @@ -351,8 +351,11 @@ proxyWriteClientSocket(int nr, virProxyPacketPtr req) { static int proxyReadClientSocket(int nr) { virDomainDefPtr def; - virProxyFullPacket request; - virProxyPacketPtr req = (virProxyPacketPtr) &request; + union { + virProxyFullPacket full_request; + virProxyPacket request; + } r; + virProxyPacketPtr req = &r.request;
Minor indentation bug there in the union.
int ret; char *xml, *ostype;
@@ -398,7 +401,7 @@ retry: */ if (req->len > ret) { int total, extra; - char *base = (char *) &request; + char *base = (char *) &r;
total = ret; while (total < req->len) { @@ -444,8 +447,8 @@ retry2:
if (req->len != sizeof(virProxyPacket)) goto comm_error; - maxids = sizeof(request.extra.arg) / sizeof(int); - ret = xenHypervisorListDomains(conn, &request.extra.arg[0], + maxids = sizeof(r.full_request.extra.arg) / sizeof(int); + ret = xenHypervisorListDomains(conn, &r.full_request.extra.arg[0], maxids); if (ret < 0) { req->len = sizeof(virProxyPacket); @@ -469,9 +472,9 @@ retry2: case VIR_PROXY_DOMAIN_INFO: if (req->len != sizeof(virProxyPacket)) goto comm_error; - memset(&request.extra.dinfo, 0, sizeof(virDomainInfo)); + memset(&r.full_request.extra.dinfo, 0, sizeof(virDomainInfo)); ret = xenHypervisorGetDomInfo(conn, req->data.arg, - &request.extra.dinfo); + &r.full_request.extra.dinfo); if (ret < 0) { req->data.arg = -1; } else { @@ -495,8 +498,8 @@ retry2: name[1000] = 0; } req->len += VIR_UUID_BUFLEN + len + 1; - memcpy(&request.extra.str[0], uuid, VIR_UUID_BUFLEN); - strcpy(&request.extra.str[VIR_UUID_BUFLEN], name); + memcpy(&r.full_request.extra.str[0], uuid, VIR_UUID_BUFLEN); + strcpy(&r.full_request.extra.str[VIR_UUID_BUFLEN], name); } free(name); break; @@ -521,7 +524,7 @@ retry2: if (names != NULL) { while (*tmp != NULL) { ident = xenDaemonDomainLookupByName_ids(conn, *tmp, &uuid[0]); - if (!memcmp(uuid, &request.extra.str[0], VIR_UUID_BUFLEN)) { + if (!memcmp(uuid, &r.full_request.extra.str[0], VIR_UUID_BUFLEN)) { name = *tmp; break; } @@ -539,7 +542,7 @@ retry2: name[1000] = 0; } req->len = sizeof(virProxyPacket) + len + 1; - strcpy(&request.extra.str[0], name); + strcpy(&r.full_request.extra.str[0], name); req->data.arg = ident; } free(names); @@ -553,14 +556,14 @@ retry2: goto comm_error;
ident = xenDaemonDomainLookupByName_ids(conn, - &request.extra.str[0], &uuid[0]); + &r.full_request.extra.str[0], &uuid[0]); if (ident < 0) { /* not found */ req->data.arg = -1; req->len = sizeof(virProxyPacket); } else { req->len = sizeof(virProxyPacket) + VIR_UUID_BUFLEN; - memcpy(&request.extra.str[0], uuid, VIR_UUID_BUFLEN); + memcpy(&r.full_request.extra.str[0], uuid, VIR_UUID_BUFLEN); req->data.arg = ident; } break; @@ -574,7 +577,7 @@ retry2: * cache them ? Since it's probably an unfrequent call better * not make assumption and do the xend RPC each call. */ - ret = xenDaemonNodeGetInfo(conn, &request.extra.ninfo); + ret = xenDaemonNodeGetInfo(conn, &r.full_request.extra.ninfo); if (ret < 0) { req->data.arg = -1; req->len = sizeof(virProxyPacket); @@ -594,12 +597,12 @@ retry2: req->len = sizeof (virProxyPacket); } else { int xmllen = strlen (xml); - if (xmllen > (int) sizeof (request.extra.str)) { + if (xmllen > (int) sizeof (r.full_request.extra.str)) { req->data.arg = -2; req->len = sizeof (virProxyPacket); } else { req->data.arg = 0; - memmove (request.extra.str, xml, xmllen); + memmove (r.full_request.extra.str, xml, xmllen); req->len = sizeof (virProxyPacket) + xmllen; } free (xml); @@ -616,7 +619,7 @@ retry2: * rather hard to get from that code path. So proxy * users won't see CPU pinning (last NULL arg) */ - def = xenDaemonDomainFetch(conn, request.data.arg, NULL, NULL); + def = xenDaemonDomainFetch(conn, r.full_request.data.arg, NULL, NULL); if (!def) { req->data.arg = -1; req->len = sizeof(virProxyPacket); @@ -627,12 +630,12 @@ retry2: req->len = sizeof(virProxyPacket); } else { int xmllen = strlen(xml); - if (xmllen > (int) sizeof(request.extra.str)) { + if (xmllen > (int) sizeof(r.full_request.extra.str)) { req->data.arg = -2; req->len = sizeof(virProxyPacket); } else { req->data.arg = 0; - memmove(&request.extra.str[0], xml, xmllen); + memmove(&r.full_request.extra.str[0], xml, xmllen); req->len = sizeof(virProxyPacket) + xmllen; } free(xml); @@ -644,18 +647,18 @@ retry2: if (req->len != sizeof(virProxyPacket)) goto comm_error;
- ostype = xenStoreDomainGetOSTypeID(conn, request.data.arg); + ostype = xenStoreDomainGetOSTypeID(conn, r.full_request.data.arg); if (!ostype) { req->data.arg = -1; req->len = sizeof(virProxyPacket); } else { int ostypelen = strlen(ostype); - if (ostypelen > (int) sizeof(request.extra.str)) { + if (ostypelen > (int) sizeof(r.full_request.extra.str)) { req->data.arg = -2; req->len = sizeof(virProxyPacket); } else { req->data.arg = 0; - memmove(&request.extra.str[0], ostype, ostypelen); + memmove(&r.full_request.extra.str[0], ostype, ostypelen); req->len = sizeof(virProxyPacket) + ostypelen; } free(ostype); --
ACK, modulo the whitespace bug noted above 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 :|

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@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 :|

On Fri, Feb 13, 2009 at 11:54:09AM +0000, Mark McLoughlin wrote:
bridge.c: In function 'brSetInetAddr': bridge.c:665: error: dereferencing pointer '({anonymous})' does break strict-aliasing rules bridge.c:665: note: initialized from here bridge.c:666: error: dereferencing pointer '({anonymous})' does break strict-aliasing rules bridge.c:666: note: initialized from here
Signed-off-by: Mark McLoughlin <markmc@redhat.com> --- src/bridge.c | 10 ++++++++-- 1 files changed, 8 insertions(+), 2 deletions(-)
diff --git a/src/bridge.c b/src/bridge.c index 990a567..fc11429 100644 --- a/src/bridge.c +++ b/src/bridge.c @@ -642,6 +642,10 @@ brSetInetAddr(brControl *ctl, int cmd, const char *addr) { + union { + struct sockaddr sa; + struct sockaddr_in sa_in; + } s; struct ifreq ifr; struct in_addr inaddr; int len, ret; @@ -662,8 +666,10 @@ brSetInetAddr(brControl *ctl, else if (ret == 0) return EINVAL;
- ((struct sockaddr_in *)&ifr.ifr_data)->sin_family = AF_INET; - ((struct sockaddr_in *)&ifr.ifr_data)->sin_addr = inaddr; + s.sa_in.sin_family = AF_INET; + s.sa_in.sin_addr = inaddr; + + ifr.ifr_addr = s.sa;
if (ioctl(ctl->fd, cmd, &ifr) < 0) return errno;
ACK, though I notice we only cope with IPv4 here ! Have to fix that one day :-) 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 :|

On Fri, Feb 13, 2009 at 11:54:08AM +0000, Mark McLoughlin wrote:
Hi,
It seems gcc's strict aliasing rules got stricter with gcc-4.4.
The basic rule is that two pointers of different types can't be used to reference the same address in memory. One exception is using a char* and another is when different types are members of a union.
I've used unions to fix all the warnings I see with current CVS HEAD. I can't say I like the solution all that much, so if anyone has better ideas ...
For the proxy we could get around it by changing it so that we only had one struct to use, just reading part of the struct to start with, and then reading the remainder if needed. For the socket stuff, I don't see any alternative, since the socket() API basically requires that you have these horrible casts between the different sockaddr structs. 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 :|
participants (2)
-
Daniel P. Berrange
-
Mark McLoughlin