]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Handle assignment to self correctly.
authorAlex Rousskov <rousskov@measurement-factory.com>
Sun, 29 Aug 2010 21:16:57 +0000 (15:16 -0600)
committerAlex Rousskov <rousskov@measurement-factory.com>
Sun, 29 Aug 2010 21:16:57 +0000 (15:16 -0600)
Self-assignment probably does not happen in the current code.

src/base/CbcPointer.h

index 622d963f9705bb7ae6c173d1162d4bd5346877ee..128332702251795ec833df3e7dd780e609341909 100644 (file)
@@ -48,10 +48,12 @@ public:
     /// support assigning a child cbc pointer to a parent cbc pointer
     template <typename Other>
     CbcPointer &operator =(const CbcPointer<Other> &o) {
+        if (this != &o) { // assignment to self
         clear();
         cbc = o.raw(); // so that set() is accurate
         if (o.valid())
             lock = cbdataReference(o->toCbdata());
+        }
         return *this;
     }
 
@@ -101,10 +103,12 @@ CbcPointer<Cbc>::~CbcPointer()
 template<class Cbc>
 CbcPointer<Cbc> &CbcPointer<Cbc>::operator =(const CbcPointer &d)
 {
+    if (this != &d) { // assignment to self
     clear();
     cbc = d.cbc;
     if (d.lock && cbdataReferenceValid(d.lock))
         lock = cbdataReference(d.lock);
+    }
     return *this;
 }