Add self-assignment check in operator=
authorgarima-g <garima.g@samsung.com>
Thu, 5 Nov 2015 05:42:24 +0000 (11:12 +0530)
committergarima-g <garima.g@samsung.com>
Thu, 5 Nov 2015 05:42:24 +0000 (11:12 +0530)
Method 'operator=' should check its argument with 'this' pointer.

taglib/asf/asfattribute.cpp

index 116bfe21d79e67620b22660b398e4cf74316e7d8..7a40bea3aa604c7b212e13420398732335318d1b 100644 (file)
@@ -72,10 +72,12 @@ ASF::Attribute::Attribute(const ASF::Attribute &other)
 
 ASF::Attribute &ASF::Attribute::operator=(const ASF::Attribute &other)
 {
-  if(d->deref())
-    delete d;
-  d = other.d;
-  d->ref();
+  if(&other != this) {
+    if(d->deref())
+      delete d;
+    d = other.d;
+    d->ref();
+  }
   return *this;
 }