Fixed possible infinite loop when searching in text editor

Caused by uninitialized variable and failure to check for the case where
nothing is found.

Done-with: mae
This commit is contained in:
Thorbjørn Lindeijer
2010-04-16 12:26:31 +02:00
parent c57e2eaff4
commit 2128669052

View File

@@ -38,11 +38,13 @@ using namespace Find;
BaseTextFind::BaseTextFind(QTextEdit *editor)
: m_editor(editor), m_incrementalStartPos(-1)
, m_findScopeVerticalBlockSelection(0)
{
}
BaseTextFind::BaseTextFind(QPlainTextEdit *editor)
: m_plaineditor(editor), m_incrementalStartPos(-1)
, m_findScopeVerticalBlockSelection(0)
{
}
@@ -280,6 +282,9 @@ bool BaseTextFind::find(const QString &txt,
QTextCursor BaseTextFind::findOne(const QRegExp &expr, const QTextCursor &from, QTextDocument::FindFlags options) const
{
QTextCursor candidate = document()->find(expr, from, options);
if (candidate.isNull())
return candidate;
if (!m_findScopeVerticalBlockSelection)
return candidate;
forever {
@@ -311,7 +316,7 @@ void BaseTextFind::defineFindScope()
if (cursor.hasSelection() && cursor.block() != cursor.document()->findBlock(cursor.anchor())) {
m_findScopeStart = QTextCursor(document()->docHandle(), qMax(0, cursor.selectionStart()-1));
m_findScopeEnd = QTextCursor(document()->docHandle(), cursor.selectionEnd());
m_findScopeVerticalBlockSelection = false;
m_findScopeVerticalBlockSelection = 0;
int verticalBlockSelection = 0;
if (m_plaineditor && m_plaineditor->metaObject()->indexOfProperty("verticalBlockSelection") >= 0)