Add self-assignment check in operator=

Method 'operator=' should check its argument with 'this' pointer.
This commit is contained in:
garima-g 2015-11-05 11:19:44 +05:30
parent 998ebf4ce6
commit 8b4a27beb4

View 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;
}