Fix UB in QGraphicsScene::wheelEvent()

operator--() would iterate before begin() if the
list was empty. This is UB, and will crash in Qt 6,
where begin()/end() can return an iterator pointing
to a nullptr if the list is empty.

Change-Id: I39c3a8ebb09fcad75d42019b02426ac5ac05eed9
Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
bb10
Lars Knoll 2020-05-29 10:24:31 +02:00
parent d4ff606941
commit f98fe1ba41
1 changed files with 2 additions and 1 deletions

View File

@ -4101,7 +4101,8 @@ void QGraphicsScene::wheelEvent(QGraphicsSceneWheelEvent *wheelEvent)
// Remove all popups after the one found, or all or them if no popup is under the mouse.
// Then continue with the event.
QList<QGraphicsWidget *>::const_iterator iter = d->popupWidgets.constEnd();
while (--iter >= d->popupWidgets.constBegin() && !wheelCandidates.isEmpty()) {
while (iter > d->popupWidgets.constBegin() && !wheelCandidates.isEmpty()) {
--iter;
if (wheelCandidates.first() == *iter || (*iter)->isAncestorOf(wheelCandidates.first()))
break;
d->removePopup(*iter);