From 5fbfaee0f9f5469f73125a7044d8d26a0724f645 Mon Sep 17 00:00:00 2001 From: Konrad Rosenbaum Date: Mon, 13 Feb 2012 21:30:05 +0100 Subject: [PATCH] make it self-assignment safe --- dptr.h | 2 +- dptr_shared.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/dptr.h b/dptr.h index c74ad22..121aaa4 100644 --- a/dptr.h +++ b/dptr.h @@ -53,5 +53,5 @@ To be used in implementation where the actual d-pointer class is implemented. Class::DPrivate::~DPrivate(){delete d;}\ Class::DPrivate Class::DPrivate::clone()const{DPrivate r;*(r.d)=*d;return r;}\ Class::DPrivate& Class::DPrivate::operator=(const Class::DPrivate&dp)\ - {*d=*(dp.d);return *this;} + {if(d!=dp.d)*d=*(dp.d);return *this;} diff --git a/dptr_shared.h b/dptr_shared.h index b824194..88dc7a4 100644 --- a/dptr_shared.h +++ b/dptr_shared.h @@ -58,5 +58,5 @@ To be used in implementation where the actual d-pointer class is implemented. Class::DPrivate::~DPrivate(){d->detach();}\ Class::DPrivate Class::DPrivate::clone()const{DPrivate r;*(r.d)=*d;return r;}\ Class::DPrivate& Class::DPrivate::operator=(const DPrivate&dp)\ - {d->detach();d=dp.d;d->attach();return *this;} + {if(d!=dp.d){d->detach();d=dp.d;d->attach();}return *this;} -- 1.7.2.5