[svn-commits] russell: branch 1.8 r292188 - /branches/1.8/main/netsock2.c

SVN commits to the Digium repositories svn-commits at lists.digium.com
Mon Oct 18 14:50:05 CDT 2010


Author: russell
Date: Mon Oct 18 14:50:04 2010
New Revision: 292188

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=292188
Log:
Resolve some compiler errors in ast_sockaddr_is_any().

These errors came up once this function was used from within netsock2.c.
The errors were like the following:

netsock2.c:393: error: dereferencing pointer ‘({anonymous})’ does break strict-aliasing rules

The usage of a union here avoids this problem.

Modified:
    branches/1.8/main/netsock2.c

Modified: branches/1.8/main/netsock2.c
URL: http://svnview.digium.com/svn/asterisk/branches/1.8/main/netsock2.c?view=diff&rev=292188&r1=292187&r2=292188
==============================================================================
--- branches/1.8/main/netsock2.c (original)
+++ branches/1.8/main/netsock2.c Mon Oct 18 14:50:04 2010
@@ -389,11 +389,16 @@
 
 int ast_sockaddr_is_any(const struct ast_sockaddr *addr)
 {
-	return (ast_sockaddr_is_ipv4(addr) &&
-		((const struct sockaddr_in *)&addr->ss)->sin_addr.s_addr ==
-		INADDR_ANY) ||
-	    (ast_sockaddr_is_ipv6(addr) &&
-	     IN6_IS_ADDR_UNSPECIFIED(&((const struct sockaddr_in6 *)&addr->ss)->sin6_addr));
+	union {
+		struct sockaddr_storage ss;
+		struct sockaddr_in sin;
+		struct sockaddr_in6 sin6;
+	} tmp_addr = {
+		.ss = addr->ss,
+	};
+
+	return (ast_sockaddr_is_ipv4(addr) && (tmp_addr.sin.sin_addr.s_addr == INADDR_ANY)) ||
+	    (ast_sockaddr_is_ipv6(addr) && IN6_IS_ADDR_UNSPECIFIED(&tmp_addr.sin6.sin6_addr));
 }
 
 int ast_sockaddr_hash(const struct ast_sockaddr *addr)




More information about the svn-commits mailing list