From: "Daniel P. Berrange" <berrange(a)redhat.com>
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(a)redhat.com>
---
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