From 0ec433edce272297d477e5db4f6c2aa3adb8b24f Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Tue, 13 Dec 2022 18:39:25 -0500 Subject: [PATCH] LibJS: Explictly assert that a null GCPtr is not dereferenced --- Userland/Libraries/LibJS/Heap/GCPtr.h | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/Userland/Libraries/LibJS/Heap/GCPtr.h b/Userland/Libraries/LibJS/Heap/GCPtr.h index 7eca3d7129..f0c0623afa 100644 --- a/Userland/Libraries/LibJS/Heap/GCPtr.h +++ b/Userland/Libraries/LibJS/Heap/GCPtr.h @@ -52,6 +52,7 @@ public: NonnullGCPtr& operator=(GCPtr const& other) { m_ptr = const_cast(other.ptr()); + VERIFY(m_ptr); return *this; } @@ -186,8 +187,18 @@ public: return *this; } - T* operator->() const { return m_ptr; } - T& operator*() const { return *m_ptr; } + T* operator->() const + { + VERIFY(m_ptr); + return m_ptr; + } + + T& operator*() const + { + VERIFY(m_ptr); + return *m_ptr; + } + T* ptr() const { return m_ptr; } operator bool() const { return !!m_ptr; }