diff options
author | Volker Hilsheimer <volker.hilsheimer@qt.io> | 2020-03-11 19:15:10 +0100 |
---|---|---|
committer | Volker Hilsheimer <volker.hilsheimer@qt.io> | 2020-03-17 06:15:55 +0100 |
commit | ffbf5ae11d8df95ec2bb0ed7c3c32be9a45eac0c (patch) | |
tree | 11ab30f9ab52e9c2e98a76b8883eafb5f3ebc804 /src/widgets/kernel | |
parent | ddd0919bcf5bb630efce755cc21f364e36e23fca (diff) |
Fix potential out-of-bounds or nullptr access
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ø <tor.arne.vestbo@qt.io>
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Diffstat (limited to 'src/widgets/kernel')
-rw-r--r-- | src/widgets/kernel/qtooltip.cpp | 8 |
1 files changed, 4 insertions, 4 deletions
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()); |