From 611bdccbe40f4bfb7f75d849c5bec6a003695db8 Mon Sep 17 00:00:00 2001 From: Tessil Date: Mon, 26 Aug 2024 19:17:51 +0100 Subject: [PATCH] Add burst_threshold limit check to the size limit of array_hash The array_hash used in the hash_node has a size limit of std::numeric_limits::max(), if more values are inserted, an exception is thrown. Check that the burst_threshold is within this limit beforehand so it doesn't happen. --- include/tsl/htrie_hash.h | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/include/tsl/htrie_hash.h b/include/tsl/htrie_hash.h index 91ffc64..c57cfd7 100644 --- a/include/tsl/htrie_hash.h +++ b/include/tsl/htrie_hash.h @@ -164,12 +164,14 @@ class htrie_hash { using const_prefix_iterator = htrie_hash_iterator; private: + using ArrayHashIndexSizeT = std::uint16_t; using array_hash_type = typename std::conditional< has_value::value, tsl::array_map, false, KeySizeT, - std::uint16_t, tsl::ah::power_of_two_growth_policy<4>>, + ArrayHashIndexSizeT, + tsl::ah::power_of_two_growth_policy<4>>, tsl::array_set, false, KeySizeT, - std::uint16_t, + ArrayHashIndexSizeT, tsl::ah::power_of_two_growth_policy<4>>>::type; private: @@ -1245,7 +1247,11 @@ class htrie_hash { void burst_threshold(size_type threshold) { const size_type min_burst_threshold = MIN_BURST_THRESHOLD; - m_burst_threshold = std::max(min_burst_threshold, threshold); + const size_type max_burst_threshold = MAX_BURST_THRESHOLD; + + m_burst_threshold = threshold; + m_burst_threshold = std::max(m_burst_threshold, min_burst_threshold); + m_burst_threshold = std::min(m_burst_threshold, max_burst_threshold); } /* @@ -2146,6 +2152,8 @@ class htrie_hash { static const size_type HASH_NODE_DEFAULT_INIT_BUCKETS_COUNT = 32; static const size_type MIN_BURST_THRESHOLD = 4; + static const size_type MAX_BURST_THRESHOLD = + std::numeric_limits::max(); std::unique_ptr m_root; size_type m_nb_elements;