Fix v4 crash when accessing invalid attached property

Task-number: QTBUG-21883
Change-Id: Ic14a5d494890fc1bc322c660b97f657d640f2ff8
Reviewed-by: Kent Hansen <kent.hansen@nokia.com>
This commit is contained in:
Aaron Kennedy 2011-11-09 11:09:27 +00:00 committed by Qt by Nokia
parent 0c5f918550
commit 1c93b9ce6e
3 changed files with 21 additions and 1 deletions

View File

@ -311,7 +311,8 @@ void QV4CompilerPrivate::visitName(IR::Name *e)
attached.output = currentReg; attached.output = currentReg;
attached.reg = currentReg; attached.reg = currentReg;
attached.exceptionId = exceptionId(e->line, e->column); attached.exceptionId = exceptionId(e->line, e->column);
Q_ASSERT(e->declarativeType->attachedPropertiesId() != -1); if (e->declarativeType->attachedPropertiesId() == -1)
discard();
attached.id = e->declarativeType->attachedPropertiesId(); attached.id = e->declarativeType->attachedPropertiesId();
gen(attached); gen(attached);
} break; } break;

View File

@ -0,0 +1,5 @@
import Qt.v4 1.0
Result {
property Result dummy: Result
}

View File

@ -77,6 +77,7 @@ private slots:
void qtscript_data(); void qtscript_data();
void nestedObjectAccess(); void nestedObjectAccess();
void subscriptionsInConditionalExpressions(); void subscriptionsInConditionalExpressions();
void qtbug_21883();
private: private:
QDeclarativeEngine engine; QDeclarativeEngine engine;
@ -239,6 +240,19 @@ void tst_v4::subscriptionsInConditionalExpressions()
delete o; 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) QTEST_MAIN(tst_v4)
#include "tst_v4.moc" #include "tst_v4.moc"