From f298d71c08c335e45807a54d541f1275cac4ad61 Mon Sep 17 00:00:00 2001 From: levlam Date: Thu, 24 Feb 2022 22:04:21 +0300 Subject: [PATCH] HashTable bug fixes. --- tdutils/td/utils/FlatHashMapLinear.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tdutils/td/utils/FlatHashMapLinear.h b/tdutils/td/utils/FlatHashMapLinear.h index 1d4635fd8..ece4af65e 100644 --- a/tdutils/td/utils/FlatHashMapLinear.h +++ b/tdutils/td/utils/FlatHashMapLinear.h @@ -170,7 +170,7 @@ class FlatHashTable { static NodeT *allocate_nodes(uint32 size) { DCHECK(size >= 8); DCHECK((size & (size - 1)) == 0); - CHECK(size <= (1 << 29)); + CHECK(size <= min(static_cast(1) << 29, static_cast((0x7FFFFFFF - OFFSET) / sizeof(NodeT)))); auto inner = static_cast(std::malloc(OFFSET + sizeof(NodeT) * size)); NodeT *nodes = &inner->nodes_[0]; for (uint32 i = 0; i < size; i++) { @@ -555,6 +555,7 @@ class FlatHashTable { void resize(uint32 new_size) { if (unlikely(nodes_ == nullptr)) { nodes_ = allocate_nodes(new_size); + used_node_count() = 0; return; }