From 149f748cf92bc5a676f2432270405011d5ec33b7 Mon Sep 17 00:00:00 2001 From: Alexander Krotov Date: Mon, 11 Nov 2019 19:48:15 +0300 Subject: [PATCH] core: assert that Ptr is not null on dereference This way it is possible to catch errors even if the pointer is not actually dereferenced, for example when it is used to call an object method or stored as a reference. --- src/core/model/ptr.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/core/model/ptr.h b/src/core/model/ptr.h index 3188c1fe9..eee94d40a 100644 --- a/src/core/model/ptr.h +++ b/src/core/model/ptr.h @@ -780,6 +780,7 @@ template T * Ptr::operator -> () { + NS_ASSERT_MSG (m_ptr, "Attempted to dereference zero pointer"); return m_ptr; } @@ -787,6 +788,7 @@ template T * Ptr::operator -> () const { + NS_ASSERT_MSG (m_ptr, "Attempted to dereference zero pointer"); return m_ptr; } @@ -794,6 +796,7 @@ template T & Ptr::operator * () const { + NS_ASSERT_MSG (m_ptr, "Attempted to dereference zero pointer"); return *m_ptr; } @@ -801,6 +804,7 @@ template T & Ptr::operator * () { + NS_ASSERT_MSG (m_ptr, "Attempted to dereference zero pointer"); return *m_ptr; }