Fix potential out-of-bounds or nullptr access

This ammends change baed8534bc, 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>
This commit is contained in:
Volker Hilsheimer 2020-03-11 19:15:10 +01:00
parent ddd0919bcf
commit ffbf5ae11d

View File

@ -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());