aboutsummaryrefslogtreecommitdiff
path: root/platform/linux-generic/arch/x86
diff options
context:
space:
mode:
authorJere Leppänen <jere.leppanen@nokia.com>2024-03-20 17:22:45 +0200
committerMatias Elo <matias.elo@nokia.com>2024-04-16 16:49:46 +0300
commit0a444e7ea792ad42ea5655b828c44bb9bedbc8eb (patch)
treeebe535802eac7b51bb7a0242dbf8007ed8591de8 /platform/linux-generic/arch/x86
parent1274f5d62231aa1bfdb9fc982e3e33cde269d5e3 (diff)
linux-gen: hash: use unaligned types in _odp_hash_crc32c()
Since the data is not necessarily aligned, use unaligned types to read it, in order to avoid undefined behavior. Fixes GCC undefined sanitizer errors: hash_crc32.h:35:24: runtime error: load of misaligned address 0x0000005e12d4 for type 'const uint64_t', which requires 8 byte alignment hash_crc32.h:40:14: runtime error: load of misaligned address 0x0000005ff879 for type 'const uint32_t', which requires 4 byte alignment hash_crc32.h:51:47: runtime error: load of misaligned address 0x0000005e67af for type 'const uint16_t', which requires 2 byte alignment Signed-off-by: Jere Leppänen <jere.leppanen@nokia.com> Reviewed-by: Janne Peltonen <janne.peltonen@nokia.com>
Diffstat (limited to 'platform/linux-generic/arch/x86')
-rw-r--r--platform/linux-generic/arch/x86/odp/api/abi/hash_crc32.h9
1 files changed, 5 insertions, 4 deletions
diff --git a/platform/linux-generic/arch/x86/odp/api/abi/hash_crc32.h b/platform/linux-generic/arch/x86/odp/api/abi/hash_crc32.h
index 6743a4da2..576b68f20 100644
--- a/platform/linux-generic/arch/x86/odp/api/abi/hash_crc32.h
+++ b/platform/linux-generic/arch/x86/odp/api/abi/hash_crc32.h
@@ -9,6 +9,7 @@
extern "C" {
#endif
+#include <odp/api/std_types.h>
#include <stdint.h>
uint32_t _odp_hash_crc32_generic(const void *data, uint32_t data_len,
@@ -32,23 +33,23 @@ static inline uint32_t _odp_hash_crc32c(const void *data, uint32_t data_len,
#ifdef __x86_64__
for (i = 0; i < data_len / 8; i++) {
- init_val = (uint32_t)__builtin_ia32_crc32di(init_val, *(const uint64_t *)pd);
+ init_val = (uint32_t)__builtin_ia32_crc32di(init_val, *(const odp_una_u64_t *)pd);
pd += 8;
}
if (data_len & 0x4) {
- init_val = __builtin_ia32_crc32si(init_val, *(const uint32_t *)pd);
+ init_val = __builtin_ia32_crc32si(init_val, *(const odp_una_u32_t *)pd);
pd += 4;
}
#else
for (i = 0; i < data_len / 4; i++) {
- init_val = __builtin_ia32_crc32si(init_val, *(const uint32_t *)pd);
+ init_val = __builtin_ia32_crc32si(init_val, *(const odp_una_u32_t *)pd);
pd += 4;
}
#endif
if (data_len & 0x2) {
- init_val = __builtin_ia32_crc32hi(init_val, *(const uint16_t *)pd);
+ init_val = __builtin_ia32_crc32hi(init_val, *(const odp_una_u16_t *)pd);
pd += 2;
}