From 9c6bc6c89a4dc70f002b5708e227d238d2d961c7 Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Fri, 6 Mar 2020 15:01:49 +0800 Subject: [PATCH 1/3] Fix crash when renaming torrent contents Closes #10328. --- src/gui/torrentcontenttreeview.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/gui/torrentcontenttreeview.cpp b/src/gui/torrentcontenttreeview.cpp index c79aaca17..aaf30f57f 100644 --- a/src/gui/torrentcontenttreeview.cpp +++ b/src/gui/torrentcontenttreeview.cpp @@ -94,7 +94,7 @@ void TorrentContentTreeView::renameSelectedFile(BitTorrent::TorrentHandle *torre const QModelIndexList selectedIndexes = selectionModel()->selectedRows(0); if (selectedIndexes.size() != 1) return; - const QModelIndex modelIndex = selectedIndexes.first(); + const QPersistentModelIndex modelIndex = selectedIndexes.first(); if (!modelIndex.isValid()) return; auto model = dynamic_cast(TorrentContentTreeView::model()); @@ -106,7 +106,7 @@ void TorrentContentTreeView::renameSelectedFile(BitTorrent::TorrentHandle *torre bool ok = false; QString newName = AutoExpandableDialog::getText(this, tr("Renaming"), tr("New name:"), QLineEdit::Normal , modelIndex.data().toString(), &ok, isFile).trimmed(); - if (!ok) return; + if (!ok || !modelIndex.isValid()) return; if (!Utils::Fs::isValidFileSystemName(newName)) { RaisedMessageBox::warning(this, tr("Rename error"), @@ -213,7 +213,7 @@ void TorrentContentTreeView::renameSelectedFile(BitTorrent::TorrentInfo &torrent const QModelIndexList selectedIndexes = selectionModel()->selectedRows(0); if (selectedIndexes.size() != 1) return; - const QModelIndex modelIndex = selectedIndexes.first(); + const QPersistentModelIndex modelIndex = selectedIndexes.first(); if (!modelIndex.isValid()) return; auto model = dynamic_cast(TorrentContentTreeView::model()); @@ -225,7 +225,7 @@ void TorrentContentTreeView::renameSelectedFile(BitTorrent::TorrentInfo &torrent bool ok = false; QString newName = AutoExpandableDialog::getText(this, tr("Renaming"), tr("New name:"), QLineEdit::Normal , modelIndex.data().toString(), &ok, isFile).trimmed(); - if (!ok) return; + if (!ok || !modelIndex.isValid()) return; if (!Utils::Fs::isValidFileSystemName(newName)) { RaisedMessageBox::warning(this, tr("Rename error"), From 48e7191ef7266604c28d0ecfb5d4b1ea17bc5a2f Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Fri, 6 Mar 2020 15:04:29 +0800 Subject: [PATCH 2/3] Initialize boolean variables --- src/gui/properties/propertieswidget.cpp | 2 +- src/gui/properties/trackerlistwidget.cpp | 2 +- src/gui/rss/rsswidget.cpp | 6 +++--- src/gui/transferlistwidget.cpp | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/gui/properties/propertieswidget.cpp b/src/gui/properties/propertieswidget.cpp index 59c93cd8f..dd766a226 100644 --- a/src/gui/properties/propertieswidget.cpp +++ b/src/gui/properties/propertieswidget.cpp @@ -710,7 +710,7 @@ void PropertiesWidget::configure() void PropertiesWidget::askWebSeed() { - bool ok; + bool ok = false; // Ask user for a new url seed const QString urlSeed = AutoExpandableDialog::getText(this, tr("New URL seed", "New HTTP source"), tr("New URL seed:"), QLineEdit::Normal, diff --git a/src/gui/properties/trackerlistwidget.cpp b/src/gui/properties/trackerlistwidget.cpp index 1690cd46d..706c0a06e 100644 --- a/src/gui/properties/trackerlistwidget.cpp +++ b/src/gui/properties/trackerlistwidget.cpp @@ -482,7 +482,7 @@ void TrackerListWidget::editSelectedTracker() // During multi-select only process item selected last const QUrl trackerURL = selectedTrackerItems.last()->text(COL_URL); - bool ok; + bool ok = false; const QUrl newTrackerURL = AutoExpandableDialog::getText(this, tr("Tracker editing"), tr("Tracker URL:"), QLineEdit::Normal, trackerURL.toString(), &ok).trimmed(); if (!ok) return; diff --git a/src/gui/rss/rsswidget.cpp b/src/gui/rss/rsswidget.cpp index 7e342f4a6..45267a381 100644 --- a/src/gui/rss/rsswidget.cpp +++ b/src/gui/rss/rsswidget.cpp @@ -216,7 +216,7 @@ void RSSWidget::displayItemsListMenu(const QPoint &) void RSSWidget::askNewFolder() { - bool ok; + bool ok = false; QString newName = AutoExpandableDialog::getText( this, tr("Please choose a folder name"), tr("Folder name:"), QLineEdit::Normal , tr("New folder"), &ok); @@ -257,7 +257,7 @@ void RSSWidget::on_newFeedButton_clicked() const QString clipText = qApp->clipboard()->text(); const QString defaultURL = Net::DownloadManager::hasSupportedScheme(clipText) ? clipText : "http://"; - bool ok; + bool ok = false; QString newURL = AutoExpandableDialog::getText( this, tr("Please type a RSS feed URL"), tr("Feed URL:"), QLineEdit::Normal, defaultURL, &ok); if (!ok) return; @@ -386,7 +386,7 @@ void RSSWidget::renameSelectedRSSItem() RSS::Item *rssItem = m_feedListWidget->getRSSItem(item); const QString parentPath = RSS::Item::parentPath(rssItem->path()); - bool ok; + bool ok = false; do { QString newName = AutoExpandableDialog::getText( this, tr("Please choose a new name for this RSS feed"), tr("New feed name:") diff --git a/src/gui/transferlistwidget.cpp b/src/gui/transferlistwidget.cpp index 3dda70199..30e196c03 100644 --- a/src/gui/transferlistwidget.cpp +++ b/src/gui/transferlistwidget.cpp @@ -1003,7 +1003,7 @@ void TransferListWidget::renameSelectedTorrent() if (!torrent) return; // Ask for a new Name - bool ok; + bool ok = false; QString name = AutoExpandableDialog::getText(this, tr("Rename"), tr("New name:"), QLineEdit::Normal, torrent->name(), &ok); if (ok && !name.isEmpty()) { name.replace(QRegularExpression("\r?\n|\r"), " "); From 62b0d251406657fda3e4a3bc9b1ff2656e3a1ace Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Sat, 7 Mar 2020 10:06:35 +0800 Subject: [PATCH 3/3] Capture pointer by value --- src/gui/properties/propertieswidget.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gui/properties/propertieswidget.cpp b/src/gui/properties/propertieswidget.cpp index dd766a226..8698c6e7e 100644 --- a/src/gui/properties/propertieswidget.cpp +++ b/src/gui/properties/propertieswidget.cpp @@ -640,7 +640,7 @@ void PropertiesWidget::displayFilesListMenu(const QPoint &) // The selected torrent might have disappeared during exec() // so we just close menu when an appropriate model is reset connect(m_ui->filesList->model(), &QAbstractItemModel::modelAboutToBeReset - , menu, [&menu]() + , menu, [menu]() { menu->setActiveAction(nullptr); menu->close();