From: Konrad Rosenbaum Date: Mon, 13 Feb 2012 20:30:05 +0000 (+0100) Subject: make it self-assignment safe X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=5fbfaee0f9f5469f73125a7044d8d26a0724f645;p=konrad%2Felam.git make it self-assignment safe --- 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;}