Skip to content
This repository was archived by the owner on Mar 22, 2023. It is now read-only.

Commit d346272

Browse files
author
Szymon Romik
authored
Merge pull request #860 from igchor/stable-1.9_defrag_fix
concurrent_hash_map: make double to size_t cast explicit in defragment()
2 parents 8dc9c20 + 415e8b9 commit d346272

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

include/libpmemobj++/container/concurrent_hash_map.hpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2851,8 +2851,14 @@ class concurrent_hash_map
28512851
}
28522852

28532853
size_t max_index = mask().load(std::memory_order_acquire);
2854-
size_t start_index = (start_percent * max_index) / 100;
2855-
size_t end_index = (end_percent * max_index) / 100;
2854+
size_t start_index =
2855+
static_cast<size_t>((start_percent * max_index) / 100);
2856+
size_t end_index =
2857+
static_cast<size_t>((end_percent * max_index) / 100);
2858+
2859+
/* Make sure we do not use too big index, even in case of
2860+
* rounding errors. */
2861+
end_index = (std::min)(end_index, max_index);
28562862

28572863
#if LIBPMEMOBJ_CPP_VG_HELGRIND_ENABLED
28582864
ANNOTATE_HAPPENS_AFTER(&(this->my_mask));

0 commit comments

Comments
 (0)