diff options
| author | Dentomologist <dentomologist@gmail.com> | 2023-12-31 11:57:16 -0800 |
|---|---|---|
| committer | Dentomologist <dentomologist@gmail.com> | 2024-01-01 00:41:48 -0800 |
| commit | 7dbf463ddf4a89ec7158c955b421adb77670d37e (patch) | |
| tree | 2885a586708da259997c2230bc9c391aca27ef05 /Source/UnitTests/Common/BitSetTest.cpp | |
| parent | 58c5ae3de92015f8b4c3ae4b63e23b8669798edc (diff) | |
BitSet64: Fix iterator incrementation
Use 1 of the same type as the stored value when shifting left. This
prevents undefined behavior caused by shifting an int more than 31 bits.
Previously iterator incrementation could either hang or prematurely
report it had reached the end of the bitset.
Diffstat (limited to 'Source/UnitTests/Common/BitSetTest.cpp')
| -rw-r--r-- | Source/UnitTests/Common/BitSetTest.cpp | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/Source/UnitTests/Common/BitSetTest.cpp b/Source/UnitTests/Common/BitSetTest.cpp index 6ec2b74bdb..397f9fecbe 100644 --- a/Source/UnitTests/Common/BitSetTest.cpp +++ b/Source/UnitTests/Common/BitSetTest.cpp @@ -41,6 +41,10 @@ TEST(BitSet, Count) { const auto bitset = BitSet32(number); EXPECT_EQ(bitset.Count(), bitcount); + u32 iterating_count = 0; + for (auto iter = bitset.begin(); iter != bitset.end(); ++iter) + ++iterating_count; + EXPECT_EQ(iterating_count, bitcount); } constexpr std::array<std::pair<u64, u32>, 9> random_64bit_number_bitcount_pairs = { @@ -57,6 +61,10 @@ TEST(BitSet, Count) { const auto bitset = BitSet64(number); EXPECT_EQ(bitset.Count(), bitcount); + u32 iterating_count = 0; + for (auto iter = bitset.begin(); iter != bitset.end(); ++iter) + ++iterating_count; + EXPECT_EQ(iterating_count, bitcount); } } |
