You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by so...@apache.org on 2013/08/17 21:59:16 UTC

[3/5] git commit: TS-302: Switch to using Alias32 type so we aren't breaking strict aliasing. These instances should be converted to using inet_ntop or similar to make then v6 compliant.

TS-302: Switch to using Alias32 type so we aren't breaking strict aliasing.
These instances should be converted to using inet_ntop or similar to make then
v6 compliant.


Project: http://git-wip-us.apache.org/repos/asf/trafficserver/repo
Commit: http://git-wip-us.apache.org/repos/asf/trafficserver/commit/45afd4ff
Tree: http://git-wip-us.apache.org/repos/asf/trafficserver/tree/45afd4ff
Diff: http://git-wip-us.apache.org/repos/asf/trafficserver/diff/45afd4ff

Branch: refs/heads/master
Commit: 45afd4ff5490fdc058c8376f8e36f0b349f80b89
Parents: c40c601
Author: Phil Sorber <so...@apache.org>
Authored: Sat Aug 17 12:12:01 2013 -0600
Committer: Phil Sorber <so...@apache.org>
Committed: Sat Aug 17 12:12:16 2013 -0600

----------------------------------------------------------------------
 iocore/cluster/ClusterHandlerBase.cc | 14 ++++++--------
 iocore/cluster/ClusterMachine.cc     |  7 +++----
 2 files changed, 9 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/trafficserver/blob/45afd4ff/iocore/cluster/ClusterHandlerBase.cc
----------------------------------------------------------------------
diff --git a/iocore/cluster/ClusterHandlerBase.cc b/iocore/cluster/ClusterHandlerBase.cc
index 6647354..520e3a3 100644
--- a/iocore/cluster/ClusterHandlerBase.cc
+++ b/iocore/cluster/ClusterHandlerBase.cc
@@ -1453,13 +1453,12 @@ void
 ClusterHandler::dump_write_msg(int res)
 {
   // Debug support for inter cluster message trace
-  unsigned char x[4];
-  memset(x, 0, sizeof(x));
-  *(uint32_t *) & x = (uint32_t) ((struct sockaddr_in *)(net_vc->get_remote_addr()))->sin_addr.s_addr;
+  Alias32 x;
+  x.u32 = (uint32_t) ((struct sockaddr_in *)(net_vc->get_remote_addr()))->sin_addr.s_addr;
 
   fprintf(stderr,
           "[W] %hhu.%hhu.%hhu.%hhu SeqNo=%u, Cnt=%d, CntlCnt=%d Todo=%d, Res=%d\n",
-          x[0], x[1], x[2], x[3], write.sequence_number, write.msg.count, write.msg.control_bytes, write.to_do, res);
+          x.byte[0], x.byte[1], x.byte[2], x.byte[3], write.sequence_number, write.msg.count, write.msg.control_bytes, write.to_do, res);
   for (int i = 0; i < write.msg.count; ++i) {
     fprintf(stderr, "   d[%i] Type=%d, Chan=%d, SeqNo=%d, Len=%u\n",
             i, (write.msg.descriptor[i].type ? 1 : 0),
@@ -1472,12 +1471,11 @@ void
 ClusterHandler::dump_read_msg()
 {
   // Debug support for inter cluster message trace
-  unsigned char x[4];
-  memset(x, 0, sizeof(x));
-  *(uint32_t *) & x = (uint32_t) ((struct sockaddr_in *)(net_vc->get_remote_addr()))->sin_addr.s_addr;
+  Alias32 x;
+  x.u32 = (uint32_t) ((struct sockaddr_in *)(net_vc->get_remote_addr()))->sin_addr.s_addr;
 
   fprintf(stderr, "[R] %hhu.%hhu.%hhu.%hhu  SeqNo=%u, Cnt=%d, CntlCnt=%d\n",
-          x[0], x[1], x[2], x[3], read.sequence_number, read.msg.count, read.msg.control_bytes);
+          x.byte[0], x.byte[1], x.byte[2], x.byte[3], read.sequence_number, read.msg.count, read.msg.control_bytes);
   for (int i = 0; i < read.msg.count; ++i) {
     fprintf(stderr, "   d[%i] Type=%d, Chan=%d, SeqNo=%d, Len=%u\n",
             i, (read.msg.descriptor[i].type ? 1 : 0),

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/45afd4ff/iocore/cluster/ClusterMachine.cc
----------------------------------------------------------------------
diff --git a/iocore/cluster/ClusterMachine.cc b/iocore/cluster/ClusterMachine.cc
index afc4c11..00e99e6 100644
--- a/iocore/cluster/ClusterMachine.cc
+++ b/iocore/cluster/ClusterMachine.cc
@@ -132,10 +132,9 @@ ClusterMachine::ClusterMachine(char *ahostname, unsigned int aip, int aport)
     struct hostent *r = ink_gethostbyaddr_r((char *) &ip, sizeof(int), AF_INET, &data);
 
     if (r == NULL) {
-      unsigned char x[4];
-      memset(x, 0, sizeof(x));
-      *(uint32_t *) & x = (uint32_t) ip;
-      Debug("machine_debug", "unable to reverse DNS %u.%u.%u.%u: %d", x[0], x[1], x[2], x[3], data.herrno);
+      Alias32 x;
+      memcpy(&x.u32, &ip, sizeof(x.u32));
+      Debug("machine_debug", "unable to reverse DNS %u.%u.%u.%u: %d", x.byte[0], x.byte[1], x.byte[2], x.byte[3], data.herrno);
     } else
       hostname = ats_strdup(r->h_name);
   }