Skip to content

Commit 76edd74

Browse files
authored
Merge pull request #432 from ClickHouse/clickhouse-fix-ubsan-clang-18
Fix UBSan report while compiling with clang-18
2 parents 836b87e + 62aa4c8 commit 76edd74

1 file changed

Lines changed: 5 additions & 6 deletions

File tree

common/include/MurmurHash3.h

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,10 @@ typedef struct {
7171
// Block read - if your platform needs to do endian-swapping or can only
7272
// handle aligned reads, do the conversion here
7373

74-
MURMUR3_FORCE_INLINE uint64_t getblock64 ( const uint64_t * p, size_t i )
74+
MURMUR3_FORCE_INLINE uint64_t getblock64 ( const uint8_t * p, size_t i )
7575
{
7676
uint64_t res;
77-
memcpy(&res, p + i, sizeof(res));
77+
memcpy(&res, p + i * sizeof(uint64_t), sizeof(res));
7878
return res;
7979
}
8080

@@ -104,13 +104,12 @@ MURMUR3_FORCE_INLINE void MurmurHash3_x64_128(const void* key, size_t lenBytes,
104104

105105
// Number of full 128-bit blocks of 16 bytes.
106106
// Possible exclusion of a remainder of up to 15 bytes.
107-
const size_t nblocks = lenBytes >> 4; // bytes / 16
107+
const size_t nblocks = lenBytes >> 4; // bytes / 16
108108

109109
// Process the 128-bit blocks (the body) into the hash
110-
const uint64_t* blocks = (const uint64_t*)(data);
111110
for (size_t i = 0; i < nblocks; ++i) { // 16 bytes per block
112-
uint64_t k1 = getblock64(blocks, i * 2 + 0);
113-
uint64_t k2 = getblock64(blocks, i * 2 + 1);
111+
uint64_t k1 = getblock64(data, i * 2 + 0);
112+
uint64_t k2 = getblock64(data, i * 2 + 1);
114113

115114
k1 *= c1; k1 = MURMUR3_ROTL64(k1,31); k1 *= c2; out.h1 ^= k1;
116115
out.h1 = MURMUR3_ROTL64(out.h1,27);

0 commit comments

Comments
 (0)