From 549dabc93359fcd579aa7cd76eedb202a7c8dec7 Mon Sep 17 00:00:00 2001 From: James Raphael Tiovalen Date: Sat, 16 Sep 2023 15:28:54 +0800 Subject: [PATCH] hash: Add explicit typecasts to fix C++ compilation issues C++ does not allow implicit conversion from void pointer to a specific pointer type. This change removes the cast from uint32_t* to void* in `hash_words_32aligned` and adds an explicit typecast from uint32_t* to uint64_t* in `hash_words_inline`. This issue was initially discovered on G++ v9.2.0 when a downstream C++ application included the hash.h header file and was compiled on an AMD Ryzen Zen 2 CPU (__SSE4_2__ && __x86_64__). On the latest G++ version, it would throw an error. On the latest GCC version with `-Wc++-compat`, it would throw a warning. Acked-by: Mike Pattrick Signed-off-by: James Raphael Tiovalen Signed-off-by: 0-day Robot --- lib/hash.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/hash.h b/lib/hash.h index 7b7f70c112a..307309fd059 100644 --- a/lib/hash.h +++ b/lib/hash.h @@ -198,9 +198,8 @@ hash_finish32(uint64_t hash, uint32_t final, uint32_t semifinal) } static inline uint32_t -hash_words_32aligned(const uint32_t *p_, size_t n_words, uint32_t basis) +hash_words_32aligned(const uint32_t *p, size_t n_words, uint32_t basis) { - const uint32_t *p = (const void *) p_; uint32_t hash1 = basis; uint32_t hash2 = 0; uint32_t hash3 = n_words; @@ -254,7 +253,7 @@ hash_words_32aligned(const uint32_t *p_, size_t n_words, uint32_t basis) static inline uint32_t hash_words_inline(const uint32_t *p_, size_t n_words, uint32_t basis) { - const uint64_t *p = (const void *)p_; + const uint64_t *p = ALIGNED_CAST(const uint64_t *, p_); uint64_t hash1 = basis; uint64_t hash2 = 0; uint64_t hash3 = n_words;