From f8aac9601dcd3c86b810479c022d07c7e1eb2b86 Mon Sep 17 00:00:00 2001 From: Eskil Abrahamsen Blomfeldt Date: Fri, 13 Jan 2023 14:04:20 +0100 Subject: compositor: Fix crash when raising shell surface item This was introduced by d89c8920f3b82dd2098971b5a66c4b9c75da5af0. The raise() function would search for a suitable surface, but failing to find one, it would search past the end of the childItems list and cause memory corruption. [ChangeLog][QtWaylandCompositor] Fixed an issue where the compositor would sometimes crash if a shell surface item was brought to front. Fixes: QTBUG-109051 Change-Id: I2249f0881b90fc05b5f0292cd35c6524db4663c5 Reviewed-by: Paul Olav Tvete (cherry picked from commit 0088b09e79da01534a703f69dbccbd721e7594d8) Reviewed-by: Qt Cherry-pick Bot --- src/compositor/extensions/qwaylandquickshellsurfaceitem.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/compositor/extensions/qwaylandquickshellsurfaceitem.cpp b/src/compositor/extensions/qwaylandquickshellsurfaceitem.cpp index 28806f622..dfbe41490 100644 --- a/src/compositor/extensions/qwaylandquickshellsurfaceitem.cpp +++ b/src/compositor/extensions/qwaylandquickshellsurfaceitem.cpp @@ -319,11 +319,14 @@ void QWaylandQuickShellSurfaceItemPrivate::raise() return (!staysOnTop && surf->staysOnTop()) || (staysOnBottom && !surf->staysOnBottom()); return true; // ignore any other Quick items that may be there }; - while (skip(*it)) + auto end = parent->childItems().crend(); + while (it != end && skip(*it)) ++it; - QQuickItem *top = *it; - if (moveItem != top) - moveItem->stackAfter(top); + if (it != end) { + QQuickItem *top = *it; + if (moveItem != top) + moveItem->stackAfter(top); + } } /* -- cgit v1.2.3