From d3b1232df8fc8b238d1be8301e58c14e7102cce3 Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Mon, 9 Nov 2009 18:47:29 +1000 Subject: Don't crash on invalid expressions QTBUG-5577 --- src/declarative/qml/qmlexpression.cpp | 7 ++++++- src/declarative/qml/qmlrewrite.cpp | 8 +++++++- src/declarative/qml/qmlrewrite_p.h | 2 +- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/declarative/qml/qmlexpression.cpp b/src/declarative/qml/qmlexpression.cpp index 4e4daf7..d2d60ee 100644 --- a/src/declarative/qml/qmlexpression.cpp +++ b/src/declarative/qml/qmlexpression.cpp @@ -315,7 +315,12 @@ QVariant QmlExpressionPrivate::evalQtScript(QObject *secondaryScope, bool *isUnd } else { QmlRewrite::RewriteBinding rewriteBinding; - const QString code = rewriteBinding(data->expression); + bool ok = true; + const QString code = rewriteBinding(data->expression, &ok); + if (!ok) { + scriptEngine->popContext(); + return QVariant(); + } data->expressionFunction = scriptEngine->evaluate(code, data->url.toString(), data->line); } diff --git a/src/declarative/qml/qmlrewrite.cpp b/src/declarative/qml/qmlrewrite.cpp index b86f2f2..32e2fef 100644 --- a/src/declarative/qml/qmlrewrite.cpp +++ b/src/declarative/qml/qmlrewrite.cpp @@ -49,7 +49,7 @@ DEFINE_BOOL_CONFIG_OPTION(rewriteDump, QML_REWRITE_DUMP); namespace QmlRewrite { -QString RewriteBinding::operator()(const QString &code) +QString RewriteBinding::operator()(const QString &code, bool *ok) { Engine engine; NodePool pool(QString(), &engine); @@ -57,6 +57,12 @@ QString RewriteBinding::operator()(const QString &code) Parser parser(&engine); lexer.setCode(code, 0); parser.parseStatement(); + if (!parser.statement()) { + if (ok) *ok = false; + return QString(); + } else { + if (ok) *ok = true; + } return rewrite(code, 0, parser.statement()); } diff --git a/src/declarative/qml/qmlrewrite_p.h b/src/declarative/qml/qmlrewrite_p.h index 914f997..a5cb841 100644 --- a/src/declarative/qml/qmlrewrite_p.h +++ b/src/declarative/qml/qmlrewrite_p.h @@ -69,7 +69,7 @@ class RewriteBinding: protected AST::Visitor TextWriter *_writer; public: - QString operator()(const QString &code); + QString operator()(const QString &code, bool *ok = 0); protected: using AST::Visitor::visit; -- cgit v0.12