From c729444787a5cbabf88d2f3f9338712b16a4d152 Mon Sep 17 00:00:00 2001 From: Stan Date: Thu, 5 Jan 2023 12:09:02 +0000 Subject: [PATCH] replace NULL by nullptr remove nullptr check before delete. They are redundant. remove nullptr check after new. They will never be null. two whitespaces changes forgotten in https://code.wildfiregames.com/D4800. Patch by: @phosit Differential Revision: https://code.wildfiregames.com/D4853 This was SVN commit r27351. --- source/network/FSM.cpp | 43 ++++++++++++------------------------------ 1 file changed, 12 insertions(+), 31 deletions(-) diff --git a/source/network/FSM.cpp b/source/network/FSM.cpp index 3920c99ad1..a7a14f3c21 100644 --- a/source/network/FSM.cpp +++ b/source/network/FSM.cpp @@ -28,7 +28,7 @@ CFsmEvent::CFsmEvent(unsigned int type) { m_Type = type; - m_Param = NULL; + m_Param = nullptr; } //----------------------------------------------------------------------------- @@ -37,7 +37,7 @@ CFsmEvent::CFsmEvent(unsigned int type) //----------------------------------------------------------------------------- CFsmEvent::~CFsmEvent() { - m_Param = NULL; + m_Param = nullptr; } //----------------------------------------------------------------------------- @@ -123,7 +123,7 @@ void CFsmTransition::SetNextState(unsigned int nextState) //----------------------------------------------------------------------------- bool CFsmTransition::ApplyConditions() const { - bool eval = true; + bool eval = true; CallbackList::const_iterator it = m_Conditions.begin(); for (; it != m_Conditions.end(); ++it) @@ -201,24 +201,12 @@ void CFsm::Shutdown() // Release transitions TransitionList::iterator itTransition = m_Transitions.begin(); for (; itTransition < m_Transitions.end(); ++itTransition) - { - CFsmTransition* pCurrTransition = *itTransition; - if (!pCurrTransition) - continue; - - delete pCurrTransition; - } + delete *itTransition; // Release events EventMap::iterator itEvent = m_Events.begin(); for (; itEvent != m_Events.end(); ++itEvent) - { - CFsmEvent* pCurrEvent = itEvent->second; - if (!pCurrEvent) - continue; - - delete pCurrEvent; - } + delete itEvent->second; m_States.clear(); m_Events.clear(); @@ -247,7 +235,7 @@ void CFsm::AddState(unsigned int state) //----------------------------------------------------------------------------- CFsmEvent* CFsm::AddEvent(unsigned int eventType) { - CFsmEvent* pEvent = NULL; + CFsmEvent* pEvent = nullptr; // Lookup event by type EventMap::iterator it = m_Events.find(eventType); @@ -258,8 +246,6 @@ CFsmEvent* CFsm::AddEvent(unsigned int eventType) else { pEvent = new CFsmEvent(eventType); - if (!pEvent) - return NULL; // Store new event into internal map m_Events[eventType] = pEvent; @@ -283,15 +269,10 @@ CFsmTransition* CFsm::AddTransition(unsigned int state, unsigned int eventType, // Make sure we store the event CFsmEvent* pEvent = AddEvent(eventType); if (!pEvent) - return NULL; + return nullptr; // Create new transition CFsmTransition* pNewTransition = new CFsmTransition(state); - if (!pNewTransition) - { - delete pEvent; - return NULL; - } // Setup new transition pNewTransition->SetEvent(pEvent); @@ -312,7 +293,7 @@ CFsmTransition* CFsm::AddTransition(unsigned int state, unsigned int eventType, { CFsmTransition* pTransition = AddTransition(state, eventType, nextState); if (!pTransition) - return NULL; + return nullptr; // If action specified, register it if (pAction) @@ -329,18 +310,18 @@ CFsmTransition* CFsm::GetTransition(unsigned int state, unsigned int eventType) { // Valid state? if (!IsValidState(state)) - return NULL; + return nullptr; // Valid event? if (!IsValidEvent(eventType)) - return NULL; + return nullptr; // Loop through the list of transitions TransitionList::const_iterator it = m_Transitions.begin(); for (; it != m_Transitions.end(); ++it) { CFsmTransition* pCurrTransition = *it; - if ( !pCurrTransition ) + if (!pCurrTransition) continue; CFsmEvent* pCurrEvent = pCurrTransition->GetEvent(); @@ -353,7 +334,7 @@ CFsmTransition* CFsm::GetTransition(unsigned int state, unsigned int eventType) } // No transition found - return NULL; + return nullptr; } //-----------------------------------------------------------------------------