[Lldb-commits] [lldb] r319934 - [MappedHash] Fix alignment violations

Vedant Kumar via lldb-commits lldb-commits at lists.llvm.org
Wed Dec 6 11:21:08 PST 2017


Author: vedantk
Date: Wed Dec  6 11:21:08 2017
New Revision: 319934

URL: http://llvm.org/viewvc/llvm-project?rev=319934&view=rev
Log:
[MappedHash] Fix alignment violations

This fixes a few alignment problems pointed out by UBSan, and is
otherwise NFC.

Modified:
    lldb/trunk/include/lldb/Core/MappedHash.h

Modified: lldb/trunk/include/lldb/Core/MappedHash.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/MappedHash.h?rev=319934&r1=319933&r2=319934&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Core/MappedHash.h (original)
+++ lldb/trunk/include/lldb/Core/MappedHash.h Wed Dec  6 11:21:08 2017
@@ -357,21 +357,24 @@ public:
     }
 
     uint32_t GetHashIndex(uint32_t bucket_idx) const {
+      uint32_t result = UINT32_MAX;
       if (m_hash_indexes && bucket_idx < m_header.bucket_count)
-        return m_hash_indexes[bucket_idx];
-      return UINT32_MAX;
+        memcpy(&result, m_hash_indexes + bucket_idx, sizeof(uint32_t));
+      return result;
     }
 
     uint32_t GetHashValue(uint32_t hash_idx) const {
+      uint32_t result = UINT32_MAX;
       if (m_hash_values && hash_idx < m_header.hashes_count)
-        return m_hash_values[hash_idx];
-      return UINT32_MAX;
+        memcpy(&result, m_hash_values + hash_idx, sizeof(uint32_t));
+      return result;
     }
 
     uint32_t GetHashDataOffset(uint32_t hash_idx) const {
+      uint32_t result = UINT32_MAX;
       if (m_hash_offsets && hash_idx < m_header.hashes_count)
-        return m_hash_offsets[hash_idx];
-      return UINT32_MAX;
+        memcpy(&result, m_hash_offsets + hash_idx, sizeof(uint32_t));
+      return result;
     }
 
     bool Find(const char *name, Pair &pair) const {




More information about the lldb-commits mailing list