QHighDpiScaling: fix potential null pointer dereference

It's not guaranteed that QPlatformScreen::screen should always return a
valid pointer. Furthermore, you can run into this situation with, for
example, two screens setup.

Task-number: QTBUG-53022
Change-Id: Ic23bb2c30b1245f98a793a44cc5e0b39f9afac4b
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
bb10
Vitaly Fanaskov 2019-10-25 14:47:15 +02:00
parent 75f791419c
commit ed20f32098
1 changed files with 2 additions and 1 deletions

View File

@ -657,7 +657,8 @@ qreal QHighDpiScaling::screenSubfactor(const QPlatformScreen *screen)
// Check if there is a factor set on the screen object or associated
// with the screen name. These are mutually exclusive, so checking
// order is not significant.
QVariant byIndex = screen->screen()->property(scaleFactorProperty);
auto qScreen = screen->screen();
auto byIndex = qScreen ? qScreen->property(scaleFactorProperty) : QVariant();
auto byNameIt = qNamedScreenScaleFactors()->constFind(screen->name());
if (byIndex.isValid()) {
screenPropertyUsed = true;