Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(822)

Unified Diff: runtime/bin/socket_linux.cc

Issue 14426004: Anoher try to avoid GCC strict-aliasing error (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/bin/socket_linux.cc
diff --git a/runtime/bin/socket_linux.cc b/runtime/bin/socket_linux.cc
index fb0cd41c8c9b252172015df2fd3118f367cabe68..0ce00d028010aa7197d1e2ddaea79ee235e420e3 100644
--- a/runtime/bin/socket_linux.cc
+++ b/runtime/bin/socket_linux.cc
@@ -25,12 +25,20 @@
ntohs(reinterpret_cast<struct sockaddr_in6*>(&addr)->sin6_port)
+typedef union {
+ struct sockaddr sa;
+ struct sockaddr_in sa_in;
+ struct sockaddr_in6 sa_in6;
+ struct sockaddr_storage sa_stor;
+} address;
+
+
static void SetPort(sockaddr_storage* addr, int port) {
- char* ptr = reinterpret_cast<char*>(addr);
- if (addr->ss_family == AF_INET) {
- reinterpret_cast<struct sockaddr_in*>(ptr)->sin_port = htons(port);
+ address* ptr = reinterpret_cast<address*>(addr);
+ if (ptr->sa_stor.ss_family == AF_INET) {
+ ptr->sa_in.sin_port = htons(port);
} else { \
- reinterpret_cast<struct sockaddr_in6*>(ptr)->sin6_port = htons(port);
+ ptr->sa_in6.sin6_port = htons(port);
}
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698