Adding SAN option to CMakeLists.txt, to make it easier to use clang's address/undefined behavior sanitizer on codebase

Fixing overflow issue on extreme colors in color_distance().
Explicitly disabling unaligned addressing in miniz and transcoder when UBSAN is enabled
Disabling a needless optimization in transcoder causing ubsan issues (that could have easily been worked around in a different way, but it was an unnecessary optimization to begin with)
Rebuild wasm builds
This commit is contained in:
Richard Geldreich
2022-02-24 19:45:01 -05:00
parent 44e1bcd3e1
commit 7a2094b807
9 changed files with 47 additions and 15 deletions

View File

@@ -37,6 +37,14 @@
#endif
#endif
// Using unaligned loads and stores causes errors when using UBSan. Jam it off.
#if defined(__has_feature)
#if __has_feature(undefined_behavior_sanitizer)
#undef BASISD_USE_UNALIGNED_WORD_READS
#define BASISD_USE_UNALIGNED_WORD_READS 0
#endif
#endif
#define BASISD_SUPPORTED_BASIS_VERSION (0x13)
#ifndef BASISD_SUPPORT_KTX2
@@ -12440,12 +12448,8 @@ namespace basist
bits = read_bits64(blk.m_bytes, bit_ofs, basisu::minimum<int>(64, 128 - (int)bit_ofs));
else
{
#ifdef __EMSCRIPTEN__
bits = blk.m_dwords[2];
bits |= (((uint64_t)blk.m_dwords[3]) << 32U);
#else
bits = blk.m_qwords[1];
#endif
if (bit_ofs >= 64U)
bits >>= (bit_ofs - 64U);