diff options
author | Ulf Hermann <ulf.hermann@theqtcompany.com> | 2016-04-05 14:05:16 +0200 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@theqtcompany.com> | 2016-04-14 15:14:44 +0000 |
commit | 972eaad3123f0471345e514b6b7b095fe5728f6e (patch) | |
tree | 37aefa7c5f068c6469ccd04d3feb8dbc1724454f | |
parent | 14c1090c89bba1af881d568274d4f1b9fe5f8a28 (diff) |
Don't crash on misplaced <invoke>
Change-Id: I052261ef64ae4ada5c93211c61718cd81e4f0dd7
Reviewed-by: Jarek Kobus <jaroslaw.kobus@theqtcompany.com>
-rw-r--r-- | src/scxml/qscxmlparser.cpp | 12 | ||||
-rw-r--r-- | tests/auto/qscxmlc/data/misplacedinvoke.scxml | 18 | ||||
-rw-r--r-- | tests/auto/qscxmlc/tst_qscxmlc.qrc | 1 |
3 files changed, 29 insertions, 2 deletions
diff --git a/src/scxml/qscxmlparser.cpp b/src/scxml/qscxmlparser.cpp index 83cdd7b..5857b5a 100644 --- a/src/scxml/qscxmlparser.cpp +++ b/src/scxml/qscxmlparser.cpp @@ -2471,8 +2471,16 @@ void QScxmlParserPrivate::parse() m_stack.append(pNew); } else if (elName == QLatin1String("finalize")) { ParserState pNew(ParserState::Finalize); - auto invoke = m_stack.last().instruction->asInvoke(); - Q_ASSERT(invoke); + auto instr = m_stack.last().instruction; + if (!instr) { + addError(QStringLiteral("no previous instruction found for <finalize>")); + return; + } + auto invoke = instr->asInvoke(); + if (!invoke) { + addError(QStringLiteral("instruction before <finalize> is not <invoke>")); + return; + } pNew.instructionContainer = &invoke->finalize; m_stack.append(pNew); } else { diff --git a/tests/auto/qscxmlc/data/misplacedinvoke.scxml b/tests/auto/qscxmlc/data/misplacedinvoke.scxml new file mode 100644 index 0000000..fe5e5de --- /dev/null +++ b/tests/auto/qscxmlc/data/misplacedinvoke.scxml @@ -0,0 +1,18 @@ +<?xml version="1.0" encoding="UTF-8"?> +<scxml + xmlns="http://www.w3.org/2005/07/scxml" + xmlns:conf="http://www.w3.org/2005/scxml-conformance" + initial="p01" version="1.0"> + <state id="p01"> + <invoke type="http://Www.w3.org/TR/scxml/"> + <content> + <scxml version="1.0" initial="subFinal1" datamodel="ecmascript"> + <final id="subFinal1"></final> + </scxml> + <finalize> + <assign location="Var1" expr="_event.data.aParam"/> + </finalize> + </content> + </invoke> + </state> +</scxml> diff --git a/tests/auto/qscxmlc/tst_qscxmlc.qrc b/tests/auto/qscxmlc/tst_qscxmlc.qrc index 85911ca..24ee227 100644 --- a/tests/auto/qscxmlc/tst_qscxmlc.qrc +++ b/tests/auto/qscxmlc/tst_qscxmlc.qrc @@ -1,6 +1,7 @@ <RCC> <qresource prefix="/tst_qscxmlc"> <file>data/empty.scxml</file> + <file>data/misplacedinvoke.scxml</file> <file>data/id000000sig11src000000opflip1pos24.scxml</file> <file>data/id000001sig11src000000opflip1pos7243.scxml</file> <file>data/id000002sig11src000000opflip1pos7244.scxml</file> |