Fix strict aliasing warning.
authorPeter D. Barnes, Jr. <barnes26@llnl.gov>
Mon, 15 Jul 2013 14:19:57 -0700
changeset 9949 254133001f4f
parent 9948 c99418afca49
child 9950 9963d622b120
Fix strict aliasing warning.
src/core/model/hash-function.h
--- a/src/core/model/hash-function.h	Mon Jul 15 21:26:03 2013 +0200
+++ b/src/core/model/hash-function.h	Mon Jul 15 14:19:57 2013 -0700
@@ -21,6 +21,7 @@
 #ifndef HASHFUNCTION_H
 #define HASHFUNCTION_H
 
+#include <cstring>  // memcpy
 #include "simple-ref-count.h"
 
 namespace ns3 {
@@ -143,8 +144,11 @@
   }
   uint32_t GetHash32 (const char * buffer, const size_t size)
   {
-    uint64_t hash = GetHash64 (buffer, size);
-    return *(uint32_t *)(void *)(&hash);
+    uint32_t hash32;
+    uint64_t hash64 = GetHash64 (buffer, size);
+
+    memcpy (&hash32, &hash64, sizeof (hash32));
+    return hash32;
   }
   void clear () { };
 private: