From 65eb57392685d69313217fd17e06376db8f9c05b Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Thu, 8 Jan 2015 14:52:01 +0100 Subject: 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 --- src/corelib/statemachine/qstatemachine.cpp | 5 ++--- 1 file 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= 0; --i) { QAbstractState *s = exitedStates_sorted.at(i); QHash restorables = registeredRestorablesForState.value(s); - QHash::const_iterator it = restorables.constFind(id); + QHash::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 QListproperty(id.second); + return object->property(propertyName); } void QStateMachinePrivate::registerRestorable(QAbstractState *state, QObject *object, const QByteArray &propertyName, -- cgit v1.2.3