From ffbf5ae11d8df95ec2bb0ed7c3c32be9a45eac0c Mon Sep 17 00:00:00 2001 From: Volker Hilsheimer Date: Wed, 11 Mar 2020 19:15:10 +0100 Subject: Fix potential out-of-bounds or nullptr access MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This ammends change baed8534bc1dac36a9d0ef4240fc14398076a192, which might have introduced a hard to reproduce segmentation fault when the screen number is out of bounds, or when the QScreen object doesn't return a valid pointer for QScreen::handle. As the issue doesn't reliably reproduce, this is a speculative fix that adds bounds and nullptr checking. Change-Id: I0cec0a344e80159ee1723d840f207267a608cef4 Fixes: QTBUG-82807 Reviewed-by: Tor Arne Vestbø Reviewed-by: Volker Hilsheimer --- src/widgets/kernel/qtooltip.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/widgets/kernel/qtooltip.cpp') diff --git a/src/widgets/kernel/qtooltip.cpp b/src/widgets/kernel/qtooltip.cpp index 1ec3612457..45835a2043 100644 --- a/src/widgets/kernel/qtooltip.cpp +++ b/src/widgets/kernel/qtooltip.cpp @@ -402,10 +402,10 @@ void QTipLabel::placeTip(const QPoint &pos, QWidget *w) #endif //QT_NO_STYLE_STYLESHEET QPoint p = pos; - int screenNumber = getTipScreen(pos, w); - QScreen *screen = QGuiApplication::screens().at(screenNumber); - if (screen) { - const QPlatformScreen *platformScreen = screen->handle(); + const QScreen *screen = QGuiApplication::screens().value(getTipScreen(pos, w), + QGuiApplication::primaryScreen()); + // a QScreen's handle *should* never be null, so this is a bit paranoid + if (const QPlatformScreen *platformScreen = screen ? screen->handle() : nullptr) { const QSize cursorSize = QHighDpi::fromNativePixels(platformScreen->cursor()->size(), platformScreen); QPoint offset(2, cursorSize.height()); -- cgit v1.2.3