diff --git a/src/include/common/hashfn_unstable.h b/src/include/common/hashfn_unstable.h index 428936b8b64..f18cb4afe0a 100644 --- a/src/include/common/hashfn_unstable.h +++ b/src/include/common/hashfn_unstable.h @@ -86,7 +86,8 @@ * By handling the terminator on-the-fly, we can avoid needing a strlen() * call to tell us how many bytes to hash. Experimentation has found that * SMHasher fails unless we incorporate the length, so it is passed to - * the finalizer as a tweak. + * the finalizer as a tweak. When hashing multiple strings, it is + * recommended to pass the total length of the hashed strings. */ @@ -291,10 +292,13 @@ fasthash_accum_cstring(fasthash_state *hs, const char *str) #if SIZEOF_VOID_P >= 8 size_t len; -#ifdef USE_ASSERT_CHECKING - size_t len_check; - fasthash_state hs_check; + size_t len_check PG_USED_FOR_ASSERTS_ONLY; + fasthash_state hs_check PG_USED_FOR_ASSERTS_ONLY; + + if (str == NULL) + return 0; +#ifdef USE_ASSERT_CHECKING memcpy(&hs_check, hs, sizeof(fasthash_state)); len_check = fasthash_accum_cstring_unaligned(&hs_check, str); #endif