From 98552767a600bafc378e0f1c239cb1729660c8a7 Mon Sep 17 00:00:00 2001
From: Oliver Sander <sander@dune-project.org>
Date: Thu, 13 Jan 2011 15:00:09 +0000
Subject: [PATCH] Fix copy construction and assignment from a null pointer.

This fixes FS 864.

[[Imported from SVN: r6322]]
---
 dune/common/shared_ptr.hh | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/dune/common/shared_ptr.hh b/dune/common/shared_ptr.hh
index 77059386a..2ba6f5bd7 100644
--- a/dune/common/shared_ptr.hh
+++ b/dune/common/shared_ptr.hh
@@ -214,14 +214,17 @@ namespace Dune
   template<class T>
   inline shared_ptr<T>::shared_ptr(const shared_ptr<T>& other) : rep_(other.rep_)
   {
-    ++(rep_->count_);
+    if (rep_)
+      ++(rep_->count_);
   }
 
   template<class T>
   inline shared_ptr<T>& shared_ptr<T>::operator=(const shared_ptr<T>& other)
   {
-    (other.rep_->count_)++;
-    if(rep_!=0 && --(rep_->count_)<=0) delete rep_;
+    if (other.rep_) {
+      (other.rep_->count_)++;
+      if(rep_!=0 && --(rep_->count_)<=0) delete rep_;
+    }
     rep_ = other.rep_;
     return *this;
   }
-- 
GitLab