Fix crash in QTextLayout::cursorToX
When 'cursorPos' is out of bounds ([0, lineEnd]), this method crashed. Change-Id: Ia0540ab3afbffb5c598f7b8515263cce3b3928e4 Task-number: QTBUG-40753 Reviewed-by: Dominik Haumann <dhaumann@kde.org> Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@digia.com> Reviewed-by: Konstantin Ritt <ritt.ks@gmail.com>
This commit is contained in:
parent
b9a7cedb6e
commit
eb44767945
@ -2583,7 +2583,7 @@ qreal QTextLine::cursorToX(int *cursorPos, Edge edge) const
|
||||
}
|
||||
|
||||
int lineEnd = line.from + line.length + line.trailingSpaces;
|
||||
int pos = *cursorPos;
|
||||
int pos = qBound(0, *cursorPos, lineEnd);
|
||||
int itm;
|
||||
const QCharAttributes *attributes = eng->attributes();
|
||||
if (!attributes) {
|
||||
|
@ -86,6 +86,7 @@ private slots:
|
||||
void cursorToXForSetColumns();
|
||||
void cursorToXForTrailingSpaces_data();
|
||||
void cursorToXForTrailingSpaces();
|
||||
void cursorToXInvalidInput();
|
||||
void horizontalAlignment_data();
|
||||
void horizontalAlignment();
|
||||
void horizontalAlignmentMultiline_data();
|
||||
@ -674,6 +675,28 @@ void tst_QTextLayout::cursorToXForTrailingSpaces()
|
||||
QCOMPARE(line.cursorToX(6), cursorAt6);
|
||||
}
|
||||
|
||||
void tst_QTextLayout::cursorToXInvalidInput()
|
||||
{
|
||||
QTextLayout layout("aaa", testFont);
|
||||
|
||||
layout.beginLayout();
|
||||
QTextLine line = layout.createLine();
|
||||
line.setLineWidth(5);
|
||||
layout.endLayout();
|
||||
|
||||
int cursorPos;
|
||||
|
||||
cursorPos = 0;
|
||||
layout.lineAt(0).cursorToX(&cursorPos);
|
||||
QCOMPARE(cursorPos, 0);
|
||||
cursorPos = -300;
|
||||
layout.lineAt(0).cursorToX(&cursorPos);
|
||||
QCOMPARE(cursorPos, 0);
|
||||
cursorPos = 300;
|
||||
layout.lineAt(0).cursorToX(&cursorPos);
|
||||
QCOMPARE(cursorPos, 3);
|
||||
}
|
||||
|
||||
void tst_QTextLayout::horizontalAlignment_data()
|
||||
{
|
||||
qreal width = TESTFONT_SIZE * 4;
|
||||
|
Loading…
x
Reference in New Issue
Block a user