From 9632464c451346f351b3101648ced05f59584aca Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Mon, 25 Nov 2002 12:17:56 +0000 Subject: [PATCH] Test w/ NULL pointer to enabled_... object added; bug fixed. [SVN r16402] --- enable_shared_from_this_test.cpp | 8 ++++++++ include/boost/shared_ptr.hpp | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/enable_shared_from_this_test.cpp b/enable_shared_from_this_test.cpp index 8225a39..75ca31d 100644 --- a/enable_shared_from_this_test.cpp +++ b/enable_shared_from_this_test.cpp @@ -66,9 +66,12 @@ void test() BOOST_TEST(py.use_count() == 3); } +void test2(); + int main() { test(); + test2(); return boost::report_errors(); } @@ -102,3 +105,8 @@ boost::shared_ptr createY() boost::shared_ptr pi(new impl2); return pi; } + +void test2() +{ + boost::shared_ptr pi(static_cast(0)); +} diff --git a/include/boost/shared_ptr.hpp b/include/boost/shared_ptr.hpp index 03ea7d4..473543a 100644 --- a/include/boost/shared_ptr.hpp +++ b/include/boost/shared_ptr.hpp @@ -72,7 +72,7 @@ template<> struct shared_ptr_traits template void sp_enable_shared_from_this(boost::enable_shared_from_this * pe, Y * px, shared_count const & pn) { - pe->_internal_weak_this._internal_assign(px, pn); + if(pe != 0) pe->_internal_weak_this._internal_assign(px, pn); } inline void sp_enable_shared_from_this(void const *, void const *, shared_count const &)