diff options
author | Eugene Kliuchnikov <eustas@google.com> | 2019-07-22 14:29:51 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-07-22 14:29:51 +0200 |
commit | f1124c8524647932a72b17eedf03c6ed5676fc44 (patch) | |
tree | 3a9df04bebb0b2871cc1aa7247d8d97c2790ea7c /c | |
parent | c8b37e8fd1c6cc232d5f3b8fdcfb4ab98c5cf77a (diff) | |
download | brotli-f1124c8524647932a72b17eedf03c6ed5676fc44.zip brotli-f1124c8524647932a72b17eedf03c6ed5676fc44.tar.gz brotli-f1124c8524647932a72b17eedf03c6ed5676fc44.tar.bz2 |
More careful sanitizer detection (#764)
Diffstat (limited to 'c')
-rwxr-xr-x | c/common/platform.h | 7 | ||||
-rw-r--r-- | c/include/brotli/port.h | 14 |
2 files changed, 17 insertions, 4 deletions
diff --git a/c/common/platform.h b/c/common/platform.h index bf5f97b..b6d634e 100755 --- a/c/common/platform.h +++ b/c/common/platform.h @@ -308,8 +308,7 @@ static BROTLI_INLINE void BrotliUnalignedWrite64(void* p, uint64_t v) { } #else /* BROTLI_ALIGNED_READ */ /* Unaligned memory access is allowed: just cast pointer to requested type. */ -#if defined(ADDRESS_SANITIZER) || defined(THREAD_SANITIZER) || \ - defined(MEMORY_SANITIZER) +#if BROTLI_SANITIZED /* Consider we have an unaligned load/store of 4 bytes from address 0x...05. AddressSanitizer will treat it as a 3-byte access to the range 05:07 and will miss a bug if 08 is the first unaddressable byte. @@ -334,7 +333,7 @@ extern "C" { #define BrotliUnalignedRead32 __sanitizer_unaligned_load32 #define BrotliUnalignedRead64 __sanitizer_unaligned_load64 #define BrotliUnalignedWrite64 __sanitizer_unaligned_store64 -#else +#else /* BROTLI_SANITIZED */ static BROTLI_INLINE uint16_t BrotliUnalignedRead16(const void* p) { return *(const uint16_t*)p; } @@ -374,7 +373,7 @@ static BROTLI_INLINE void BrotliUnalignedWrite64(void* p, uint64_t v) { } #endif /* BROTLI_GNUC_HAS_ATTRIBUTE(aligned, 2, 7, 0) */ #endif /* BROTLI_64_BITS */ -#endif /* ASAN / TSAN / MSAN */ +#endif /* BROTLI_SANITIZED */ #endif /* BROTLI_ALIGNED_READ */ #if BROTLI_LITTLE_ENDIAN diff --git a/c/include/brotli/port.h b/c/include/brotli/port.h index 20dc231..825237a 100644 --- a/c/include/brotli/port.h +++ b/c/include/brotli/port.h @@ -218,6 +218,20 @@ BROTLI_GNUC_VERSION_CHECK(major, minor, patch) #endif +#if defined(__has_feature) +#define BROTLI_HAS_FEATURE(feature) __has_feature(feature) +#else +#define BROTLI_HAS_FEATURE(feature) (0) +#endif + +#if defined(ADDRESS_SANITIZER) || BROTLI_HAS_FEATURE(address_sanitizer) || \ + defined(THREAD_SANITIZER) || BROTLI_HAS_FEATURE(thread_sanitizer) || \ + defined(MEMORY_SANITIZER) || BROTLI_HAS_FEATURE(memory_sanitizer) +#define BROTLI_SANITIZED 1 +#else +#define BROTLI_SANITIZED 0 +#endif + #if defined(_WIN32) || defined(__CYGWIN__) #define BROTLI_PUBLIC #elif BROTLI_GNUC_VERSION_CHECK(3, 3, 0) || \ |