From 5fb34b67b810ca284c216009925f4f38220c4510 Mon Sep 17 00:00:00 2001 From: Maximilian Goldstein Date: Wed, 3 Feb 2021 12:06:33 +0100 Subject: qmllint: Fix segmentation fault Pick-to: 6.0 Change-Id: Ie04ad4221b25628687c2575facf90488b83d21bf Reviewed-by: Fabian Kosmale --- tests/auto/qml/qmllint/data/SegFault.bad.qml | 6 ++++++ tests/auto/qml/qmllint/data/SegFault.qml | 6 ++++++ tests/auto/qml/qmllint/tst_qmllint.cpp | 10 ++++++++++ tools/qmllint/checkidentifiers.cpp | 2 +- 4 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 tests/auto/qml/qmllint/data/SegFault.bad.qml create mode 100644 tests/auto/qml/qmllint/data/SegFault.qml diff --git a/tests/auto/qml/qmllint/data/SegFault.bad.qml b/tests/auto/qml/qmllint/data/SegFault.bad.qml new file mode 100644 index 0000000000..c31777e7c8 --- /dev/null +++ b/tests/auto/qml/qmllint/data/SegFault.bad.qml @@ -0,0 +1,6 @@ +import QtQuick as T +T.Item { + T.Rectangle { + property int length: parent.T.Screen.foobar + } +} diff --git a/tests/auto/qml/qmllint/data/SegFault.qml b/tests/auto/qml/qmllint/data/SegFault.qml new file mode 100644 index 0000000000..c66ad472f1 --- /dev/null +++ b/tests/auto/qml/qmllint/data/SegFault.qml @@ -0,0 +1,6 @@ +import QtQuick as T +T.Item { + T.Rectangle { + property int length: parent.T.Screen.pixelDensity + } +} diff --git a/tests/auto/qml/qmllint/tst_qmllint.cpp b/tests/auto/qml/qmllint/tst_qmllint.cpp index b874d3cc6f..dc84e1c535 100644 --- a/tests/auto/qml/qmllint/tst_qmllint.cpp +++ b/tests/auto/qml/qmllint/tst_qmllint.cpp @@ -277,6 +277,12 @@ void TestQmllint::dirtyQmlCode_data() << QStringLiteral("brokenNamespace.qml") << QString("Warning: type not found in namespace at %1:4:17") << QString(); + // TODO: This fails but currently for the wrong reasons, make sure to add a warning message requirement + // once it does fail properly in order to avoid regressions. + QTest::newRow("segFault (bad)") + << QStringLiteral("SegFault.bad.qml") + << QString() + << QString(); } void TestQmllint::dirtyQmlCode() @@ -338,12 +344,14 @@ void TestQmllint::cleanQmlCode_data() QTest::newRow("jsmoduleimport") << QStringLiteral("jsmoduleimport.qml"); QTest::newRow("overridescript") << QStringLiteral("overridescript.qml"); QTest::newRow("multiExtension") << QStringLiteral("multiExtension.qml"); + QTest::newRow("segFault") << QStringLiteral("SegFault.qml"); } void TestQmllint::cleanQmlCode() { QFETCH(QString, filename); const QString warnings = runQmllint(filename, true); + QEXPECT_FAIL("segFault", "This property exists and should not produce a warning", Abort); QVERIFY2(warnings.isEmpty(), qPrintable(warnings)); } @@ -388,6 +396,8 @@ QString TestQmllint::runQmllint(const QString &fileToLint, bool shouldSucceed, c return runQmllint(fileToLint, [&](QProcess &process) { QVERIFY(process.waitForFinished()); QCOMPARE(process.exitStatus(), QProcess::NormalExit); + + QEXPECT_FAIL("segFault", "This property exists and should not produce a warning", Abort); if (shouldSucceed) QCOMPARE(process.exitCode(), 0); else diff --git a/tools/qmllint/checkidentifiers.cpp b/tools/qmllint/checkidentifiers.cpp index 6400e5db77..60efbc90ca 100644 --- a/tools/qmllint/checkidentifiers.cpp +++ b/tools/qmllint/checkidentifiers.cpp @@ -252,7 +252,7 @@ bool CheckIdentifiers::checkMemberAccess(const QVector &members, if (access.m_name.front().isUpper() && scope->scopeType() == QQmlJSScope::QMLScope) { // may be an attached type const auto it = m_types.find(access.m_name); - if (it != m_types.end() && !(*it)->attachedTypeName().isEmpty()) { + if (it != m_types.end() && *it && !(*it)->attachedTypeName().isEmpty()) { if (const auto attached = (*it)->attachedType()) { scope = attached; continue; -- cgit v1.2.3