[collectd] [PATCH] Fix gcc-4.4 strict-aliasing issue
apevec at gmail.com
apevec at gmail.com
Tue Mar 3 18:23:03 CET 2009
From: Alan Pevec <apevec at redhat.com>
cc1: warnings being treated as errors
liboping.c: In function 'ping_host_add':
liboping.c:995: error: dereferencing pointer 'si' does break strict-aliasing rules
...
Signed-off-by: Alan Pevec <apevec at redhat.com>
---
src/liboping/liboping.c | 18 ++++++++++++------
1 files changed, 12 insertions(+), 6 deletions(-)
diff --git a/src/liboping/liboping.c b/src/liboping/liboping.c
index 13bcc92..94adb1d 100644
--- a/src/liboping/liboping.c
+++ b/src/liboping/liboping.c
@@ -987,9 +987,12 @@ int ping_host_add (pingobj_t *obj, const char *host)
if (ai_ptr->ai_family == AF_INET)
{
- struct sockaddr_in *si;
-
- si = (struct sockaddr_in *) &sockaddr;
+ union {
+ struct sockaddr_storage any_socket;
+ struct sockaddr_in si;
+ } s;
+ s.any_socket = sockaddr;
+ struct sockaddr_in *si = &s.si;
si->sin_family = AF_INET;
si->sin_port = htons (ph->ident);
si->sin_addr.s_addr = htonl (INADDR_ANY);
@@ -999,9 +1002,12 @@ int ping_host_add (pingobj_t *obj, const char *host)
}
else if (ai_ptr->ai_family == AF_INET6)
{
- struct sockaddr_in6 *si;
-
- si = (struct sockaddr_in6 *) &sockaddr;
+ union {
+ struct sockaddr_storage any_socket;
+ struct sockaddr_in6 si;
+ } s;
+ s.any_socket = sockaddr;
+ struct sockaddr_in6 *si = &s.si;
si->sin6_family = AF_INET6;
si->sin6_port = htons (ph->ident);
si->sin6_addr = in6addr_any;
--
1.6.0.6
More information about the collectd
mailing list