From a3a7553dd52a90a95cfeef80d36b1fd671b335b2 Mon Sep 17 00:00:00 2001 From: Nicolas Arnaud-Cormos Date: Tue, 15 May 2012 19:02:42 +0200 Subject: Fix crash when using aliases and variants Right now, the parser crash when using id.variant.property for an alias. The current patch fix the crash, and it displays an error message in the console now (like QtQuick 2). Task-number: QTBUG-25341 Change-Id: I5e2c13f487655fd2b90129c5693f5daf3f77984b Reviewed-by: Matthew Vogt --- src/declarative/qml/qdeclarativevaluetype_p.h | 2 +- .../qdeclarativelanguage/data/invalidAlias.11.errors.txt | 1 + .../declarative/qdeclarativelanguage/data/invalidAlias.11.qml | 9 +++++++++ .../qdeclarativelanguage/tst_qdeclarativelanguage.cpp | 1 + 4 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 tests/auto/declarative/qdeclarativelanguage/data/invalidAlias.11.errors.txt create mode 100644 tests/auto/declarative/qdeclarativelanguage/data/invalidAlias.11.qml diff --git a/src/declarative/qml/qdeclarativevaluetype_p.h b/src/declarative/qml/qdeclarativevaluetype_p.h index 5c2cda7..6666532 100644 --- a/src/declarative/qml/qdeclarativevaluetype_p.h +++ b/src/declarative/qml/qdeclarativevaluetype_p.h @@ -92,7 +92,7 @@ public: static void registerValueTypes(); QDeclarativeValueType *operator[](int idx) const { - if (idx >= (int)QVariant::UserType) return 0; + if (idx < 0 || idx >= (int)QVariant::UserType) return 0; else return valueTypes[idx]; } diff --git a/tests/auto/declarative/qdeclarativelanguage/data/invalidAlias.11.errors.txt b/tests/auto/declarative/qdeclarativelanguage/data/invalidAlias.11.errors.txt new file mode 100644 index 0000000..b94e92c --- /dev/null +++ b/tests/auto/declarative/qdeclarativelanguage/data/invalidAlias.11.errors.txt @@ -0,0 +1 @@ +8:25:Invalid alias location diff --git a/tests/auto/declarative/qdeclarativelanguage/data/invalidAlias.11.qml b/tests/auto/declarative/qdeclarativelanguage/data/invalidAlias.11.qml new file mode 100644 index 0000000..25efe28 --- /dev/null +++ b/tests/auto/declarative/qdeclarativelanguage/data/invalidAlias.11.qml @@ -0,0 +1,9 @@ +import QtQuick 1.0 + +QtObject { + id: main + property variant v: Text{ + text: "variant text" + } + property alias foo: main.v.text +} diff --git a/tests/auto/declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp b/tests/auto/declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp index bfc0a5f..c8f26d5 100644 --- a/tests/auto/declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp +++ b/tests/auto/declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp @@ -385,6 +385,7 @@ void tst_qdeclarativelanguage::errors_data() QTest::newRow("invalidAlias.8") << "invalidAlias.8.qml" << "invalidAlias.8.errors.txt" << false; QTest::newRow("invalidAlias.9") << "invalidAlias.9.qml" << "invalidAlias.9.errors.txt" << false; QTest::newRow("invalidAlias.10") << "invalidAlias.10.qml" << "invalidAlias.10.errors.txt" << false; + QTest::newRow("invalidAlias.11") << "invalidAlias.11.qml" << "invalidAlias.11.errors.txt" << false; QTest::newRow("invalidAttachedProperty.1") << "invalidAttachedProperty.1.qml" << "invalidAttachedProperty.1.errors.txt" << false; QTest::newRow("invalidAttachedProperty.2") << "invalidAttachedProperty.2.qml" << "invalidAttachedProperty.2.errors.txt" << false; -- cgit v0.12