From fc6e314498183def435360df069beee1ce1b8d95 Mon Sep 17 00:00:00 2001 From: Oleg Efimov Date: Sun, 4 May 2014 00:34:08 +0400 Subject: [PATCH 1/2] Enable usage of AddressSanitizer to check Jansson --- src/lookup3.h | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/lookup3.h b/src/lookup3.h index 8847483..3c6a1ce 100644 --- a/src/lookup3.h +++ b/src/lookup3.h @@ -205,7 +205,22 @@ static uint32_t hashlittle(const void *key, size_t length, uint32_t initval) if (HASH_LITTLE_ENDIAN && ((u.i & 0x3) == 0)) { const uint32_t *k = (const uint32_t *)key; /* read 32-bit chunks */ +/* Detect Valgrind or AddressSanitizer */ #ifdef VALGRIND +# define NO_MASKING_TRICK 1 +#else +# if defined(__has_feature) /* Clang */ +# if __has_feature(address_sanitizer) /* is ASAN enabled? */ +# define NO_MASKING_TRICK 1 +# endif +# else +# if defined(__SANITIZE_ADDRESS__) /* GCC 4.8.x, is ASAN enabled? */ +# define NO_MASKING_TRICK 1 +# endif +# endif +#endif + +#ifdef NO_MASKING_TRICK const uint8_t *k8; #endif @@ -230,7 +245,7 @@ static uint32_t hashlittle(const void *key, size_t length, uint32_t initval) * still catch it and complain. The masking trick does make the hash * noticably faster for short strings (like English words). */ -#ifndef VALGRIND +#ifndef NO_MASKING_TRICK switch(length) { @@ -271,6 +286,10 @@ static uint32_t hashlittle(const void *key, size_t length, uint32_t initval) #endif /* !valgrind */ +#ifdef NO_MASKING_TRICK +# undef NO_MASKING_TRICK +#endif + } else if (HASH_LITTLE_ENDIAN && ((u.i & 0x1) == 0)) { const uint16_t *k = (const uint16_t *)key; /* read 16-bit chunks */ const uint8_t *k8; From 541cdf5960efe7b06c87bf93344d38f0f924fab1 Mon Sep 17 00:00:00 2001 From: Oleg Efimov Date: Mon, 5 May 2014 15:40:41 +0400 Subject: [PATCH 2/2] Remove unneeded undef --- src/lookup3.h | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/lookup3.h b/src/lookup3.h index 3c6a1ce..522a41a 100644 --- a/src/lookup3.h +++ b/src/lookup3.h @@ -286,10 +286,6 @@ static uint32_t hashlittle(const void *key, size_t length, uint32_t initval) #endif /* !valgrind */ -#ifdef NO_MASKING_TRICK -# undef NO_MASKING_TRICK -#endif - } else if (HASH_LITTLE_ENDIAN && ((u.i & 0x1) == 0)) { const uint16_t *k = (const uint16_t *)key; /* read 16-bit chunks */ const uint8_t *k8;