From fc0c0f585eace7293bbf921985b3e1c44732ce30 Mon Sep 17 00:00:00 2001 From: Cameron Cawley Date: Tue, 20 Jul 2021 18:22:34 +0100 Subject: [PATCH] Avoid using unaligned memory access in UBSan builds --- miniz.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/miniz.h b/miniz.h index 42e1ea2..185e596 100644 --- a/miniz.h +++ b/miniz.h @@ -168,6 +168,13 @@ #define MINIZ_LITTLE_ENDIAN 0 #endif +/* Using unaligned loads and stores causes errors when using UBSan */ +#if defined(__has_feature) +#if __has_feature(undefined_behavior_sanitizer) +#define MINIZ_USE_UNALIGNED_LOADS_AND_STORES 0 +#endif +#endif + /* Set MINIZ_USE_UNALIGNED_LOADS_AND_STORES only if not set */ #if !defined(MINIZ_USE_UNALIGNED_LOADS_AND_STORES) #if MINIZ_X86_OR_X64_CPU