folly: Hash: use loadUnassigned to avoid UB in hsieh_hash32_buf (fsanitize=alignment)
authorLucian Grijincu <lucian@fb.com>
Mon, 1 Feb 2016 19:51:51 +0000 (11:51 -0800)
committerfacebook-github-bot-1 <folly-bot@fb.com>
Mon, 1 Feb 2016 20:20:30 +0000 (12:20 -0800)
Reviewed By: philippv

Differential Revision: D2886152

fb-gh-sync-id: 64c3543db831c72c7f4cf307867223270293066e

folly/Hash.h

index 7e44fbb2dec986cedebce4e5e8bf72452338c967..0def3efccb3a2f604fdd176bffca7d2ef6b5461b 100644 (file)
@@ -25,6 +25,7 @@
 #include <utility>
 
 #include <folly/ApplyTuple.h>
+#include <folly/Bits.h>
 #include <folly/SpookyHashV1.h>
 #include <folly/SpookyHashV2.h>
 
@@ -277,7 +278,7 @@ inline uint64_t fnv64(const std::string& str,
  * Paul Hsieh: http://www.azillionmonkeys.com/qed/hash.html
  */
 
-#define get16bits(d) (*((const uint16_t*) (d)))
+#define get16bits(d) folly::loadUnaligned<uint16_t>(d)
 
 inline uint32_t hsieh_hash32_buf(const void* buf, size_t len) {
   // forcing signed char, since other platforms can use unsigned