From 75192d44aa1269b814abaa612f7e8e22f1da70b5 Mon Sep 17 00:00:00 2001 From: Nikolai Kochetov Date: Fri, 20 Mar 2020 20:05:04 +0300 Subject: [PATCH] Fix weakHash --- dbms/src/Common/HashTable/Hash.h | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/dbms/src/Common/HashTable/Hash.h b/dbms/src/Common/HashTable/Hash.h index 3ba5a18a5e7..11d84408b0a 100644 --- a/dbms/src/Common/HashTable/Hash.h +++ b/dbms/src/Common/HashTable/Hash.h @@ -85,7 +85,7 @@ inline UInt32 updateWeakHash32(const DB::UInt8 * pos, size_t size, DB::UInt32 u } const auto * end = pos + size; - while (pos + 8 < end) + while (pos + 8 <= end) { auto word = unalignedLoad(pos); updated_value = intHashCRC32(word, updated_value); @@ -93,9 +93,16 @@ inline UInt32 updateWeakHash32(const DB::UInt8 * pos, size_t size, DB::UInt32 u pos += 8; } - auto word = unalignedLoad(end - 8); - word &= (~UInt64(0)) << DB::UInt8(8 * (8 - (end - pos))); - return intHashCRC32(word, updated_value); + if (pos < end) + { + DB::UInt8 tail_size = end - pos; + auto word = unalignedLoad(end - 8); + word &= (~UInt64(0)) << DB::UInt8(8 * (8 - tail_size)); + word |= tail_size; + updated_value = intHashCRC32(word, updated_value); + } + + return updated_value; } template