uint8_t pointers yield strict aliasing violations
gsauthof opened this issue · 3 comments
The SipHash hash function signature reads:
int siphash(const uint8_t *in, const size_t inlen, const uint8_t *k,
uint8_t *out, const size_t outlen);
That means if I need to hash - say - an integer I have to cast an integer pointer to uint8_t*
.
Unfortunately, uint8_t*
doesn't have the same strict aliasing implications as char*
/unsigned char *
/void*
or even std::byte*
.
(Meaning the C standard just includes exceptions from the strict aliasing rules for char/void pointers but not for uint8_t
pointers.)
That means that such a cast yields undefined behaviour.
Possible fix: change the type of the first argument to const void *in
(such that callers don't have to cast) and cast that pointer in the function to const unsigned char *
and use that for the accesses and address calculations.
Thanks, will fix.
Thank you for looking into this, I left some review comments in the pull request.