Skip to content

Commit

Permalink
Fix: bdlma_pool ordered hashmap UB
Browse files Browse the repository at this point in the history
Signed-off-by: Melvin He <[email protected]>
  • Loading branch information
melvinhe committed Apr 15, 2024
1 parent dff0082 commit bfb93c5
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/groups/mwc/mwcc/mwcc_orderedhashmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ size_t OrderedHashMap_ImpDetails::nextPrime(size_t n)
257, 521, 1049, 2099, 4201, 8419,
16843, 33703, 67409, 134837, 269513, 539039,
1078081, 2156171, 5312353, 10624709, 21249443, 42498893,
84997793, 169995589, 339991181, 679982363, 1359964751, 2719929503u};
84997793, 169995589, 339991181, 679982363, 1359964751};

static const size_t s_nPrimes = sizeof(s_primes) / sizeof(s_primes[0]);
static const size_t* const s_beginPrimes = s_primes;
Expand Down
4 changes: 2 additions & 2 deletions src/groups/mwc/mwcc/mwcc_orderedhashmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -1082,7 +1082,7 @@ inline void OrderedHashMap<KEY, VALUE, HASH, VALUE_TYPE>::initialize()
d_allocator_p->allocate(sizeof(Bucket) * d_bucketArraySize));

bsl::fill_n(d_bucketArray_p, d_bucketArraySize, Bucket());
d_nodePool.reserveCapacity(d_bucketArraySize);
d_nodePool.reserveCapacity(static_cast<int>(d_bucketArraySize));
d_sentinel_p = static_cast<Link*>(d_nodePool.allocate());
new (d_sentinel_p) Link();
d_sentinel_p->reset();
Expand Down Expand Up @@ -1194,7 +1194,7 @@ bool OrderedHashMap<KEY, VALUE, HASH, VALUE_TYPE>::rehashIfNeeded()
// Reserve in nodepool.

if (d_bucketArraySize > d_numElements) {
d_nodePool.reserveCapacity(d_bucketArraySize - d_numElements);
d_nodePool.reserveCapacity(static_cast<int>(d_bucketArraySize - d_numElements));
}

// Destroy & deallocate old bucket array.
Expand Down
2 changes: 1 addition & 1 deletion src/groups/mwc/mwcc/mwcc_twokeyhashmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -1105,7 +1105,7 @@ inline TwoKeyHashMap<K1, K2, VALUE, H1, H2>::TwoKeyHashMap(
this));

// copy elements from 'original' to '*this'
d_nodeAllocator->reserveCapacity(original.size());
d_nodeAllocator->reserveCapacity(static_cast<int>(original.size()));
for (const_iterator it = original.cbegin(); it != original.cend(); ++it) {
insert(*it);
}
Expand Down

0 comments on commit bfb93c5

Please sign in to comment.