Fix crash in QAccessibleTextWidget::attributes()
Task-number: QTBUG-44006 Change-Id: I79d7d84206a3e4abcd49c7c6e5e91b7c9c753dd6 Reviewed-by: Frederik Gladhorn <frederik.gladhorn@theqtcompany.com>
This commit is contained in:
parent
bcfacd4b6f
commit
395f0181ee
@ -727,19 +727,31 @@ QString QAccessibleTextWidget::attributes(int offset, int *startOffset, int *end
|
||||
int blockEnd = blockStart + block.length();
|
||||
|
||||
QTextBlock::iterator iter = block.begin();
|
||||
while (!iter.fragment().contains(offset))
|
||||
int lastFragmentIndex = blockStart;
|
||||
while (!iter.atEnd()) {
|
||||
QTextFragment f = iter.fragment();
|
||||
if (f.contains(offset))
|
||||
break;
|
||||
lastFragmentIndex = f.position() + f.length();
|
||||
++iter;
|
||||
}
|
||||
|
||||
QTextFragment fragment = iter.fragment();
|
||||
int pos = fragment.position();
|
||||
|
||||
// text block and fragment may overlap, use the smallest common range
|
||||
*startOffset = qMax(pos, blockStart);
|
||||
QTextCharFormat charFormat;
|
||||
if (!iter.atEnd()) {
|
||||
QTextFragment fragment = iter.fragment();
|
||||
charFormat = fragment.charFormat();
|
||||
int pos = fragment.position();
|
||||
// text block and fragment may overlap, use the smallest common range
|
||||
*startOffset = qMax(pos, blockStart);
|
||||
*endOffset = qMin(pos + fragment.length(), blockEnd);
|
||||
} else {
|
||||
charFormat = block.charFormat();
|
||||
*startOffset = lastFragmentIndex;
|
||||
*endOffset = blockEnd;
|
||||
}
|
||||
Q_ASSERT(*startOffset <= offset);
|
||||
*endOffset = qMin(pos + fragment.length(), blockEnd);
|
||||
Q_ASSERT(*endOffset >= offset);
|
||||
|
||||
QTextCharFormat charFormat = fragment.charFormat();
|
||||
QTextBlockFormat blockFormat = cursor.blockFormat();
|
||||
|
||||
QMap<QByteArray, QString> attrs;
|
||||
|
@ -733,6 +733,7 @@ void tst_QAccessibility::textAttributes_data()
|
||||
QTest::newRow("left right left aligned 10") << leftRightLeftAligned << 10 << 10 << 11 << rightAlign;
|
||||
QTest::newRow("left right left aligned 11") << leftRightLeftAligned << 11 << 11 << 15 << bold;
|
||||
QTest::newRow("left right left aligned 15") << leftRightLeftAligned << 15 << 11 << 15 << bold;
|
||||
QTest::newRow("empty with no fragments") << QString::fromLatin1("\n\n\n\n") << 0 << 0 << 1 << defaults;
|
||||
}
|
||||
|
||||
void tst_QAccessibility::textAttributes()
|
||||
|
Loading…
Reference in New Issue
Block a user