From 2766513bf44b1f62faf09956899114d3d6d64267 Mon Sep 17 00:00:00 2001 From: "akalin@chromium.org" Date: Tue, 31 Jan 2012 02:16:55 +0000 Subject: Add assert() for scoped_refptr::operator->() This is to make NULL dereference crashes more obvious. Also matches scoped_ptr (which uses assert) and weak_ptr (which uses DCHECK). DCHECK wasn't used because it pulls in logging.h, and that somehow conflicts with a webkit #define of LOG. BUG= TEST= Review URL: http://codereview.chromium.org/9232069 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@119820 0039d316-1c4b-4281-b951-d872f2087c98 --- base/memory/ref_counted.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'base/memory') diff --git a/base/memory/ref_counted.h b/base/memory/ref_counted.h index b7cb5e0..cf8ff16 100644 --- a/base/memory/ref_counted.h +++ b/base/memory/ref_counted.h @@ -6,6 +6,8 @@ #define BASE_MEMORY_REF_COUNTED_H_ #pragma once +#include + #include "base/atomic_ref_count.h" #include "base/base_export.h" #include "base/threading/thread_collision_warner.h" @@ -243,7 +245,10 @@ class scoped_refptr { T* get() const { return ptr_; } operator T*() const { return ptr_; } - T* operator->() const { return ptr_; } + T* operator->() const { + assert(ptr_ != NULL); + return ptr_; + } // Release a pointer. // The return value is the current pointer held by this object. -- cgit v1.1