Fix infinite loop in QTextLayout with setNumColumns()
If the line width is negative, then we might exit the layout loop before consuming any text, and thus the loop will never finish. This is a side effect of a change for maximumWidth:bb10991c056438.49a63d3759fixed this issue for QTextLayout::setFixedSize(), but I forgot to do the same in the overload of QTextLayout::setNumColumns() which includes an alignment width and therefore sets the line width in addition to the column count. Basically, we just make sure the line width is never negative so that the width > line.width condition also means the width > 0. Pick-to: 6.5 6.6 6.7 Fixes: QTBUG-115459 Change-Id: If904bfc64cd74e819a0864db55fa9555073d0781 Reviewed-by: Vladimir Belyavsky <belyavskyv@gmail.com> Reviewed-by: Lars Knoll <lars@knoll.priv.no>
parent
f757662486
commit
be6c651be4
|
|
@ -1652,7 +1652,7 @@ void QTextLine::setNumColumns(int numColumns)
|
|||
void QTextLine::setNumColumns(int numColumns, qreal alignmentWidth)
|
||||
{
|
||||
QScriptLine &line = eng->lines[index];
|
||||
line.width = QFixed::fromReal(alignmentWidth);
|
||||
line.width = QFixed::fromReal(qBound(0.0, alignmentWidth, qreal(QFIXED_MAX)));
|
||||
line.length = 0;
|
||||
line.textWidth = 0;
|
||||
layout_helper(numColumns);
|
||||
|
|
|
|||
|
|
@ -2737,13 +2737,25 @@ void tst_QTextLayout::min_maximumWidth()
|
|||
|
||||
void tst_QTextLayout::negativeLineWidth()
|
||||
{
|
||||
QTextLayout layout;
|
||||
layout.setText("Foo bar");
|
||||
layout.beginLayout();
|
||||
QTextLine line = layout.createLine();
|
||||
line.setLineWidth(-1);
|
||||
QVERIFY(line.textLength() > 0);
|
||||
layout.endLayout();
|
||||
{
|
||||
QTextLayout layout;
|
||||
layout.setText("Foo bar");
|
||||
layout.beginLayout();
|
||||
QTextLine line = layout.createLine();
|
||||
line.setLineWidth(-1);
|
||||
QVERIFY(line.textLength() > 0);
|
||||
layout.endLayout();
|
||||
}
|
||||
|
||||
{
|
||||
QTextLayout layout;
|
||||
layout.setText("Foo bar");
|
||||
layout.beginLayout();
|
||||
QTextLine line = layout.createLine();
|
||||
line.setNumColumns(2, -1);
|
||||
QVERIFY(line.textLength() > 0);
|
||||
layout.endLayout();
|
||||
}
|
||||
}
|
||||
|
||||
QTEST_MAIN(tst_QTextLayout)
|
||||
|
|
|
|||
Loading…
Reference in New Issue