[PATCH 7/7] Avoid cast alignment warnings in port allocator test

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

 



From: "Daniel P. Berrange" <berrange@xxxxxxxxxx>

To avoid

virportallocatortest.c: In function 'bind':
virportallocatortest.c:34:33: warning: cast increases required alignment of target type [-Wcast-align]
     struct sockaddr_in *saddr = (struct sockaddr_in *)addr;
                                 ^

Signed-off-by: Daniel P. Berrange <berrange@xxxxxxxxxx>
---
 tests/virportallocatortest.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/tests/virportallocatortest.c b/tests/virportallocatortest.c
index 9931e11..1935602 100644
--- a/tests/virportallocatortest.c
+++ b/tests/virportallocatortest.c
@@ -31,12 +31,14 @@ int bind(int sockfd ATTRIBUTE_UNUSED,
          const struct sockaddr *addr,
          socklen_t addrlen ATTRIBUTE_UNUSED)
 {
-    struct sockaddr_in *saddr = (struct sockaddr_in *)addr;
+    struct sockaddr_in saddr;
 
-    if (saddr->sin_port == htons(5900) ||
-        saddr->sin_port == htons(5904) ||
-        saddr->sin_port == htons(5905) ||
-        saddr->sin_port == htons(5906)) {
+    memcpy(&saddr, addr, sizeof(saddr));
+
+    if (saddr.sin_port == htons(5900) ||
+        saddr.sin_port == htons(5904) ||
+        saddr.sin_port == htons(5905) ||
+        saddr.sin_port == htons(5906)) {
         errno = EADDRINUSE;
         return -1;
     }
-- 
1.8.1.4

--
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]