diff options
author | Tsuda Kageyu <tsuda.kageyu@gmail.com> | 2015-11-05 15:43:03 +0900 |
---|---|---|
committer | Tsuda Kageyu <tsuda.kageyu@gmail.com> | 2015-11-05 15:43:03 +0900 |
commit | 77087cf865c20a59dc0fc0c6cdc87bc60ede1c12 (patch) | |
tree | a1a223b4f366de18382fd3fd8962a20bc296e344 | |
parent | 153820bf12df9ebafbfaea702209eb03b68367ac (diff) | |
parent | 8b4a27beb409c5a81f956b48c248c4fad0b258a3 (diff) |
Merge pull request #675 from garima-g/patch-1
Add self-assignment check in operator=
-rw-r--r-- | taglib/ape/apeitem.cpp | 6 | ||||
-rw-r--r-- | taglib/asf/asfattribute.cpp | 10 | ||||
-rw-r--r-- | taglib/mp4/mp4coverart.cpp | 9 | ||||
-rw-r--r-- | taglib/mp4/mp4item.cpp | 10 |
4 files changed, 21 insertions, 14 deletions
diff --git a/taglib/ape/apeitem.cpp b/taglib/ape/apeitem.cpp index 3490173a..49c3a665 100644 --- a/taglib/ape/apeitem.cpp +++ b/taglib/ape/apeitem.cpp @@ -86,8 +86,10 @@ APE::Item::~Item() Item &APE::Item::operator=(const Item &item) { - delete d; - d = new ItemPrivate(*item.d); + if(&item != this) { + delete d; + d = new ItemPrivate(*item.d); + } return *this; } diff --git a/taglib/asf/asfattribute.cpp b/taglib/asf/asfattribute.cpp index 116bfe21..7a40bea3 100644 --- a/taglib/asf/asfattribute.cpp +++ b/taglib/asf/asfattribute.cpp @@ -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; } diff --git a/taglib/mp4/mp4coverart.cpp b/taglib/mp4/mp4coverart.cpp index 2746469d..f2152335 100644 --- a/taglib/mp4/mp4coverart.cpp +++ b/taglib/mp4/mp4coverart.cpp @@ -54,11 +54,12 @@ MP4::CoverArt::CoverArt(const CoverArt &item) : d(item.d) MP4::CoverArt & MP4::CoverArt::operator=(const CoverArt &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; } diff --git a/taglib/mp4/mp4item.cpp b/taglib/mp4/mp4item.cpp index 671f26b4..aa59feda 100644 --- a/taglib/mp4/mp4item.cpp +++ b/taglib/mp4/mp4item.cpp @@ -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; } |