summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin Funk <kevin.funk@kdab.com>2016-11-17 23:07:32 +0100
committerJan Arne Petersen <jan.petersen@kdab.com>2016-11-22 15:22:05 +0000
commitb187f0bf115847c09cee70c74c2d4fdfc6a292d8 (patch)
treec9999e01398dfbcfc9989d0211b3f4fd9dd0d8a9
parent1806b1b4dd93ab10e0dbe0435596b32aa8b8e1b3 (diff)
Guard QScxmlStateMachineInfo::stateChildren()
Make sure we return something useful when querying the children of the root state. Add tests Change-Id: I39f41403dce6f67fc5aeb93cee98950368f7e14b Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
-rw-r--r--src/scxml/qscxmlstatemachineinfo.cpp12
1 files changed, 9 insertions, 3 deletions
diff --git a/src/scxml/qscxmlstatemachineinfo.cpp b/src/scxml/qscxmlstatemachineinfo.cpp
index 7b52f8a..154cea1 100644
--- a/src/scxml/qscxmlstatemachineinfo.cpp
+++ b/src/scxml/qscxmlstatemachineinfo.cpp
@@ -140,12 +140,18 @@ QVector<QScxmlStateMachineInfo::StateId> QScxmlStateMachineInfo::stateChildren(S
{
Q_D(const QScxmlStateMachineInfo);
+ int childStates = QScxmlExecutableContent::StateTable::InvalidIndex;
+ if (stateId == InvalidStateId)
+ childStates = d->stateTable()->childStates;
+ if (stateId >= 0 && stateId < d->stateTable()->stateCount)
+ childStates = d->stateTable()->state(stateId).childStates;
+
QVector<QScxmlStateMachineInfo::StateId> all;
- auto state = d->stateTable()->state(stateId);
- if (state.childStates == QScxmlExecutableContent::StateTable::InvalidIndex)
+ if (childStates == QScxmlExecutableContent::StateTable::InvalidIndex)
return all;
- auto kids = d->stateTable()->array(state.childStates);
+ const auto kids = d->stateTable()->array(childStates);
+ all.reserve(kids.size());
for (auto childId : kids) {
all.append(childId);
}