From 6fbfb1ab3f26ad672eb24f9b4a0ce1a8eea08298 Mon Sep 17 00:00:00 2001 From: Andrew den Exter Date: Mon, 9 May 2011 14:04:08 +1000 Subject: Don't crash on an invalid replacementStart from an input method. Ensure the cursor position does not exceed the bounds of the current text. Change-Id: If38f7729372562324d11eadd1a976c0c6da91863 Task-number: QTBUG-19054 Reviewed-by: Martin Jones --- src/gui/widgets/qlinecontrol.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/gui/widgets/qlinecontrol.cpp b/src/gui/widgets/qlinecontrol.cpp index 202ea7a..8d4a90e 100644 --- a/src/gui/widgets/qlinecontrol.cpp +++ b/src/gui/widgets/qlinecontrol.cpp @@ -435,6 +435,8 @@ void QLineControl::processInputMethodEvent(QInputMethodEvent *event) c += event->commitString().length() - qMin(-event->replacementStart(), event->replacementLength()); m_cursor += event->replacementStart(); + if (m_cursor < 0) + m_cursor = 0; // insert commit string if (event->replacementLength()) { @@ -447,7 +449,7 @@ void QLineControl::processInputMethodEvent(QInputMethodEvent *event) cursorPositionChanged = true; } - m_cursor = qMin(c, m_text.length()); + m_cursor = qBound(0, c, m_text.length()); for (int i = 0; i < event->attributes().size(); ++i) { const QInputMethodEvent::Attribute &a = event->attributes().at(i); -- cgit v0.12