diff --git a/AK/RefPtr.h b/AK/RefPtr.h index 70dc84f97f..d698cfa261 100644 --- a/AK/RefPtr.h +++ b/AK/RefPtr.h @@ -49,18 +49,21 @@ public: RefPtr(const NonnullRefPtr& other) : m_ptr(const_cast(other.ptr())) { + ASSERT(m_ptr); m_ptr->ref(); } template RefPtr(const NonnullRefPtr& other) : m_ptr(static_cast(const_cast(other.ptr()))) { + ASSERT(m_ptr); m_ptr->ref(); } template RefPtr(NonnullRefPtr&& other) : m_ptr(static_cast(&other.leak_ref())) { + ASSERT(m_ptr); } template RefPtr(RefPtr&& other) @@ -121,6 +124,7 @@ public: { RefPtr tmp = move(other); swap(tmp); + ASSERT(m_ptr); return *this; } @@ -128,6 +132,7 @@ public: { RefPtr tmp = other; swap(tmp); + ASSERT(m_ptr); return *this; } @@ -136,6 +141,7 @@ public: { RefPtr tmp = other; swap(tmp); + ASSERT(m_ptr); return *this; } @@ -192,11 +198,29 @@ public: T* ptr() { return m_ptr; } const T* ptr() const { return m_ptr; } - T* operator->() { return m_ptr; } - const T* operator->() const { return m_ptr; } + T* operator->() + { + ASSERT(m_ptr); + return m_ptr; + } - T& operator*() { return *m_ptr; } - const T& operator*() const { return *m_ptr; } + const T* operator->() const + { + ASSERT(m_ptr); + return m_ptr; + } + + T& operator*() + { + ASSERT(m_ptr); + return *m_ptr; + } + + const T& operator*() const + { + ASSERT(m_ptr); + return *m_ptr; + } operator const T*() const { return m_ptr; } operator T*() { return m_ptr; }