From 9bdd26de43d95e62007920e5914335e590f206a9 Mon Sep 17 00:00:00 2001 From: "Vladimir Golovnev (Glassez)" Date: Fri, 15 Jan 2016 08:50:36 +0300 Subject: [PATCH 1/4] Simplify Log::Msg and Log::Peer Also fixes some unitialized scalar field bugs. --- src/base/logger.cpp | 29 ++--------------------------- src/base/logger.h | 4 ---- 2 files changed, 2 insertions(+), 31 deletions(-) diff --git a/src/base/logger.cpp b/src/base/logger.cpp index 29fb88f2f..d0a1e1220 100644 --- a/src/base/logger.cpp +++ b/src/base/logger.cpp @@ -2,31 +2,6 @@ #include -namespace Log -{ - Msg::Msg() {} - - Msg::Msg(int id, MsgType type, const QString &message) - : id(id) - , timestamp(QDateTime::currentMSecsSinceEpoch()) - , type(type) - , message(message) - { - } - - Peer::Peer() {} - - Peer::Peer(int id, const QString &ip, bool blocked, const QString &reason) - : id(id) - , timestamp(QDateTime::currentMSecsSinceEpoch()) - , ip(ip) - , blocked(blocked) - , reason(reason) - { - } - -} - Logger* Logger::m_instance = 0; Logger::Logger() @@ -61,7 +36,7 @@ void Logger::addMessage(const QString &message, const Log::MsgType &type) { QWriteLocker locker(&lock); - Log::Msg temp(msgCounter++, type, message); + Log::Msg temp = { msgCounter++, QDateTime::currentMSecsSinceEpoch(), type, message }; m_messages.push_back(temp); if (m_messages.size() >= MAX_LOG_MESSAGES) @@ -74,7 +49,7 @@ void Logger::addPeer(const QString &ip, bool blocked, const QString &reason) { QWriteLocker locker(&lock); - Log::Peer temp(peerCounter++, ip, blocked, reason); + Log::Peer temp = { peerCounter++, QDateTime::currentMSecsSinceEpoch(), ip, blocked, reason }; m_peers.push_back(temp); if (m_peers.size() >= MAX_LOG_MESSAGES) diff --git a/src/base/logger.h b/src/base/logger.h index 5520353f5..aaccebbc1 100644 --- a/src/base/logger.h +++ b/src/base/logger.h @@ -20,8 +20,6 @@ namespace Log struct Msg { - Msg(); - Msg(int id, MsgType type, const QString &message); int id; qint64 timestamp; MsgType type; @@ -30,8 +28,6 @@ namespace Log struct Peer { - Peer(int id, const QString &ip, bool blocked, const QString &reason); - Peer(); int id; qint64 timestamp; QString ip; From ea8acf3bbd4caa7588221fb243438cb4097ef380 Mon Sep 17 00:00:00 2001 From: "Vladimir Golovnev (Glassez)" Date: Fri, 15 Jan 2016 09:44:10 +0300 Subject: [PATCH 2/4] Fix unitialized scalar field bugs --- src/base/bittorrent/torrentcreatorthread.cpp | 3 +++ src/base/net/smtp.cpp | 1 + src/webui/abstractwebapplication.cpp | 2 +- 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/base/bittorrent/torrentcreatorthread.cpp b/src/base/bittorrent/torrentcreatorthread.cpp index 548836500..ea82c44e1 100644 --- a/src/base/bittorrent/torrentcreatorthread.cpp +++ b/src/base/bittorrent/torrentcreatorthread.cpp @@ -60,6 +60,9 @@ bool fileFilter(const std::string &f) TorrentCreatorThread::TorrentCreatorThread(QObject *parent) : QThread(parent) + , m_private(false) + , m_pieceSize(0) + , m_abort(false) { } diff --git a/src/base/net/smtp.cpp b/src/base/net/smtp.cpp index e232beeb4..23485e18f 100644 --- a/src/base/net/smtp.cpp +++ b/src/base/net/smtp.cpp @@ -96,6 +96,7 @@ Smtp::Smtp(QObject *parent) : QObject(parent) , m_state(Init) , m_useSsl(false) + , m_authType(AuthPlain) { #ifndef QT_NO_OPENSSL m_socket = new QSslSocket(this); diff --git a/src/webui/abstractwebapplication.cpp b/src/webui/abstractwebapplication.cpp index 131dd2ee3..e9d88d754 100644 --- a/src/webui/abstractwebapplication.cpp +++ b/src/webui/abstractwebapplication.cpp @@ -68,6 +68,7 @@ struct WebSession WebSession(const QString& id) : id(id) { + updateTimestamp(); } void updateTimestamp() @@ -349,7 +350,6 @@ bool AbstractWebApplication::sessionStart() { if (session_ == 0) { session_ = new WebSession(generateSid()); - session_->updateTimestamp(); sessions_[session_->id] = session_; QNetworkCookie cookie(C_SID, session_->id.toUtf8()); From a203246e85023c3d71369419336a4f92bb9a65bc Mon Sep 17 00:00:00 2001 From: "Vladimir Golovnev (Glassez)" Date: Fri, 15 Jan 2016 09:50:29 +0300 Subject: [PATCH 3/4] Fix unitialized pointer field --- src/gui/rss/feedlistwidget.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/gui/rss/feedlistwidget.cpp b/src/gui/rss/feedlistwidget.cpp index 6f00ffcbd..28feef1d2 100644 --- a/src/gui/rss/feedlistwidget.cpp +++ b/src/gui/rss/feedlistwidget.cpp @@ -34,7 +34,11 @@ #include "guiiconprovider.h" #include "feedlistwidget.h" -FeedListWidget::FeedListWidget(QWidget *parent, const Rss::ManagerPtr& rssmanager): QTreeWidget(parent), m_rssManager(rssmanager) { +FeedListWidget::FeedListWidget(QWidget *parent, const Rss::ManagerPtr& rssmanager) + : QTreeWidget(parent) + , m_rssManager(rssmanager) + , m_currentFeed(nullptr) +{ setContextMenuPolicy(Qt::CustomContextMenu); setDragDropMode(QAbstractItemView::InternalMove); setSelectionMode(QAbstractItemView::ExtendedSelection); From a35cbdc4a9e1e40258fcb25c6c0b4759d5942037 Mon Sep 17 00:00:00 2001 From: "Vladimir Golovnev (Glassez)" Date: Fri, 15 Jan 2016 11:32:16 +0300 Subject: [PATCH 4/4] Fix unchecked dynamic_cast Replace some unnecessary (and slow) dynamic_cast with static_cast. --- src/gui/torrentcontentmodel.cpp | 9 ++++++--- src/gui/transferlistsortmodel.cpp | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/gui/torrentcontentmodel.cpp b/src/gui/torrentcontentmodel.cpp index ac4269048..8faf800bd 100644 --- a/src/gui/torrentcontentmodel.cpp +++ b/src/gui/torrentcontentmodel.cpp @@ -167,9 +167,12 @@ TorrentContentModelItem::ItemType TorrentContentModel::itemType(const QModelInde int TorrentContentModel::getFileIndex(const QModelIndex& index) { - TorrentContentModelFile* item = dynamic_cast(static_cast(index.internalPointer())); - Q_ASSERT(item); - return item->fileIndex(); + TorrentContentModelItem *item = static_cast(index.internalPointer()); + if (item->itemType() == TorrentContentModelItem::FileType) + return static_cast(item)->fileIndex(); + + Q_ASSERT(item->itemType() == TorrentContentModelItem::FileType); + return -1; } QVariant TorrentContentModel::data(const QModelIndex& index, int role) const diff --git a/src/gui/transferlistsortmodel.cpp b/src/gui/transferlistsortmodel.cpp index 658563f37..4e7f97c92 100644 --- a/src/gui/transferlistsortmodel.cpp +++ b/src/gui/transferlistsortmodel.cpp @@ -191,7 +191,7 @@ bool TransferListSortModel::lessThan(const QModelIndex &left, const QModelIndex bool TransferListSortModel::lowerPositionThan(const QModelIndex &left, const QModelIndex &right) const { - const TorrentModel *model = dynamic_cast(sourceModel()); + const TorrentModel *model = static_cast(sourceModel()); // Sort according to TR_PRIORITY const int queueL = model->data(model->index(left.row(), TorrentModel::TR_PRIORITY)).toInt();