From 2efd4f2a771b642d6bd4be3cc91cc8e937a0b231 Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Thu, 9 Sep 2021 21:36:47 +0800 Subject: [PATCH 1/2] Prevent self-assignment in assignment operator --- src/base/bittorrent/torrentinfo.cpp | 5 ++++- src/base/rss/rss_autodownloadrule.cpp | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/base/bittorrent/torrentinfo.cpp b/src/base/bittorrent/torrentinfo.cpp index c8a6e118c..a5196e052 100644 --- a/src/base/bittorrent/torrentinfo.cpp +++ b/src/base/bittorrent/torrentinfo.cpp @@ -88,7 +88,10 @@ TorrentInfo::TorrentInfo(const TorrentInfo &other) TorrentInfo &TorrentInfo::operator=(const TorrentInfo &other) { - m_nativeInfo = other.m_nativeInfo; + if (this != &other) + { + m_nativeInfo = other.m_nativeInfo; + } return *this; } diff --git a/src/base/rss/rss_autodownloadrule.cpp b/src/base/rss/rss_autodownloadrule.cpp index ecc6b08fd..d78bb3541 100644 --- a/src/base/rss/rss_autodownloadrule.cpp +++ b/src/base/rss/rss_autodownloadrule.cpp @@ -440,7 +440,10 @@ bool AutoDownloadRule::accepts(const QVariantHash &articleData) AutoDownloadRule &AutoDownloadRule::operator=(const AutoDownloadRule &other) { - m_dataPtr = other.m_dataPtr; + if (this != &other) + { + m_dataPtr = other.m_dataPtr; + } return *this; } From cb29685a24183067e56b56c88c3704b12a926d1c Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Thu, 9 Sep 2021 21:38:59 +0800 Subject: [PATCH 2/2] Use Qt macro to disable various constructors --- src/gui/raisedmessagebox.h | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/gui/raisedmessagebox.h b/src/gui/raisedmessagebox.h index 28d8fd238..e994a940f 100644 --- a/src/gui/raisedmessagebox.h +++ b/src/gui/raisedmessagebox.h @@ -32,7 +32,8 @@ class RaisedMessageBox final : public QMessageBox { - Q_OBJECT + Q_OBJECT + Q_DISABLE_COPY_MOVE(RaisedMessageBox) public: static QMessageBox::StandardButton critical(QWidget *parent, const QString &title, const QString &text, QMessageBox::StandardButtons buttons = QMessageBox::Ok, QMessageBox::StandardButton defaultButton = QMessageBox::NoButton); @@ -45,9 +46,6 @@ protected: private: RaisedMessageBox(QMessageBox::Icon icon, const QString &title, const QString &text, QMessageBox::StandardButtons buttons = NoButton, QWidget *parent = nullptr, Qt::WindowFlags f = Qt::Dialog|Qt::MSWindowsFixedSizeDialogHint); - RaisedMessageBox(); - RaisedMessageBox(RaisedMessageBox const&); - void operator=(RaisedMessageBox const&); static QMessageBox::StandardButton impl(const QMessageBox::Icon &icon, QWidget *parent, const QString &title, const QString &text, QMessageBox::StandardButtons buttons = QMessageBox::Ok, QMessageBox::StandardButton defaultButton = QMessageBox::NoButton); };