summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibJS/Heap
diff options
context:
space:
mode:
authorTimothy Flynn <trflynn89@pm.me>2022-12-13 18:39:25 -0500
committerLinus Groh <mail@linusgroh.de>2022-12-14 09:59:35 +0000
commit0ec433edce272297d477e5db4f6c2aa3adb8b24f (patch)
tree07985aef4cecfa45680b7db7438b28a9c8b98685 /Userland/Libraries/LibJS/Heap
parent8379b87d4eaa78eaf27e44432eea47ffa21b5cbf (diff)
downloadserenity-0ec433edce272297d477e5db4f6c2aa3adb8b24f.zip
LibJS: Explictly assert that a null GCPtr is not dereferenced
Diffstat (limited to 'Userland/Libraries/LibJS/Heap')
-rw-r--r--Userland/Libraries/LibJS/Heap/GCPtr.h15
1 files 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<T> const& other)
{
m_ptr = const_cast<T*>(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; }