From feb076d23ed832b21bf415032146570f4afb25d5 Mon Sep 17 00:00:00 2001 From: Shawn Rutledge Date: Fri, 4 Jun 2021 13:17:40 +0200 Subject: Check for null pointer in QQuickPointerHandler::approveGrabTransition() Found by static analysis: https://testresults.qt.io/codechecker/daily_diffs/qtdeclarative/dev/qtdeclarative-dev-20210604-1285b67a11/qquickpointerhandler.cpp_51058486.html#reportHash=9b76a76200c3a2eceb0e115776dda98b Amends b09ce7dcd8ecf24ef23da8197a64e3fced3fc894 Change-Id: I4c35f648be9513e5e237d9b8d4e502e40e9f8a76 Reviewed-by: Fabian Kosmale (cherry picked from commit 63b1f379b710c510f00311e03641aa65e72aaf34) Reviewed-by: Qt CI Bot --- src/quick/handlers/qquickpointerhandler.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/quick/handlers/qquickpointerhandler.cpp b/src/quick/handlers/qquickpointerhandler.cpp index b33b95eec1..12b064a79b 100644 --- a/src/quick/handlers/qquickpointerhandler.cpp +++ b/src/quick/handlers/qquickpointerhandler.cpp @@ -353,10 +353,13 @@ bool QQuickPointerHandler::approveGrabTransition(QPointerEvent *event, const QEv } else if ((d->grabPermissions & CanTakeOverFromItems)) { allowed = true; QQuickItem * existingItemGrabber = qobject_cast(event->exclusiveGrabber(point)); - auto da = QQuickItemPrivate::get(parentItem())->deliveryAgentPrivate(); + auto da = parentItem() ? QQuickItemPrivate::get(parentItem())->deliveryAgentPrivate() + : QQuickDeliveryAgentPrivate::currentEventDeliveryAgent ? static_cast( + QQuickDeliveryAgentPrivate::get(QQuickDeliveryAgentPrivate::currentEventDeliveryAgent)) : nullptr; + const bool isTouchMouse = (da && da->isDeliveringTouchAsMouse()); if (existingItemGrabber && ((existingItemGrabber->keepMouseGrab() && - (QQuickWindowPrivate::isMouseEvent(event) || da->isDeliveringTouchAsMouse())) || + (QQuickWindowPrivate::isMouseEvent(event) || isTouchMouse)) || (existingItemGrabber->keepTouchGrab() && QQuickWindowPrivate::isTouchEvent(event)))) { allowed = false; // If the handler wants to steal the exclusive grab from an Item, the Item can usually veto @@ -369,7 +372,7 @@ bool QQuickPointerHandler::approveGrabTransition(QPointerEvent *event, const QEv if (existingItemGrabber->keepMouseGrab() && existingItemGrabber->filtersChildMouseEvents() && existingItemGrabber->isAncestorOf(parentItem())) { Q_ASSERT(da); - if (da->isDeliveringTouchAsMouse() && point.id() == da->touchMouseId) { + if (isTouchMouse && point.id() == da->touchMouseId) { qCDebug(lcPointerHandlerGrab) << this << "steals touchpoint" << point.id() << "despite parent touch-mouse grabber with keepMouseGrab=true" << existingItemGrabber; allowed = true; -- cgit v1.2.3