Skip to content

Commit 32197d1

Browse files
committed
Fix UBSan "misaligned-pointer-use" warning on aarch64
See: bitcoin/bitcoin#29178
1 parent 0bac72c commit 32197d1

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/crc32c_arm64.cc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
#include <cstddef>
1414
#include <cstdint>
15+
#include <cstring>
1516

1617
#include "./crc32c_internal.h"
1718
#ifdef CRC32C_HAVE_CONFIG_H
@@ -67,7 +68,7 @@ namespace crc32c {
6768
uint32_t ExtendArm64(uint32_t crc, const uint8_t *data, size_t size) {
6869
int64_t length = size;
6970
uint32_t crc0, crc1, crc2, crc3;
70-
uint64_t t0, t1, t2;
71+
uint64_t t0, t1, t2, t3;
7172

7273
// k0=CRC(x^(3*SEGMENTBYTES*8)), k1=CRC(x^(2*SEGMENTBYTES*8)),
7374
// k2=CRC(x^(SEGMENTBYTES*8))
@@ -98,7 +99,8 @@ uint32_t ExtendArm64(uint32_t crc, const uint8_t *data, size_t size) {
9899
}
99100

100101
while (length >= 8) {
101-
crc = __crc32cd(crc, *(uint64_t *)data);
102+
std::memcpy(&t3, data, sizeof t3);
103+
crc = __crc32cd(crc, t3);
102104
data += 8;
103105
length -= 8;
104106
}

0 commit comments

Comments
 (0)