Fix subtle issue in tst_qtablewidget

Fixed UB when QList::begin() iterator is used after a call to
QList::remove(). As QList is now effectively double-ended container,
there is no guarantee on iterator validity upon erasure

Task-number: QTBUG-84320
Change-Id: I27793f131e8e23a41ac6c2c1db0bdc61ee58891f
Reviewed-by: Sona Kurazyan <sona.kurazyan@qt.io>
bb10
Andrei Golubev 2020-08-27 16:05:43 +02:00
parent 7883bf7304
commit 4b2f5371d9
1 changed files with 1 additions and 1 deletions

View File

@ -589,7 +589,7 @@ void QTableModel::ensureSorted(int column, Qt::SortOrder order,
int oldRow = sorting.at(i).second;
QTableWidgetItem *item = colItems.at(oldRow);
colItems.remove(oldRow);
vit = sortedInsertionIterator(vit, colItems.end(), order, item);
vit = sortedInsertionIterator(colItems.begin(), colItems.end(), order, item);
int newRow = qMax((int)(vit - colItems.begin()), 0);
if ((newRow < oldRow) && !(*item < *colItems.at(oldRow - 1)) && !(*colItems.at(oldRow - 1) < *item))
newRow = oldRow;