From 35d60aaae58b88d314dbe2501b5ee415490a1b96 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Fri, 11 Nov 2016 19:45:57 +0100 Subject: [PATCH] Remove remaining occurences of "this == nullptr" (#828) --- src/CBot/CBotProgram.cpp | 3 +-- src/CBot/CBotStack.cpp | 17 +++++++++++++---- src/CBot/CBotToken.cpp | 6 +++--- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/CBot/CBotProgram.cpp b/src/CBot/CBotProgram.cpp index 978c6410..a303df6d 100644 --- a/src/CBot/CBotProgram.cpp +++ b/src/CBot/CBotProgram.cpp @@ -363,8 +363,7 @@ bool CBotProgram::RestoreState(FILE* pf) } // retrieves the stack from the memory - // uses a nullptr pointer (m_stack) but it's ok like that - // TODO: no it's not okay like that! but it looks like it doesn't get optimized out at least ~krzys_h + m_stack = CBotStack::AllocateStack(); if (!m_stack->RestoreState(pf, m_stack)) return false; m_stack->SetProgram(this); // bases for routines diff --git a/src/CBot/CBotStack.cpp b/src/CBot/CBotStack.cpp index c554d7ca..6afcc754 100644 --- a/src/CBot/CBotStack.cpp +++ b/src/CBot/CBotStack.cpp @@ -192,8 +192,18 @@ bool CBotStack::Return(CBotStack* pfils) m_var = pfils->m_var; // result transmitted pfils->m_var = nullptr; // not to destroy the variable - if (m_next != nullptr) m_next->Delete();m_next = nullptr; // releases the stack above - if (m_next2 != nullptr) m_next2->Delete();m_next2 = nullptr; // also the second stack (catch) + if (m_next != nullptr) + { + // releases the stack above + m_next->Delete(); + m_next = nullptr; + } + if (m_next2 != nullptr) + { + // also the second stack (catch) + m_next2->Delete(); + m_next2 = nullptr; + } return IsOk(); // interrupted if error } @@ -731,8 +741,7 @@ bool CBotStack::RestoreState(FILE* pf, CBotStack* &pStack) if (!ReadWord(pf, w)) return false; if ( w == 0 ) return true; // 0 - terminator - if ( this == nullptr ) pStack = AllocateStack(); - else pStack = AddStack(); + pStack = AddStack(); if ( w == 2 ) // 2 - m_next2 { diff --git a/src/CBot/CBotToken.cpp b/src/CBot/CBotToken.cpp index 890c038a..28e6690c 100644 --- a/src/CBot/CBotToken.cpp +++ b/src/CBot/CBotToken.cpp @@ -199,7 +199,7 @@ const CBotToken& CBotToken::operator=(const CBotToken& src) //////////////////////////////////////////////////////////////////////////////// int CBotToken::GetType() { - if (this == nullptr) return 0; + assert(this != nullptr); if (m_type == TokenTypKeyWord) return m_keywordId; return m_type; } @@ -225,14 +225,14 @@ void CBotToken::SetString(const std::string& name) //////////////////////////////////////////////////////////////////////////////// int CBotToken::GetStart() { - if (this == nullptr) return -1; + assert(this != nullptr); return m_start; } //////////////////////////////////////////////////////////////////////////////// int CBotToken::GetEnd() { - if (this == nullptr) return -1; + assert(this != nullptr); return m_end; }