Fix crash when QTextLayout::setAdditionalFormats is called with ranges with negative length

That can be reproduced in Qt Creator when deleting code.

Task-number: QTBUG-27140
Change-Id: Ida7177612653f10e5d866bf9a422c71c632f4eb3
Reviewed-by: Simon Hausmann <simon.hausmann@nokia.com>
This commit is contained in:
Olivier Goffart 2012-09-05 20:42:28 +02:00 committed by Qt by Nokia
parent 59774b5d64
commit e28a957035

View File

@ -2723,8 +2723,10 @@ void QTextEngine::resolveAdditionalFormats() const
QVarLengthArray<int, 64> addFormatSortedByStart;
addFormatSortedByStart.reserve(specialData->addFormats.count());
for (int i = 0; i < specialData->addFormats.count(); ++i)
addFormatSortedByStart.append(i);
for (int i = 0; i < specialData->addFormats.count(); ++i) {
if (specialData->addFormats.at(i).length >= 0)
addFormatSortedByStart.append(i);
}
QVarLengthArray<int, 64> addFormatSortedByEnd = addFormatSortedByStart;
qSort(addFormatSortedByStart.begin(), addFormatSortedByStart.end(),
FormatRangeComparatorByStart(specialData->addFormats));