Skip to content

Commit

Permalink
hash: Add explicit typecasts to fix C++ compilation issues
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: James Raphael Tiovalen <[email protected]>
Signed-off-by: 0-day Robot <[email protected]>
  • Loading branch information
jamestiotio authored and ovsrobot committed Sep 16, 2023
1 parent bac34b2 commit 549dabc
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions lib/hash.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 549dabc

Please sign in to comment.