diff mbox series

[1/3] kernel-shark: Make KsEventsCheckBoxWidget::removeSystem more robust

Message ID 20190723125204.22799-2-y.karadz@gmail.com (mailing list archive)
State Accepted
Headers show
Series Fixes needed befor KS 1.0 | expand

Commit Message

Yordan Karadzhov July 23, 2019, 12:52 p.m. UTC
The function has to be able to handle safely the case when the Checkbox
tree widget is empty or it does not contain the item to be removed.

Reported-by: howaboutsynergy <howaboutsynergy@pm.me>
Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=204277
Fixes: 4a02481fff (Remove all system=ftrace events from Record dialog)
Signed-off-by: Yordan Karadzhov (VMware) <y.karadz@gmail.com>
---
 kernel-shark/src/KsWidgetsLib.cpp | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
diff mbox series

Patch

diff --git a/kernel-shark/src/KsWidgetsLib.cpp b/kernel-shark/src/KsWidgetsLib.cpp
index 84afec9..330230e 100644
--- a/kernel-shark/src/KsWidgetsLib.cpp
+++ b/kernel-shark/src/KsWidgetsLib.cpp
@@ -749,10 +749,13 @@  QStringList KsEventsCheckBoxWidget::getCheckedEvents(bool option)
 
 /** Remove a System from the Checkbox tree. */
 void KsEventsCheckBoxWidget::removeSystem(QString name) {
-	QTreeWidgetItem *item =
-		_tree.findItems(name, Qt::MatchFixedString, 0)[0];
+	auto itemList = _tree.findItems(name, Qt::MatchFixedString, 0);
+	int index;
 
-	int index = _tree.indexOfTopLevelItem(item);
+	if (itemList.isEmpty())
+		return;
+
+	index = _tree.indexOfTopLevelItem(itemList[0]);
 	if (index >= 0)
 		_tree.takeTopLevelItem(index);
 }