From 5d7f1133205d14002463456c26a97f8ba17d69b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Morten=20Johan=20S=C3=B8rvig?= Date: Wed, 7 Aug 2019 13:15:51 +0200 Subject: Add nullptr guard to QHighDScaling::scaleAndOrigin(QPlatformScreen *) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Commit b6ded193 added an unconditional dereference of the platformScreen pointer, for calls where nativePostion is non-nullptr. Change-Id: I4a6fbbd0337f91d4fcb76c17b4dc60e1b9ad10ed Reviewed-by: Tor Arne Vestbø --- .../gui/kernel/qhighdpiscaling/tst_qhighdpiscaling.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'tests/auto/gui/kernel') diff --git a/tests/auto/gui/kernel/qhighdpiscaling/tst_qhighdpiscaling.cpp b/tests/auto/gui/kernel/qhighdpiscaling/tst_qhighdpiscaling.cpp index 969b2351ec..ec80c2d02c 100644 --- a/tests/auto/gui/kernel/qhighdpiscaling/tst_qhighdpiscaling.cpp +++ b/tests/auto/gui/kernel/qhighdpiscaling/tst_qhighdpiscaling.cpp @@ -36,6 +36,7 @@ class tst_QHighDpiScaling: public QObject Q_OBJECT private slots: + void factor(); void scale(); }; @@ -50,6 +51,23 @@ public: QImage::Format format() const override { return QImage::Format_ARGB32_Premultiplied; } }; +void tst_QHighDpiScaling::factor() +{ + QHighDpiScaling::setGlobalFactor(2); + + // Verfy that QHighDpiScaling::factor() does not crash on nullptr contexts. + QPoint fakeNativePosition = QPoint(5, 5); + QPlatformScreen *screenContext = nullptr; + QVERIFY(QHighDpiScaling::factor(screenContext) >= 0); + QVERIFY(QHighDpiScaling::factor(screenContext, &fakeNativePosition) >= 0); + QPlatformScreen *platformScreenContext = nullptr; + QVERIFY(QHighDpiScaling::factor(platformScreenContext) >= 0); + QVERIFY(QHighDpiScaling::factor(platformScreenContext, &fakeNativePosition) >= 0); + QWindow *windowContext = nullptr; + QVERIFY(QHighDpiScaling::factor(windowContext) >= 0); + QVERIFY(QHighDpiScaling::factor(windowContext, &fakeNativePosition) >= 0); +} + // QTBUG-77255: Test some scaling overloads void tst_QHighDpiScaling::scale() { -- cgit v1.2.3