Author: loonycyborg
Date: Sun Jul 24 14:27:21 2011
New Revision: 50380

URL: http://svn.gna.org/viewcvs/wesnoth?rev=50380&view=rev
Log:
Fixed strict aliasing warnings from old network code.

Modified:
    trunk/src/network.cpp

Modified: trunk/src/network.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/network.cpp?rev=50380&r1=50379&r2=50380&view=diff
==============================================================================
--- trunk/src/network.cpp (original)
+++ trunk/src/network.cpp Sun Jul 24 14:27:21 2011
@@ -456,9 +456,12 @@
        }
 
        // Send data telling the remote host that this is a new connection
-       char buf[4] ALIGN_4;
-       SDLNet_Write32(0, reinterpret_cast<void*>(buf));
-       const int nbytes = SDLNet_TCP_Send(sock,buf,4);
+       union
+       {
+       char data[4] ALIGN_4;
+       } buf;
+       SDLNet_Write32(0, &buf);
+       const int nbytes = SDLNet_TCP_Send(sock,&buf,4);
        if(nbytes != 4) {
                SDLNet_TCP_Close(sock);
                error_ = "Could not send initial handshake";
@@ -530,7 +533,10 @@
 
        // Receive the 4 bytes telling us if they're a new connection
        // or trying to recover a connection
-       char buf[4] ALIGN_4;
+       union
+       {
+       char data[4] ALIGN_4;
+       } buf;
 
        const TCPsocket psock = *i;
        SDLNet_TCP_DelSocket(pending_socket_set,psock);
@@ -538,14 +544,14 @@
 
        DBG_NW << "receiving data from pending socket...\n";
 
-       const int len = SDLNet_TCP_Recv(psock,buf,4);
+       const int len = SDLNet_TCP_Recv(psock,&buf,4);
        if(len != 4) {
                WRN_NW << "pending socket disconnected\n";
                SDLNet_TCP_Close(psock);
                return 0;
        }
 
-       const int handle = SDLNet_Read32(reinterpret_cast<void*>(buf));
+       const int handle = SDLNet_Read32(&buf);
 
        DBG_NW << "received handshake from client: '" << handle << "'\n";
 
@@ -560,8 +566,8 @@
        const connection connect = create_connection(psock,"",0);
 
        // Send back their connection number
-       SDLNet_Write32(connect, reinterpret_cast<void*>(buf));
-       const int nbytes = SDLNet_TCP_Send(psock,buf,4);
+       SDLNet_Write32(connect, &buf);
+       const int nbytes = SDLNet_TCP_Send(psock,&buf,4);
        if(nbytes != 4) {
                SDLNet_TCP_DelSocket(socket_set,psock);
                SDLNet_TCP_Close(psock);
@@ -740,13 +746,15 @@
                        // See if this socket is still waiting for it to be 
assigned its remote handle.
                        // If it is, then the first 4 bytes must be the remote 
handle.
                        if(is_pending_remote_handle(*i)) {
-                               char buf[4] ALIGN_4;
-                               int len = SDLNet_TCP_Recv(sock,buf,4);
+                               union {
+                               char data[4] ALIGN_4;
+                               } buf;
+                               int len = SDLNet_TCP_Recv(sock,&buf,4);
                                if(len != 4) {
                                        throw error("Remote host 
disconnected",*i);
                                }
 
-                               const int remote_handle = 
SDLNet_Read32(reinterpret_cast<void*>(buf));
+                               const int remote_handle = SDLNet_Read32(&buf);
                                set_remote_handle(*i,remote_handle);
 
                                continue;
@@ -849,13 +857,15 @@
                        // See if this socket is still waiting for it to be 
assigned its remote handle.
                        // If it is, then the first 4 bytes must be the remote 
handle.
                        if(is_pending_remote_handle(*i)) {
-                               char buf[4] ALIGN_4;
-                               int len = SDLNet_TCP_Recv(sock,buf,4);
+                               union {
+                               char data[4] ALIGN_4;
+                               } buf;
+                               int len = SDLNet_TCP_Recv(sock,&buf,4);
                                if(len != 4) {
                                        throw error("Remote host 
disconnected",*i);
                                }
 
-                               const int remote_handle = 
SDLNet_Read32(reinterpret_cast<void*>(buf));
+                               const int remote_handle = SDLNet_Read32(&buf);
                                set_remote_handle(*i,remote_handle);
 
                                continue;


_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits

Reply via email to