aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDenis Shienkov <denis.shienkov@gmail.com>2021-11-27 12:54:32 +0300
committerDenis Shienkov <denis.shienkov@gmail.com>2021-11-29 18:54:44 +0000
commit2218ba5de2a8564bc5a5510a34a4797a473ccd44 (patch)
tree0d45f10946a11a0b8737068eb78adde458470bd2 /src
parentef9780f0f77bc0d757fda61e5567befa6d45f429 (diff)
Fix Clang-Tidy & Clazy 'bugprone-unhandled-self-assignment' warnings
Change-Id: I566b2caaddb3f1167c4579915af0c15dde836b73 Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/lib/corelib/logging/logger.cpp3
-rw-r--r--src/lib/corelib/parser/qmlerror.cpp3
-rw-r--r--src/shared/json/json.cpp12
3 files changed, 18 insertions, 0 deletions
diff --git a/src/lib/corelib/logging/logger.cpp b/src/lib/corelib/logging/logger.cpp
index d4020892f..d4f51cd30 100644
--- a/src/lib/corelib/logging/logger.cpp
+++ b/src/lib/corelib/logging/logger.cpp
@@ -79,6 +79,9 @@ LogWriter::~LogWriter()
const LogWriter &LogWriter::operator=(const LogWriter &other)
{
+ if (this == &other) // Self assignment guard.
+ return *this;
+
m_logSink = other.m_logSink;
m_level = other.m_level;
m_message = other.m_message;
diff --git a/src/lib/corelib/parser/qmlerror.cpp b/src/lib/corelib/parser/qmlerror.cpp
index 157d1690f..d9fbdd703 100644
--- a/src/lib/corelib/parser/qmlerror.cpp
+++ b/src/lib/corelib/parser/qmlerror.cpp
@@ -114,6 +114,9 @@ QmlError::QmlError(const QmlError &other)
*/
QmlError &QmlError::operator=(const QmlError &other)
{
+ if (this == &other) // Self assignment guard.
+ return *this;
+
if (!other.d) {
delete d;
d = nullptr;
diff --git a/src/shared/json/json.cpp b/src/shared/json/json.cpp
index ffd7cbe9a..eb27d6296 100644
--- a/src/shared/json/json.cpp
+++ b/src/shared/json/json.cpp
@@ -841,6 +841,9 @@ JsonValue::JsonValue(const JsonValue &other)
*/
JsonValue &JsonValue::operator=(const JsonValue &other)
{
+ if (this == &other) // Self assignment guard.
+ return *this;
+
if (t == String && stringData && !stringData->ref.deref())
delete stringData;
@@ -1310,6 +1313,9 @@ JsonArray::JsonArray(const JsonArray &other)
*/
JsonArray &JsonArray::operator=(const JsonArray &other)
{
+ if (this == &other) // Self assignment guard.
+ return *this;
+
if (d != other.d) {
if (d && !d->ref.deref())
delete d;
@@ -2353,6 +2359,9 @@ JsonObject::JsonObject(const JsonObject &other)
*/
JsonObject &JsonObject::operator=(const JsonObject &other)
{
+ if (this == &other) // Self assignment guard.
+ return *this;
+
if (d != other.d) {
if (d && !d->ref.deref())
delete d;
@@ -3305,6 +3314,9 @@ JsonDocument::JsonDocument(const JsonDocument &other)
*/
JsonDocument &JsonDocument::operator=(const JsonDocument &other)
{
+ if (this == &other) // Self assignment guard.
+ return *this;
+
if (d != other.d) {
if (d && !d->ref.deref())
delete d;