[libgdata/libgdata-0-14: 13/18] tests: Fix strict aliasing problems with struct sockaddr



commit 9124c1e8829e20082fa5c8d54e7f53e1460141cc
Author: Philip Withnall <philip withnall collabora co uk>
Date:   Tue Nov 19 19:05:04 2013 +0000

    tests: Fix strict aliasing problems with struct sockaddr
    
    Make it a union and GCC is happy again.

 gdata/tests/streams.c |   13 ++++++++-----
 1 files changed, 8 insertions(+), 5 deletions(-)
---
diff --git a/gdata/tests/streams.c b/gdata/tests/streams.c
index a8c77a4..7b4fe5f 100644
--- a/gdata/tests/streams.c
+++ b/gdata/tests/streams.c
@@ -99,7 +99,10 @@ test_download_stream_download_server_content_length_handler_cb (SoupServer *serv
 static SoupServer *
 create_server (SoupServerCallback callback, gpointer user_data, GMainContext **async_context)
 {
-       struct sockaddr_in sock;
+       union {
+               struct sockaddr_in in;
+               struct sockaddr norm;
+       } sock;
        SoupAddress *addr;
        SoupServer *server;
 
@@ -107,11 +110,11 @@ create_server (SoupServerCallback callback, gpointer user_data, GMainContext **a
 
        /* Create the server */
        memset (&sock, 0, sizeof (sock));
-       sock.sin_family = AF_INET;
-       sock.sin_addr.s_addr = htonl (INADDR_LOOPBACK);
-       sock.sin_port = htons (0); /* random port */
+       sock.in.sin_family = AF_INET;
+       sock.in.sin_addr.s_addr = htonl (INADDR_LOOPBACK);
+       sock.in.sin_port = htons (0); /* random port */
 
-       addr = soup_address_new_from_sockaddr ((struct sockaddr *) &sock, sizeof (sock));
+       addr = soup_address_new_from_sockaddr (&sock.norm, sizeof (sock.norm));
        g_assert (addr != NULL);
 
        *async_context = g_main_context_new ();


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