Fix crash when loading invalid QML with behavior on invalid group property
authorSimon Hausmann <simon.hausmann@digia.com>
Fri, 1 Aug 2014 08:13:06 +0000 (10:13 +0200)
committerSérgio Martins <sergio.martins@kdab.com>
Fri, 8 Aug 2014 07:12:09 +0000 (09:12 +0200)
Behaviors require the creation of a meta-object. However when trying to
create a behavior on a non-existent group property, we don't have a
base meta-object to base the "new" meta-object on, therefore this patch
adds a null pointer check.

The error in the QML file itself will be caught later on. The added test
ensures that as well as that it doesn't crash of course.

Change-Id: If73116053464e7e69b02ef59e8387060835083c8
Task-number: QTBUG-40369
Reviewed-by: Sérgio Martins <sergio.martins@kdab.com>
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
src/qml/compiler/qqmltypecompiler.cpp
tests/auto/qml/qqmllanguage/data/nonexistantProperty.8.errors.txt [new file with mode: 0644]
tests/auto/qml/qqmllanguage/data/nonexistantProperty.8.qml [new file with mode: 0644]
tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp

index dacaa14..f5cb5db 100644 (file)
@@ -541,12 +541,14 @@ bool QQmlPropertyCacheCreator::buildMetaObjectRecursively(int objectIndex, int r
         Q_ASSERT(baseTypeCache);
     }
 
-    if (needVMEMetaObject) {
-        if (!createMetaObject(objectIndex, obj, baseTypeCache))
-            return false;
-    } else if (baseTypeCache) {
-        propertyCaches[objectIndex] = baseTypeCache;
-        baseTypeCache->addref();
+    if (baseTypeCache) {
+        if (needVMEMetaObject) {
+            if (!createMetaObject(objectIndex, obj, baseTypeCache))
+                return false;
+        } else {
+            propertyCaches[objectIndex] = baseTypeCache;
+            baseTypeCache->addref();
+        }
     }
 
     if (propertyCaches.at(objectIndex)) {
diff --git a/tests/auto/qml/qqmllanguage/data/nonexistantProperty.8.errors.txt b/tests/auto/qml/qqmllanguage/data/nonexistantProperty.8.errors.txt
new file mode 100644 (file)
index 0000000..b60b59b
--- /dev/null
@@ -0,0 +1 @@
+4:24:Cannot assign to non-existent property "root"
diff --git a/tests/auto/qml/qqmllanguage/data/nonexistantProperty.8.qml b/tests/auto/qml/qqmllanguage/data/nonexistantProperty.8.qml
new file mode 100644 (file)
index 0000000..86c5f3b
--- /dev/null
@@ -0,0 +1,5 @@
+import QtQuick 2.0
+Item {
+    id: root
+    NumberAnimation on root.opacity { duration: 1000 }
+}
index 95d6eb9..7976987 100644 (file)
@@ -347,6 +347,7 @@ void tst_qqmllanguage::errors_data()
     QTest::newRow("nonexistantProperty.5") << "nonexistantProperty.5.qml" << "nonexistantProperty.5.errors.txt" << false;
     QTest::newRow("nonexistantProperty.6") << "nonexistantProperty.6.qml" << "nonexistantProperty.6.errors.txt" << false;
     QTest::newRow("nonexistantProperty.7") << "nonexistantProperty.7.qml" << "nonexistantProperty.7.errors.txt" << false;
+    QTest::newRow("nonexistantProperty.8") << "nonexistantProperty.8.qml" << "nonexistantProperty.8.errors.txt" << false;
 
     QTest::newRow("wrongType (string for int)") << "wrongType.1.qml" << "wrongType.1.errors.txt" << false;
     QTest::newRow("wrongType (int for bool)") << "wrongType.2.qml" << "wrongType.2.errors.txt" << false;