Skip to content

Commit 0ec433e

Browse files
trflynn89linusg
authored andcommitted
LibJS: Explictly assert that a null GCPtr is not dereferenced
1 parent 8379b87 commit 0ec433e

File tree

1 file changed

+13
-2
lines changed
  • Userland/Libraries/LibJS/Heap

1 file changed

+13
-2
lines changed

Userland/Libraries/LibJS/Heap/GCPtr.h

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ class NonnullGCPtr {
5252
NonnullGCPtr& operator=(GCPtr<T> const& other)
5353
{
5454
m_ptr = const_cast<T*>(other.ptr());
55+
VERIFY(m_ptr);
5556
return *this;
5657
}
5758

@@ -186,8 +187,18 @@ class GCPtr {
186187
return *this;
187188
}
188189

189-
T* operator->() const { return m_ptr; }
190-
T& operator*() const { return *m_ptr; }
190+
T* operator->() const
191+
{
192+
VERIFY(m_ptr);
193+
return m_ptr;
194+
}
195+
196+
T& operator*() const
197+
{
198+
VERIFY(m_ptr);
199+
return *m_ptr;
200+
}
201+
191202
T* ptr() const { return m_ptr; }
192203

193204
operator bool() const { return !!m_ptr; }

0 commit comments

Comments
 (0)