diff options
author | Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io> | 2024-01-29 11:44:25 +0100 |
---|---|---|
committer | Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io> | 2024-01-29 17:02:36 +0000 |
commit | be6c651be4ccfa4f70009bcbb51bef39638e0fba (patch) | |
tree | c16ae43efb9089e67247641b550094a915c5aed1 /tests/auto/gui | |
parent | f757662486f2b44cc7cab702c7e89edbc594f4ff (diff) |
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:
991c056438b311566bc4ea543af0f33dfd5dffbb.
49a63d375972079ae3000c8b7d512d58d4de32bb fixed 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>
Diffstat (limited to 'tests/auto/gui')
-rw-r--r-- | tests/auto/gui/text/qtextlayout/tst_qtextlayout.cpp | 26 |
1 files changed, 19 insertions, 7 deletions
diff --git a/tests/auto/gui/text/qtextlayout/tst_qtextlayout.cpp b/tests/auto/gui/text/qtextlayout/tst_qtextlayout.cpp index bea2556e68..a0baa43cbc 100644 --- a/tests/auto/gui/text/qtextlayout/tst_qtextlayout.cpp +++ b/tests/auto/gui/text/qtextlayout/tst_qtextlayout.cpp @@ -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) |