Skip to content

Commit 474bb3f

Browse files
Ahmad-S792Ahmad Saleem
authored andcommitted
BitSet::setEachNthBit() and clearEachNthBit() loop forever when n is 0
https://bugs.webkit.org/show_bug.cgi?id=328452 rdar://190702141 Reviewed by Yusuke Suzuki. Both functions advance `index` by `n` inside a do/while loop, so passing n == 0 never advances the index and the loop never terminates. Passing n == 0 is a caller error, so add ASSERT(n) to both functions so it fails immediately in debug builds instead of hanging. Test: Tools/TestWebKitAPI/Tests/WTF/BitSet.cpp * Source/WTF/wtf/BitSet.h: (WTF::WordType>::setEachNthBit): (WTF::WordType>::clearEachNthBit): * Tools/TestWebKitAPI/Tests/WTF/BitSet.cpp: (TestWebKitAPI::TEST(WTF_BitSetDeathTest, MAYBE_ASSERT_ENABLED_DEATH_TEST(SetEachNthBitZero)): (TestWebKitAPI::TEST(WTF_BitSetDeathTest, MAYBE_ASSERT_ENABLED_DEATH_TEST(ClearEachNthBitZero)): Canonical link: https://commits.webkit.org/324767@main
1 parent fa28e03 commit 474bb3f

2 files changed

Lines changed: 16 additions & 0 deletions

File tree

‎Source/WTF/wtf/BitSet.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,7 @@ inline constexpr void BitSet<bitSetSize, WordType>::setAndClear(BitSet& other)
447447
template<size_t bitSetSize, typename WordType>
448448
inline void BitSet<bitSetSize, WordType>::setEachNthBit(size_t n, size_t start, size_t end)
449449
{
450+
ASSERT(n);
450451
ASSERT(start <= end);
451452
ASSERT(end <= bitSetSize);
452453

@@ -482,6 +483,7 @@ inline void BitSet<bitSetSize, WordType>::setEachNthBit(size_t n, size_t start,
482483
template<size_t bitSetSize, typename WordType>
483484
inline void BitSet<bitSetSize, WordType>::clearEachNthBit(size_t n, size_t start, size_t end)
484485
{
486+
ASSERT(n);
485487
ASSERT(start <= end);
486488
ASSERT(end <= bitSetSize);
487489

‎Tools/TestWebKitAPI/Tests/WTF/BitSet.cpp‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
#include "config.h"
2727
#include <wtf/BitSet.h>
2828

29+
#include "Helpers/Test.h"
30+
2931
namespace TestWebKitAPI {
3032

3133
constexpr size_t size = 128;
@@ -1591,4 +1593,16 @@ TEST(WTF_BitSet, Hash_uint64_t) { testBitSetHash<uint64_t>(); }
15911593

15921594
#endif // CPU(REGISTER64)
15931595

1596+
TEST(WTF_BitSetDeathTest, MAYBE_ASSERT_ENABLED_DEATH_TEST(SetEachNthBitZero))
1597+
{
1598+
WTF::BitSet<128> bitSet;
1599+
ASSERT_DEATH_IF_SUPPORTED(bitSet.setEachNthBit(0), "");
1600+
}
1601+
1602+
TEST(WTF_BitSetDeathTest, MAYBE_ASSERT_ENABLED_DEATH_TEST(ClearEachNthBitZero))
1603+
{
1604+
WTF::BitSet<128> bitSet;
1605+
ASSERT_DEATH_IF_SUPPORTED(bitSet.clearEachNthBit(0), "");
1606+
}
1607+
15941608
} // namespace TestWebKitAPI

0 commit comments

Comments
 (0)