From d9cc3e453cb6a7b5e7a3d7b477a497c8dee8f1f4 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Fri, 2 Aug 2019 10:34:40 +0200 Subject: [PATCH] AK: Add assertions when dereferencing an OwnPtr. This will make it immediately obvious what the problem is when you're dereferencing a null OwnPtr. --- AK/OwnPtr.h | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/AK/OwnPtr.h b/AK/OwnPtr.h index 67a19578db..9e40625a71 100644 --- a/AK/OwnPtr.h +++ b/AK/OwnPtr.h @@ -123,11 +123,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; }