Fix v4 crash when accessing invalid attached property
authorAaron Kennedy <aaron.kennedy@nokia.com>
Wed, 9 Nov 2011 11:09:27 +0000 (11:09 +0000)
committerQt by Nokia <qt-info@nokia.com>
Wed, 9 Nov 2011 12:13:36 +0000 (13:13 +0100)
Task-number: QTBUG-21883
Change-Id: Ic14a5d494890fc1bc322c660b97f657d640f2ff8
Reviewed-by: Kent Hansen <kent.hansen@nokia.com>

src/declarative/qml/v4/qv4compiler.cpp
tests/auto/declarative/v4/data/qtbug_21883.qml [new file with mode: 0644]
tests/auto/declarative/v4/tst_v4.cpp

index 857bceb..31a0a1e 100644 (file)
@@ -311,7 +311,8 @@ void QV4CompilerPrivate::visitName(IR::Name *e)
         attached.output = currentReg;
         attached.reg = currentReg;
         attached.exceptionId = exceptionId(e->line, e->column);
-        Q_ASSERT(e->declarativeType->attachedPropertiesId() != -1);
+        if (e->declarativeType->attachedPropertiesId() == -1)
+            discard();
         attached.id = e->declarativeType->attachedPropertiesId();
         gen(attached);
     } break;
diff --git a/tests/auto/declarative/v4/data/qtbug_21883.qml b/tests/auto/declarative/v4/data/qtbug_21883.qml
new file mode 100644 (file)
index 0000000..a51f97c
--- /dev/null
@@ -0,0 +1,5 @@
+import Qt.v4 1.0
+
+Result {
+    property Result dummy: Result
+}
index 0b6b2c2..20d739f 100644 (file)
@@ -77,6 +77,7 @@ private slots:
     void qtscript_data();
     void nestedObjectAccess();
     void subscriptionsInConditionalExpressions();
+    void qtbug_21883();
 
 private:
     QDeclarativeEngine engine;
@@ -239,6 +240,19 @@ void tst_v4::subscriptionsInConditionalExpressions()
     delete o;
 }
 
+// Crash test
+void tst_v4::qtbug_21883()
+{
+    QDeclarativeComponent component(&engine, TEST_FILE("qtbug_21883.qml"));
+
+    QString warning = component.url().toString() + ":4: Unable to assign null to ResultObject*";
+    QTest::ignoreMessage(QtWarningMsg, warning.toLatin1().constData());
+
+    QObject *o = component.create();
+    QVERIFY(o != 0);
+    delete o;
+}
+
 QTEST_MAIN(tst_v4)
 
 #include "tst_v4.moc"