Fix hang for single result search after others
authorShane Synan <digitalcircuit36939@gmail.com>
Thu, 13 Oct 2016 08:39:14 +0000 (03:39 -0500)
committerManuel Nickschas <sputnick@quassel-irc.org>
Wed, 4 Apr 2018 21:14:03 +0000 (23:14 +0200)
Add check for equal start and end indices in updateHighlights, stop
the search loop when this happens.  Regular search still seems to
work fine (if you found this via 'git blame', whoops).

Unfortunately, this seems specific to the contents of a buffer.
First, find a buffer that you've encountered freezing, and keep track
of what was loaded, where it was, and the two most recent search
terms.

For example...
1.  Load some backlog to a buffer
2.  Search for term with any number of matches
3.  Making sure to -type over existing words without first
    backspacing-, search for another term with only one match

Expected: Search results found, no freezing
Actual:   Quassel hangs.  startPos and endPos = same place,
          start = 0, end = 0, _currentHighlight appears to retain
          values from the previous search.

Resolves GH-259.

(cherry picked from commit 6d35d3ab0b4885c2db40e5aa25574a5764e52c51)

src/qtui/chatviewsearchcontroller.cpp

index e21dc8a..3fdc01a 100644 (file)
@@ -166,6 +166,30 @@ void ChatViewSearchController::updateHighlights(bool reuse)
                         _currentHighlight = start;
                         break;
                     }
+                    if (end == 0 && start == 0) {
+                        // Sometimes we can run into an issue where the start and end are both set
+                        // to zero.  Rather than endlessly spin this loop, bail out.  Search seems
+                        // to work fine.
+                        // [Test case]
+                        // Unfortunately, this seems specific to the contents of a buffer.  First,
+                        // find a buffer that you've encountered freezing, and keep track of what
+                        // was loaded, where it was, and the two most recent search terms.
+                        // For example...
+                        // 1.  Load some backlog to a buffer
+                        // 2.  Search for term with any number of matches
+                        // 3.  Making sure to -type over existing words without first backspacing-,
+                        //     search for another term with only one match
+                        // Expected: Search results found, no freezing
+                        // Actual:   Quassel hangs.  startPos and endPos = same place, start = 0,
+                        //           end = 0, _currentHighlight appears to retain values from the
+                        //           previous search.
+
+                        // Reset _currentHighlight to start, otherwise it'll retain the value from
+                        // previous search, resulting in an index-out-of-bounds error.
+                        _currentHighlight = start;
+                        // Escape from the loop!
+                        break;
+                    }
                     int pivot = (end + start) / 2;
                     QPointF pivotPos = _highlightItems[pivot]->scenePos();
                     if (startPos.y() == endPos.y()) {