INN commit: trunk/tests/lib (network-t.c)

INN Commit rra at isc.org
Sun Aug 21 00:45:16 UTC 2011


    Date: Saturday, August 20, 2011 @ 17:45:16
  Author: eagle
Revision: 9358

Work around gcc 4.4 misdiagnosis of strict aliasing violation
    
gcc 4.4 thinks part of the network test suite is a strict aliasing
violation because it declares a local struct sockaddr_storage and
then casts it to other structs.  Allocate it from the heap instead
to work around this bug.

Modified:
  trunk/tests/lib/network-t.c

-------------+
 network-t.c |   18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)

Modified: network-t.c
===================================================================
--- network-t.c	2011-08-20 23:23:26 UTC (rev 9357)
+++ network-t.c	2011-08-21 00:45:16 UTC (rev 9358)
@@ -94,22 +94,28 @@
  * A varient version of the server portion of the test.  Takes an array of
  * sockets and the size of the sockets and accepts a connection on any of
  * those sockets.
+ *
+ * saddr is allocated from the heap instead of using a local struct
+ * sockaddr_storage to work around a misdiagnosis of strict aliasing
+ * violations from gcc 4.4 (fixed in later versions).
  */
 static void
 listener_any(socket_type fds[], unsigned int count)
 {
     socket_type client;
     unsigned int i;
-    struct sockaddr_storage ss;
-    socklen_t sslen;
+    struct sockaddr *saddr;
+    socklen_t slen;
 
-    sslen = sizeof(ss);
-    client = network_accept_any(fds, count, (struct sockaddr *) &ss, &sslen);
+    slen = sizeof(struct sockaddr_storage);
+    saddr = xmalloc(slen);
+    client = network_accept_any(fds, count, saddr, &slen);
     listener_handler(client);
-    is_int(AF_INET, ss.ss_family, "...address family is IPv4");
+    is_int(AF_INET, saddr->sa_family, "...address family is IPv4");
     is_int(htonl(INADDR_LOOPBACK),
-           ((struct sockaddr_in *) &ss)->sin_addr.s_addr,
+           ((struct sockaddr_in *) saddr)->sin_addr.s_addr,
            "...and client address is 127.0.0.1");
+    free(saddr);
     for (i = 0; i < count; i++)
         close(fds[i]);
 }




More information about the inn-committers mailing list