diff mbox series

[2/2] kernel-shark-qt: Add better handling of the search iterator.

Message ID 20181130153749.4419-2-ykaradzhov@vmware.com (mailing list archive)
State Accepted
Commit 879f363c5c60ce9661b7a610e64ed9c97e043ac2
Headers show
Series [1/2] kernel-shark-qt: Correct the coordinates of the Quick Context Menu | expand

Commit Message

Yordan Karadzhov Nov. 30, 2018, 3:38 p.m. UTC
This patch provides better handling of the search iterator in the case
when no matches are found. Without these fixes, the search iterator
shows an arbitrary value when we load a session that has the active
marker being set.

Signed-off-by: Yordan Karadzhov <ykaradzhov@vmware.com>
---
 kernel-shark-qt/src/KsTraceViewer.cpp | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
diff mbox series

Patch

diff --git a/kernel-shark-qt/src/KsTraceViewer.cpp b/kernel-shark-qt/src/KsTraceViewer.cpp
index d52d7e3..a308ea0 100644
--- a/kernel-shark-qt/src/KsTraceViewer.cpp
+++ b/kernel-shark-qt/src/KsTraceViewer.cpp
@@ -420,8 +420,13 @@  void KsTraceViewer::_prev()
 
 void KsTraceViewer::_updateSearchCount()
 {
-	int index(_it - _matchList.begin());
-	int total(_matchList.count());
+	int index, total;
+
+	if (_matchList.isEmpty())
+		return;
+
+	index = _it - _matchList.begin();
+	total =_matchList.count();
 
 	_searchCountLabel.setText(QString(" %1 / %2").arg(index).arg(total));
 }
@@ -655,6 +660,7 @@  size_t KsTraceViewer::_searchItems(int column,
 
 void KsTraceViewer::_setSearchIterator(int row)
 {
+	_it = _matchList.begin();
 	if (_matchList.isEmpty())
 		return;
 
@@ -662,7 +668,6 @@  void KsTraceViewer::_setSearchIterator(int row)
 	 * Move the iterator to the first element of the match list
 	 * after the selected one.
 	 */
-	_it = _matchList.begin();
 	while (*_it < row) {
 		++_it;  // Move the iterator.
 		if (_it == _matchList.end()) {