[libvirt] [PATCH 2/3] Fix qemud.c warnings with gcc-4.4

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

--
Libvir-list mailing list
Libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list

[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]