fix ub type punning

This commit is contained in:
Yakov Olkhovskiy 2022-11-09 09:44:59 -05:00 committed by GitHub
parent 7f28a89273
commit a930ad25e1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -161,14 +161,9 @@ template <typename T>
requires (sizeof(T) <= sizeof(UInt64))
inline size_t DefaultHash64(T key)
{
union
{
T in;
DB::UInt64 out;
} u;
u.out = 0;
u.in = key;
return intHash64(u.out);
DB::UInt64 out {0};
std::memcpy(&out, &key, sizeof(T));
return intHash64(out);
}
@ -441,14 +436,9 @@ struct IntHash32
}
else if constexpr (sizeof(T) <= sizeof(UInt64))
{
union
{
T in;
DB::UInt64 out;
} u;
u.out = 0;
u.in = key;
return intHash32<salt>(u.out);
DB::UInt64 out {0};
std::memcpy(&out, &key, sizeof(T));
return intHash32<salt>(out);
}
UNREACHABLE();