Skip to content

Commit 6664e80

Browse files
author
Andy Kaylor
committed
Fix integer overflow in ConcurrentHashtTableByPtr
This change fixes a case where there was a potential integer overflow when multiplying two 32-bit values and assigning the result to a 64-bit value. The potential overflow has been present since https://reviews.llvm.org/D132455 was re-landed. The initial version of the patch defined MaxBucketSize and NumberOfBuckets as size_t (which I guess would still be a problem for some targets). When the patch was re-landed they were defined as uint32_t, making the calculation of ExtHashMask subject to overflow. Differential Revision: https://reviews.llvm.org/D158117
1 parent e698695 commit 6664e80

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

llvm/include/llvm/ADT/ConcurrentHashtable.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ class ConcurrentHashTableByPtr {
154154
MaxBucketSize = 1Ull << (std::min((size_t)31, LeadingZerosNumber));
155155

156156
// Calculate mask for extended hash bits.
157-
ExtHashMask = (NumberOfBuckets * MaxBucketSize) - 1;
157+
ExtHashMask = (uint64_t)NumberOfBuckets * MaxBucketSize - 1;
158158
}
159159

160160
virtual ~ConcurrentHashTableByPtr() {

0 commit comments

Comments
 (0)