Skip to content

Commit

Permalink
Fix UB in QGraphicsScene::wheelEvent()
Browse files Browse the repository at this point in the history
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 <[email protected]>
Reviewed-by: Mårten Nordheim <[email protected]>
  • Loading branch information
laknoll committed May 29, 2020
1 parent d4ff606 commit f98fe1b
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/widgets/graphicsview/qgraphicsscene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit f98fe1b

Please sign in to comment.