summaryrefslogtreecommitdiffstats
path: root/tests/auto
diff options
context:
space:
mode:
authorEskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@digia.com>2012-12-11 14:07:16 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-01-03 16:15:37 +0100
commit248ccb2889aec76cb99c25998534c97b48b98c4a (patch)
tree245b07bbef790f3f87fdcd7406dfe1efb5f76f59 /tests/auto
parent4319f698c893683c6a031e41272b85cfb25ac931 (diff)
Fix possible crash in QTextDocument
With trailing spaces in some cases, we would not get the "no justification at end of paragraph" special case, and continue in the code, getting the unexpected case where line_length becomes < 0 which would lead to memory corruption because we were writing outside our buffers. I added an assert to catch this type of bug earlier, and I added the trailing spaces to the test for the end of the paragraph. The test case added is one example which would crash. Task-number: QTBUG-27354 Change-Id: Id720a6fa55dbc709ce04dd5321e55687bf960d75 Reviewed-by: Lars Knoll <lars.knoll@digia.com>
Diffstat (limited to 'tests/auto')
-rw-r--r--tests/auto/gui/text/qtextdocument/tst_qtextdocument.cpp25
1 files changed, 25 insertions, 0 deletions
diff --git a/tests/auto/gui/text/qtextdocument/tst_qtextdocument.cpp b/tests/auto/gui/text/qtextdocument/tst_qtextdocument.cpp
index cf3265d446..966102033c 100644
--- a/tests/auto/gui/text/qtextdocument/tst_qtextdocument.cpp
+++ b/tests/auto/gui/text/qtextdocument/tst_qtextdocument.cpp
@@ -184,6 +184,8 @@ private slots:
void htmlExportImportBlockCount();
+ void QTBUG27354_spaceAndSoftSpace();
+
private:
void backgroundImage_checkExpectedHtml(const QTextDocument &doc);
@@ -2900,5 +2902,28 @@ void tst_QTextDocument::htmlExportImportBlockCount()
QCOMPARE(document.blockCount(), 5);
}
+void tst_QTextDocument::QTBUG27354_spaceAndSoftSpace()
+{
+ QTextDocument document;
+ {
+ QTextCursor cursor(&document);
+ QTextBlockFormat blockFormat;
+ blockFormat.setAlignment(Qt::AlignJustify);
+ cursor.mergeBlockFormat(blockFormat);
+ cursor.insertText("ac");
+ cursor.insertBlock();
+ cursor.insertText(" ");
+ cursor.insertText(QChar(0x2028));
+ }
+
+ // Trigger justification of text
+ QImage image(1000, 1000, QImage::Format_ARGB32);
+ image.fill(0);
+ {
+ QPainter p(&image);
+ document.drawContents(&p, image.rect());
+ }
+}
+
QTEST_MAIN(tst_QTextDocument)
#include "tst_qtextdocument.moc"