summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Tsuk1ha2025-08-20 23:04:42 +0800
committerGravatar Nikias Bassen2025-12-05 00:43:45 +0100
commitb020cf26b8f35aa82a091e02945325af4b2534b0 (patch)
treefa8d6c9f11dbb2099ef2f6df71d7583272869e3e
parent18e5b22a71f85091127cc063db79c8df687c582c (diff)
downloadlibplist-b020cf26b8f35aa82a091e02945325af4b2534b0.tar.gz
libplist-b020cf26b8f35aa82a091e02945325af4b2534b0.tar.bz2
cpp: Add `this` comparison to `operator=` copy assign
-rw-r--r--src/Array.cpp2
-rw-r--r--src/Boolean.cpp2
-rw-r--r--src/Data.cpp2
-rw-r--r--src/Date.cpp2
-rw-r--r--src/Dictionary.cpp2
-rw-r--r--src/Integer.cpp2
-rw-r--r--src/Key.cpp2
-rw-r--r--src/Real.cpp2
-rw-r--r--src/String.cpp2
-rw-r--r--src/Uid.cpp2
10 files changed, 20 insertions, 0 deletions
diff --git a/src/Array.cpp b/src/Array.cpp
index 49b8924..784df7c 100644
--- a/src/Array.cpp
+++ b/src/Array.cpp
@@ -62,6 +62,8 @@ Array::Array(const PList::Array& a) : Structure(a.GetParent())
Array& Array::operator=(const PList::Array& a)
{
+ if (this == &a) return *this;
+
plist_free(_node);
for (size_t it = 0; it < _array.size(); it++) {
delete _array.at(it);
diff --git a/src/Boolean.cpp b/src/Boolean.cpp
index 9ec1a63..2a5e303 100644
--- a/src/Boolean.cpp
+++ b/src/Boolean.cpp
@@ -40,6 +40,8 @@ Boolean::Boolean(const PList::Boolean& b) : Node(PLIST_BOOLEAN)
Boolean& Boolean::operator=(const PList::Boolean& b)
{
+ if (this == &b) return *this;
+
plist_free(_node);
_node = plist_copy(b.GetPlist());
return *this;
diff --git a/src/Data.cpp b/src/Data.cpp
index 56b2d6b..94767c9 100644
--- a/src/Data.cpp
+++ b/src/Data.cpp
@@ -40,6 +40,8 @@ Data::Data(const PList::Data& d) : Node(PLIST_DATA)
Data& Data::operator=(const PList::Data& b)
{
+ if (this == &b) return *this;
+
plist_free(_node);
_node = plist_copy(b.GetPlist());
return *this;
diff --git a/src/Date.cpp b/src/Date.cpp
index cbfa123..214220b 100644
--- a/src/Date.cpp
+++ b/src/Date.cpp
@@ -40,6 +40,8 @@ Date::Date(const PList::Date& d) : Node(PLIST_DATE)
Date& Date::operator=(const PList::Date& d)
{
+ if (this == &d) return *this;
+
plist_free(_node);
_node = plist_copy(d.GetPlist());
return *this;
diff --git a/src/Dictionary.cpp b/src/Dictionary.cpp
index 0a909e5..b354945 100644
--- a/src/Dictionary.cpp
+++ b/src/Dictionary.cpp
@@ -65,6 +65,8 @@ Dictionary::Dictionary(const PList::Dictionary& d) : Structure(d.GetParent())
Dictionary& Dictionary::operator=(const PList::Dictionary& d)
{
+ if (this == &d) return *this;
+
for (Dictionary::iterator it = _map.begin(); it != _map.end(); it++)
{
plist_free(it->second->GetPlist());
diff --git a/src/Integer.cpp b/src/Integer.cpp
index 653455d..26e7ccf 100644
--- a/src/Integer.cpp
+++ b/src/Integer.cpp
@@ -41,6 +41,8 @@ Integer::Integer(const PList::Integer& i) : Node(PLIST_INT)
Integer& Integer::operator=(const PList::Integer& i)
{
+ if (this == &i) return *this;
+
plist_free(_node);
_node = plist_copy(i.GetPlist());
return *this;
diff --git a/src/Key.cpp b/src/Key.cpp
index 86a0bf8..459227a 100644
--- a/src/Key.cpp
+++ b/src/Key.cpp
@@ -40,6 +40,8 @@ Key::Key(const PList::Key& k) : Node(PLIST_INT)
Key& Key::operator=(const PList::Key& k)
{
+ if (this == &k) return *this;
+
plist_free(_node);
_node = plist_copy(k.GetPlist());
return *this;
diff --git a/src/Real.cpp b/src/Real.cpp
index 02d1d9b..b743ab5 100644
--- a/src/Real.cpp
+++ b/src/Real.cpp
@@ -39,6 +39,8 @@ Real::Real(const PList::Real& d) : Node(PLIST_INT)
Real& Real::operator=(const PList::Real& d)
{
+ if (this == &d) return *this;
+
plist_free(_node);
_node = plist_copy(d.GetPlist());
return *this;
diff --git a/src/String.cpp b/src/String.cpp
index 8daec0f..bcd5e2e 100644
--- a/src/String.cpp
+++ b/src/String.cpp
@@ -40,6 +40,8 @@ String::String(const PList::String& s) : Node(PLIST_INT)
String& String::operator=(const PList::String& s)
{
+ if (this == &s) return *this;
+
plist_free(_node);
_node = plist_copy(s.GetPlist());
return *this;
diff --git a/src/Uid.cpp b/src/Uid.cpp
index 8c73c80..d73f777 100644
--- a/src/Uid.cpp
+++ b/src/Uid.cpp
@@ -40,6 +40,8 @@ Uid::Uid(const PList::Uid& i) : Node(PLIST_UID)
Uid& Uid::operator=(const PList::Uid& i)
{
+ if (this == &i) return *this;
+
plist_free(_node);
_node = plist_copy(i.GetPlist());
return *this;