From 7f28a8927392c02b157ce98dd43d52877ba17ed3 Mon Sep 17 00:00:00 2001 From: Yakov Olkhovskiy <99031427+yakov-olkhovskiy@users.noreply.github.com> Date: Wed, 9 Nov 2022 09:39:27 -0500 Subject: [PATCH] fix ub type punning --- src/Common/HashTable/Hash.h | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/Common/HashTable/Hash.h b/src/Common/HashTable/Hash.h index f36ab576766..f7c653f50d4 100644 --- a/src/Common/HashTable/Hash.h +++ b/src/Common/HashTable/Hash.h @@ -224,14 +224,9 @@ template requires (sizeof(T) <= sizeof(UInt64)) inline size_t hashCRC32(T key, DB::UInt64 updated_value = -1) { - union - { - T in; - DB::UInt64 out; - } u; - u.out = 0; - u.in = key; - return intHashCRC32(u.out, updated_value); + DB::UInt64 out {0}; + std::memcpy(&out, &key, sizeof(T)); + return intHashCRC32(out, updated_value); } template