diff options
author | Marc Mutz <marc.mutz@kdab.com> | 2015-01-08 14:52:01 +0100 |
---|---|---|
committer | Marc Mutz <marc.mutz@kdab.com> | 2015-01-09 12:06:15 +0100 |
commit | 65eb57392685d69313217fd17e06376db8f9c05b (patch) | |
tree | abdf5ee302138a0abd26f1ac5579ebfbfb1f9f05 /src/corelib/statemachine | |
parent | 3ecc44d5d26de661eaaaf4164092b2941f5dd615 (diff) |
QStateMachine: fix some misleading code
The old code creates a RestorableId from the passed (QObject*, QByteArray)
and used it for lookup in a hash table (ok) and as a container for the
(QObject*, QByteArray), satisfying later references to those parameters
from the RestorableId instance instead of using the parameters directly.
Now, RestorableId holds the QObject* in a QPointer, so the code might have
wanted to detect the object being destroyed as part of the operation, BUT:
a) the operation is a read-only one, and b) the code didn't check for
nullness before dereferencing the QObject*.
Fix by moving the creation of the RestorableId into the scope it's used
and otherwise using the parameters directly.
Change-Id: Iaf12f722fe6841ee1a55037fe33a6115aa699aca
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/statemachine')
-rw-r--r-- | src/corelib/statemachine/qstatemachine.cpp | 5 |
1 files changed, 2 insertions, 3 deletions
diff --git a/src/corelib/statemachine/qstatemachine.cpp b/src/corelib/statemachine/qstatemachine.cpp index 69e942d4fd..27c7b077c6 100644 --- a/src/corelib/statemachine/qstatemachine.cpp +++ b/src/corelib/statemachine/qstatemachine.cpp @@ -882,11 +882,10 @@ QVariant QStateMachinePrivate::savedValueForRestorable(const QList<QAbstractStat #ifdef QSTATEMACHINE_RESTORE_PROPERTIES_DEBUG qDebug() << q_func() << ": savedValueForRestorable(" << exitedStates_sorted << object << propertyName << ")"; #endif - RestorableId id(object, propertyName); for (int i = exitedStates_sorted.size() - 1; i >= 0; --i) { QAbstractState *s = exitedStates_sorted.at(i); QHash<RestorableId, QVariant> restorables = registeredRestorablesForState.value(s); - QHash<RestorableId, QVariant>::const_iterator it = restorables.constFind(id); + QHash<RestorableId, QVariant>::const_iterator it = restorables.constFind(RestorableId(object, propertyName)); if (it != restorables.constEnd()) { #ifdef QSTATEMACHINE_RESTORE_PROPERTIES_DEBUG qDebug() << q_func() << ": using" << it.value() << "from" << s; @@ -897,7 +896,7 @@ QVariant QStateMachinePrivate::savedValueForRestorable(const QList<QAbstractStat #ifdef QSTATEMACHINE_RESTORE_PROPERTIES_DEBUG qDebug() << q_func() << ": falling back to current value"; #endif - return id.first->property(id.second); + return object->property(propertyName); } void QStateMachinePrivate::registerRestorable(QAbstractState *state, QObject *object, const QByteArray &propertyName, |