Skip to content

Commit 1ebbf5c

Browse files
authored
[ZH] Prevent dereferencing NULL pointer 'state' in StateMachine::xfer() (#1100)
1 parent 5104ace commit 1ebbf5c

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

GeneralsMD/Code/GameEngine/Source/Common/StateMachine.cpp

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -865,19 +865,24 @@ void StateMachine::xfer( Xfer *xfer )
865865
}
866866
for( i = m_stateMap.begin(); i != m_stateMap.end(); ++i ) {
867867
State *state = (*i).second;
868-
StateID id = state->getID();
869-
xfer->xferUnsignedInt(&id);
870-
if (id!=state->getID()) {
871-
DEBUG_CRASH(("State ID mismatch - %d expected, %d read", state->getID(), id));
872-
throw SC_INVALID_DATA;
868+
if( state != NULL )
869+
{
870+
StateID id = state->getID();
871+
xfer->xferUnsignedInt(&id);
872+
if (id!=state->getID()) {
873+
DEBUG_CRASH(("State ID mismatch - %d expected, %d read", state->getID(), id));
874+
throw SC_INVALID_DATA;
875+
}
873876
}
874-
875-
if( state == NULL )
877+
else
876878
{
877-
DEBUG_ASSERTCRASH(state != NULL, ("state was NULL on xfer, trying to heal..."));
879+
DEBUG_CRASH(("state was NULL on xfer, trying to heal..."));
878880
// Hmm... too late to find out why we are getting NULL in our state, but if we let it go, we will Throw in xferSnapshot.
879881
state = internalGetState(m_defaultStateID);
882+
StateID id = state->getID();
883+
xfer->xferUnsignedInt(&id);
880884
}
885+
881886
xfer->xferSnapshot(state);
882887
}
883888

0 commit comments

Comments
 (0)