]> granicus.if.org Git - taglib/commitdiff
Add self-assignment check in operator=
authorgarima-g <garima.g@samsung.com>
Thu, 5 Nov 2015 05:49:44 +0000 (11:19 +0530)
committergarima-g <garima.g@samsung.com>
Thu, 5 Nov 2015 05:49:44 +0000 (11:19 +0530)
Method 'operator=' should check its argument with 'this' pointer.

taglib/mp4/mp4item.cpp

index 671f26b4d6cac6a2c6ffaf7991aaa8a49e6177ba..aa59fedadc21cc85e204c1821a0aa84e7aadabdd 100644 (file)
@@ -64,11 +64,13 @@ MP4::Item::Item(const Item &item) : d(item.d)
 MP4::Item &
 MP4::Item::operator=(const Item &item)
 {
-  if(d->deref()) {
-    delete d;
+  if(&item != this) {
+    if(d->deref()) {
+      delete d;
+    }
+    d = item.d;
+    d->ref();
   }
-  d = item.d;
-  d->ref();
   return *this;
 }