Skip to content

Commit 2c81301

Browse files
Ahmad-S792Ahmad Saleem
authored andcommitted
WeakListHashSetIteratorBase::get() const recurses infinitely
https://bugs.webkit.org/show_bug.cgi?id=328439 rdar://190695531 Reviewed by Yusuke Suzuki. The const overload of WeakListHashSetIteratorBase::get() was implemented as `return get();`. Within a const member function that resolves to the same const overload, so the function called itself unconditionally. Since WeakListHashSetConstIterator is only ever used through the const overloads, calling get(), operator*() or operator->() on an iterator obtained from begin() const, end() const or find() const overflowed the stack. Return m_position->get() instead, matching the non-const overload. Test: Tools/TestWebKitAPI/Tests/WTF/WeakPtr.cpp * Source/WTF/wtf/WeakListHashSet.h: * Tools/TestWebKitAPI/Tests/WTF/WeakPtr.cpp: (TestWebKitAPI::TEST(WTF_WeakPtr, WeakListHashSetConstIteratorAccess)): Canonical link: https://commits.webkit.org/324515@main
1 parent 961981e commit 2c81301

2 files changed

Lines changed: 17 additions & 1 deletion

File tree

‎Source/WTF/wtf/WeakListHashSet.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class WeakListHashSet final {
6969
~WeakListHashSetIteratorBase() = default;
7070

7171
T* get() LIFETIME_BOUND { return m_position->get(); }
72-
const T* get() const { return get(); }
72+
const T* get() const { return m_position->get(); }
7373
T& operator*() { return *get(); }
7474
const T& operator*() const { return *get(); }
7575
T* operator->() { return get(); }

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2796,6 +2796,22 @@ TEST(WTF_WeakPtr, WeakListHashSetPrependOrMoveToFirst)
27962796
}
27972797
}
27982798

2799+
TEST(WTF_WeakPtr, WeakListHashSetConstIteratorAccess)
2800+
{
2801+
WeakListHashSet<Base> weakListHashSet;
2802+
Base object;
2803+
weakListHashSet.add(object);
2804+
2805+
const auto& constSet = weakListHashSet;
2806+
const auto it = constSet.begin();
2807+
EXPECT_EQ(&object, it.get());
2808+
EXPECT_EQ(&object, &*it);
2809+
EXPECT_EQ(&object, it.operator->());
2810+
2811+
const auto foundIt = constSet.find(object);
2812+
EXPECT_EQ(&object, foundIt.get());
2813+
}
2814+
27992815
TEST(WTF_WeakPtr, WeakListHashSetInsertBefore)
28002816
{
28012817
{

0 commit comments

Comments
 (0)