From 0ae021f9a17625326a07bb146e3083b837d878c3 Mon Sep 17 00:00:00 2001 From: Paul I Date: Mon, 23 Apr 2018 10:54:06 +0300 Subject: [PATCH] Check QModelIndex/column before processing double click event (#450) --- src/widgets/ClassesWidget.cpp | 3 +++ src/widgets/CommentsWidget.cpp | 10 ++++++++-- src/widgets/EntrypointWidget.cpp | 5 ++++- src/widgets/ExportsWidget.cpp | 3 +++ src/widgets/FlagsWidget.cpp | 3 +++ src/widgets/FunctionsWidget.cpp | 3 +++ src/widgets/ImportsWidget.cpp | 3 +++ src/widgets/RelocsWidget.cpp | 3 +++ src/widgets/ResourcesWidget.cpp | 3 +++ src/widgets/SdbDock.cpp | 3 +++ src/widgets/SearchWidget.cpp | 3 +++ src/widgets/SectionsWidget.cpp | 3 +++ src/widgets/SidebarWidget.cpp | 10 ++++++++-- src/widgets/StringsWidget.cpp | 3 +++ src/widgets/SymbolsWidget.cpp | 3 ++- src/widgets/TypesWidget.cpp | 4 +++- src/widgets/VTablesWidget.cpp | 3 +++ 17 files changed, 61 insertions(+), 7 deletions(-) diff --git a/src/widgets/ClassesWidget.cpp b/src/widgets/ClassesWidget.cpp index d566349b..d4f4b6d8 100644 --- a/src/widgets/ClassesWidget.cpp +++ b/src/widgets/ClassesWidget.cpp @@ -267,6 +267,9 @@ void ClassesWidget::refreshClasses() void ClassesWidget::on_classesTreeView_doubleClicked(const QModelIndex &index) { + if (!index.isValid()) + return; + RVA offset = index.data(ClassesModel::OffsetRole).value(); Core()->seek(offset); } diff --git a/src/widgets/CommentsWidget.cpp b/src/widgets/CommentsWidget.cpp index a6ca70b9..9ea645d9 100644 --- a/src/widgets/CommentsWidget.cpp +++ b/src/widgets/CommentsWidget.cpp @@ -35,15 +35,21 @@ CommentsWidget::CommentsWidget(MainWindow *main, QAction *action) : CommentsWidget::~CommentsWidget() {} -void CommentsWidget::on_commentsTreeWidget_itemDoubleClicked(QTreeWidgetItem *item, int) +void CommentsWidget::on_commentsTreeWidget_itemDoubleClicked(QTreeWidgetItem *item, int column) { + if (column < 0) + return; + // Get offset and name of item double clicked CommentDescription comment = item->data(0, Qt::UserRole).value(); Core()->seek(comment.offset); } -void CommentsWidget::on_nestedCmtsTreeWidget_itemDoubleClicked(QTreeWidgetItem *item, int) +void CommentsWidget::on_nestedCmtsTreeWidget_itemDoubleClicked(QTreeWidgetItem *item, int column) { + if (column < 0) + return; + // don't react on top-level items if (item->parent() == nullptr) { return; diff --git a/src/widgets/EntrypointWidget.cpp b/src/widgets/EntrypointWidget.cpp index 132868f1..fcd798a0 100644 --- a/src/widgets/EntrypointWidget.cpp +++ b/src/widgets/EntrypointWidget.cpp @@ -45,8 +45,11 @@ void EntrypointWidget::setScrollMode() } void EntrypointWidget::on_entrypointTreeWidget_itemDoubleClicked(QTreeWidgetItem *item, - int /* column */) + int column) { + if (column < 0) + return; + EntrypointDescription ep = item->data(0, Qt::UserRole).value(); Core()->seek(ep.vaddr); } diff --git a/src/widgets/ExportsWidget.cpp b/src/widgets/ExportsWidget.cpp index 1d28009b..28942bbe 100644 --- a/src/widgets/ExportsWidget.cpp +++ b/src/widgets/ExportsWidget.cpp @@ -174,6 +174,9 @@ void ExportsWidget::setScrollMode() void ExportsWidget::on_exportsTreeView_doubleClicked(const QModelIndex &index) { + if (!index.isValid()) + return; + ExportDescription exp = index.data(ExportsModel::ExportDescriptionRole).value(); Core()->seek(exp.vaddr); } diff --git a/src/widgets/FlagsWidget.cpp b/src/widgets/FlagsWidget.cpp index 8a674202..40922ece 100644 --- a/src/widgets/FlagsWidget.cpp +++ b/src/widgets/FlagsWidget.cpp @@ -149,6 +149,9 @@ FlagsWidget::~FlagsWidget() {} void FlagsWidget::on_flagsTreeView_doubleClicked(const QModelIndex &index) { + if (!index.isValid()) + return; + FlagDescription flag = index.data(FlagsModel::FlagDescriptionRole).value(); Core()->seek(flag.offset); } diff --git a/src/widgets/FunctionsWidget.cpp b/src/widgets/FunctionsWidget.cpp index 9328be72..d329351b 100644 --- a/src/widgets/FunctionsWidget.cpp +++ b/src/widgets/FunctionsWidget.cpp @@ -451,6 +451,9 @@ void FunctionsWidget::refreshTree() void FunctionsWidget::onFunctionsDoubleClicked(const QModelIndex &index) { + if (!index.isValid()) + return; + FunctionDescription function = index.data( FunctionModel::FunctionDescriptionRole).value(); Core()->seek(function.offset); diff --git a/src/widgets/ImportsWidget.cpp b/src/widgets/ImportsWidget.cpp index 819959a7..41844eb9 100644 --- a/src/widgets/ImportsWidget.cpp +++ b/src/widgets/ImportsWidget.cpp @@ -190,5 +190,8 @@ void ImportsWidget::setScrollMode() void ImportsWidget::on_importsTreeView_doubleClicked(const QModelIndex &index) { + if (!index.isValid()) + return; + Core()->seek(index.data(ImportsModel::AddressRole).toLongLong()); } diff --git a/src/widgets/RelocsWidget.cpp b/src/widgets/RelocsWidget.cpp index f6471720..93e21817 100644 --- a/src/widgets/RelocsWidget.cpp +++ b/src/widgets/RelocsWidget.cpp @@ -88,6 +88,9 @@ RelocsWidget::~RelocsWidget() {} void RelocsWidget::on_relocsTreeView_doubleClicked(const QModelIndex &index) { + if (!index.isValid()) + return; + Core()->seek(index.data(RelocsModel::AddressRole).toLongLong()); } diff --git a/src/widgets/ResourcesWidget.cpp b/src/widgets/ResourcesWidget.cpp index 33ff00ec..5096075c 100644 --- a/src/widgets/ResourcesWidget.cpp +++ b/src/widgets/ResourcesWidget.cpp @@ -113,6 +113,9 @@ void ResourcesWidget::refreshResources() void ResourcesWidget::onDoubleClicked(const QModelIndex &index) { + if (!index.isValid()) + return; + ResourcesDescription res = index.data(Qt::UserRole).value(); Core()->seek(res.vaddr); } diff --git a/src/widgets/SdbDock.cpp b/src/widgets/SdbDock.cpp index 2a80306d..e69f0a5f 100644 --- a/src/widgets/SdbDock.cpp +++ b/src/widgets/SdbDock.cpp @@ -57,6 +57,9 @@ void SdbDock::reload(QString _path) void SdbDock::on_treeWidget_itemDoubleClicked(QTreeWidgetItem *item, int column) { + if (column < 0) + return; + QString newpath; if (column == 0) { diff --git a/src/widgets/SearchWidget.cpp b/src/widgets/SearchWidget.cpp index 98cf52a0..d515a190 100644 --- a/src/widgets/SearchWidget.cpp +++ b/src/widgets/SearchWidget.cpp @@ -154,6 +154,9 @@ SearchWidget::~SearchWidget() {} void SearchWidget::on_searchTreeView_doubleClicked(const QModelIndex &index) { + if (!index.isValid()) + return; + SearchDescription search = index.data( SearchModel::SearchDescriptionRole).value(); Core()->seek(search.offset); diff --git a/src/widgets/SectionsWidget.cpp b/src/widgets/SectionsWidget.cpp index d5ab37ce..f588bceb 100644 --- a/src/widgets/SectionsWidget.cpp +++ b/src/widgets/SectionsWidget.cpp @@ -95,6 +95,9 @@ void SectionsWidget::fillSections(int row, const SectionDescription §ion) void SectionsWidget::onSectionsDoubleClicked(const QModelIndex &index) { + if (!index.isValid()) + return; + QTreeWidgetItem *section = tree->topLevelItem(index.row()); auto addr = section->text(2); Core()->seek(addr); diff --git a/src/widgets/SidebarWidget.cpp b/src/widgets/SidebarWidget.cpp index 3d6fbba5..5b07ffb6 100644 --- a/src/widgets/SidebarWidget.cpp +++ b/src/widgets/SidebarWidget.cpp @@ -56,14 +56,20 @@ void SidebarWidget::refresh(RVA addr) fillRegistersInfo(); } -void SidebarWidget::on_xrefFromTreeWidget_itemDoubleClicked(QTreeWidgetItem *item, int /*column*/) +void SidebarWidget::on_xrefFromTreeWidget_itemDoubleClicked(QTreeWidgetItem *item, int column) { + if (column < 0) + return; + XrefDescription xref = item->data(0, Qt::UserRole).value(); Core()->seek(xref.to); } -void SidebarWidget::on_xrefToTreeWidget_itemDoubleClicked(QTreeWidgetItem *item, int /*column*/) +void SidebarWidget::on_xrefToTreeWidget_itemDoubleClicked(QTreeWidgetItem *item, int column) { + if (column < 0) + return; + XrefDescription xref = item->data(0, Qt::UserRole).value(); Core()->seek(xref.from); } diff --git a/src/widgets/StringsWidget.cpp b/src/widgets/StringsWidget.cpp index 4c9c485f..129829a2 100644 --- a/src/widgets/StringsWidget.cpp +++ b/src/widgets/StringsWidget.cpp @@ -164,6 +164,9 @@ StringsWidget::~StringsWidget() {} void StringsWidget::on_stringsTreeView_doubleClicked(const QModelIndex &index) { + if (!index.isValid()) + return; + StringDescription str = index.data(StringsModel::StringDescriptionRole).value(); Core()->seek(str.vaddr); } diff --git a/src/widgets/SymbolsWidget.cpp b/src/widgets/SymbolsWidget.cpp index cd2eaef1..e27a7499 100644 --- a/src/widgets/SymbolsWidget.cpp +++ b/src/widgets/SymbolsWidget.cpp @@ -25,7 +25,8 @@ SymbolsWidget::~SymbolsWidget() {} void SymbolsWidget::on_symbolsTreeWidget_itemDoubleClicked(QTreeWidgetItem *item, int column) { - Q_UNUSED(column); + if (column < 0) + return; // Get offset and name of item double clicked SymbolDescription symbol = item->data(0, Qt::UserRole).value(); diff --git a/src/widgets/TypesWidget.cpp b/src/widgets/TypesWidget.cpp index 8de167b7..855936f9 100644 --- a/src/widgets/TypesWidget.cpp +++ b/src/widgets/TypesWidget.cpp @@ -142,7 +142,9 @@ void TypesWidget::setScrollMode() void TypesWidget::on_typesTreeView_doubleClicked(const QModelIndex &index) { - Q_UNUSED(index); + if (!index.isValid()) + return; + // TypeDescription exp = index.data(TypesModel::TypeDescriptionRole).value(); // Core()->seek(exp.vaddr); } diff --git a/src/widgets/VTablesWidget.cpp b/src/widgets/VTablesWidget.cpp index 79c90dd6..9a007a99 100644 --- a/src/widgets/VTablesWidget.cpp +++ b/src/widgets/VTablesWidget.cpp @@ -182,6 +182,9 @@ void VTablesWidget::refreshVTables() void VTablesWidget::on_vTableTreeView_doubleClicked(const QModelIndex &index) { + if (!index.isValid()) + return; + QModelIndex parent = index.parent(); if (parent.isValid()) Core()->seek(index.data(