Browse Source

LibJS: Explictly assert that a null GCPtr is not dereferenced

Timothy Flynn 2 years ago
parent
commit
0ec433edce
1 changed files with 13 additions and 2 deletions
  1. 13 2
      Userland/Libraries/LibJS/Heap/GCPtr.h

+ 13 - 2
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; }