diff options
author | Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@nokia.com> | 2009-10-29 16:32:57 (GMT) |
---|---|---|
committer | Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@nokia.com> | 2009-10-29 16:32:57 (GMT) |
commit | 4204fdcc04e20eabd19704f2235ba06afa84605e (patch) | |
tree | c078d5bbd9ae783dc6e1c120dbb6dcdb17fd3f5e /tests | |
parent | 263c81d923a1ed90335a3fb05c87330630456073 (diff) | |
download | Qt-4204fdcc04e20eabd19704f2235ba06afa84605e.zip Qt-4204fdcc04e20eabd19704f2235ba06afa84605e.tar.gz Qt-4204fdcc04e20eabd19704f2235ba06afa84605e.tar.bz2 |
Avoid infinite loop when laying out text with unconvertible chars
When the stringToCMap() fails, it can be because it did not have enough
space in the layout, or it can because of other errors. In order to
implement "try-again" processing in a simple way, we had an infinite
loop which assumed that stringToCMap() would always succeed in the
second run (which would be the case if the only possible error was
"not enough space".)
Since there are other possible failures not related to the number of
glyphs, you could easily get into an infinite loop here, e.g. when
laying out text that contains the Byte Order Mark.
The fix changes the implementation to explictly try stringToCMap()
twice at max, and is also how it's implemented in the default
qtextengine.cpp.
Task-number: QTBUG-4680
Reviewed-by: Trond
Conflicts:
src/gui/text/qtextengine_mac.cpp
tests/auto/qtextlayout/tst_qtextlayout.cpp
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/qtextlayout/tst_qtextlayout.cpp | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/tests/auto/qtextlayout/tst_qtextlayout.cpp b/tests/auto/qtextlayout/tst_qtextlayout.cpp index a5fed4e..b02a704 100644 --- a/tests/auto/qtextlayout/tst_qtextlayout.cpp +++ b/tests/auto/qtextlayout/tst_qtextlayout.cpp @@ -119,6 +119,7 @@ private slots: void smallTextLengthWordWrap(); void smallTextLengthWrapAtWordBoundaryOrAnywhere(); void testLineBreakingAllSpaces(); + void lineWidthFromBOM(); private: @@ -1277,5 +1278,18 @@ void tst_QTextLayout::widthOfTabs() QCOMPARE(qRound(engine.width(0, 5)), qRound(engine.boundingBox(0, 5).width)); } +void tst_QTextLayout::lineWidthFromBOM() +{ + const QString string(QChar(0xfeff)); // BYTE ORDER MARK + QTextLayout layout(string); + layout.beginLayout(); + QTextLine line = layout.createLine(); + line.setLineWidth(INT_MAX / 256); + layout.endLayout(); + + // Don't spin into an infinite loop + } + + QTEST_MAIN(tst_QTextLayout) #include "tst_qtextlayout.moc" |