Skip to content

Commit

Permalink
Change remaining "if (this!=NULL)" to "ASSERT(this!=NULL)"
Browse files Browse the repository at this point in the history
Also changed all "if (this==NULL) return;"s.

Fixes some -Wtautological-undefined-compare warnings.

Quoting Clang:
"'this' pointer cannot be null in well-defined C++ code; comparison may
be assumed to always evaluate to false"
  • Loading branch information
emlai authored and DanielGibson committed May 29, 2016
1 parent 24d61d1 commit 5badefa
Show file tree
Hide file tree
Showing 12 changed files with 58 additions and 81 deletions.
10 changes: 4 additions & 6 deletions Sources/Engine/Base/Anim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,16 +173,14 @@ BOOL CAnimData::IsAutoFreed(void)
// Reference counting functions
void CAnimData::AddReference(void)
{
if (this!=NULL) {
MarkUsed();
}
ASSERT(this!=NULL);
MarkUsed();
}

void CAnimData::RemReference(void)
{
if (this!=NULL) {
RemReference_internal();
}
ASSERT(this!=NULL);
RemReference_internal();
}

void CAnimData::RemReference_internal(void)
Expand Down
40 changes: 10 additions & 30 deletions Sources/Engine/Base/Console.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,7 @@ CConsole::CConsole(void)
// Destructor.
CConsole::~CConsole(void)
{
if (this==NULL) {
return;
}
ASSERT(this!=NULL);
if (con_fLog!=NULL) {
fclose(con_fLog);
con_fLog = NULL;
Expand Down Expand Up @@ -102,25 +100,19 @@ void CConsole::Initialize(const CTFileName &fnmLog, INDEX ctCharsPerLine, INDEX
// Get current console buffer.
const char *CConsole::GetBuffer(void)
{
if (this==NULL) {
return "";
}
ASSERT(this!=NULL);
return con_strBuffer+(con_ctLines-con_ctLinesPrinted)*(con_ctCharsPerLine+1);
}
INDEX CConsole::GetBufferSize(void)
{
if (this==NULL) {
return 1;
}
ASSERT(this!=NULL);
return (con_ctCharsPerLine+1)*con_ctLines+1;
}

// Discard timing info for last lines
void CConsole::DiscardLastLineTimes(void)
{
if (this==NULL) {
return;
}
ASSERT(this!=NULL);
for(INDEX i=0; i<con_ctLines; i++) {
con_atmLines[i] = -10000.0f;
}
Expand All @@ -129,9 +121,7 @@ void CConsole::DiscardLastLineTimes(void)
// Get number of lines newer than given time
INDEX CConsole::NumberOfLinesAfter(TIME tmLast)
{
if (this==NULL) {
return 0;
}
ASSERT(this!=NULL);
// clamp console variable
con_iLastLines = Clamp( con_iLastLines, 0, (INDEX)CONSOLE_MAXLASTLINES);
// find number of last console lines to be displayed on screen
Expand All @@ -146,9 +136,7 @@ INDEX CConsole::NumberOfLinesAfter(TIME tmLast)
// Get one of last lines
CTString CConsole::GetLastLine(INDEX iLine)
{
if (this==NULL) {
return "";
}
ASSERT(this!=NULL);
if (iLine>=con_ctLinesPrinted) {
return "";
}
Expand All @@ -166,9 +154,7 @@ CTString CConsole::GetLastLine(INDEX iLine)
// clear one given line in buffer
void CConsole::ClearLine(INDEX iLine)
{
if (this==NULL) {
return;
}
ASSERT(this!=NULL);
// line must be valid
ASSERT(iLine>=0 && iLine<con_ctLines);
// get start of line
Expand All @@ -183,9 +169,7 @@ void CConsole::ClearLine(INDEX iLine)
// scroll buffer up, discarding lines at the start
void CConsole::ScrollBufferUp(INDEX ctLines)
{
if (this==NULL) {
return;
}
ASSERT(this!=NULL);
ASSERT(ctLines>0 && ctLines<con_ctLines);
// move buffer up
memmove(
Expand All @@ -207,9 +191,7 @@ void CConsole::ScrollBufferUp(INDEX ctLines)
// Add a line of text to console
void CConsole::PutString(const char *strString)
{
if (this==NULL) {
return;
}
ASSERT(this!=NULL);
// synchronize access to console
CTSingleLock slConsole(&con_csConsole, TRUE);

Expand Down Expand Up @@ -265,9 +247,7 @@ void CConsole::PutString(const char *strString)
// Close console log file buffers (call only when force-exiting!)
void CConsole::CloseLog(void)
{
if (this==NULL) {
return;
}
ASSERT(this!=NULL);
if (con_fLog!=NULL) {
fclose(con_fLog);
}
Expand Down
5 changes: 1 addition & 4 deletions Sources/Engine/Entities/Entity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2036,10 +2036,7 @@ static CStaticStackArray<CSentEvent> _aseSentEvents; // delayed events
/* Send an event to this entity. */
void CEntity::SendEvent(const CEntityEvent &ee)
{
if (this==NULL) {
ASSERT(FALSE);
return;
}
ASSERT(this!=NULL);
CSentEvent &se = _aseSentEvents.Push();
se.se_penEntity = this;
se.se_peeEvent = ((CEntityEvent&)ee).MakeCopy(); // discard const qualifier
Expand Down
18 changes: 8 additions & 10 deletions Sources/Engine/Entities/Entity.h
Original file line number Diff line number Diff line change
Expand Up @@ -694,18 +694,16 @@ inline CEntity& CEntityPointer::operator*(void) const { return *ep_pen; }
/////////////////////////////////////////////////////////////////////
// Reference counting functions
inline void CEntity::AddReference(void) {
if (this!=NULL) {
ASSERT(en_ctReferences>=0);
en_ctReferences++;
}
ASSERT(this!=NULL);
ASSERT(en_ctReferences>=0);
en_ctReferences++;
};
inline void CEntity::RemReference(void) {
if (this!=NULL) {
ASSERT(en_ctReferences>0);
en_ctReferences--;
if(en_ctReferences==0) {
delete this;
}
ASSERT(this!=NULL);
ASSERT(en_ctReferences>0);
en_ctReferences--;
if(en_ctReferences==0) {
delete this;
}
};

Expand Down
10 changes: 4 additions & 6 deletions Sources/Engine/Entities/EntityClass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,12 @@ CEntityClass::~CEntityClass(void)
/////////////////////////////////////////////////////////////////////
// Reference counting functions
void CEntityClass::AddReference(void) {
if (this!=NULL) {
MarkUsed();
}
ASSERT(this!=NULL);
MarkUsed();
};
void CEntityClass::RemReference(void) {
if (this!=NULL) {
_pEntityClassStock->Release(this);
}
ASSERT(this!=NULL);
_pEntityClassStock->Release(this);
};

/*
Expand Down
18 changes: 12 additions & 6 deletions Sources/Engine/Network/Network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -655,7 +655,8 @@ extern void FreeUnusedStock(void)
*/
void CNetworkTimerHandler::HandleTimer(void)
{
if (this==NULL || _bTempNetwork) {
ASSERT(this!=NULL);
if (_bTempNetwork) {
return; // this can happen during NET_MakeDefaultState_t()!
}
// enable stream handling during timer
Expand Down Expand Up @@ -902,7 +903,8 @@ void CNetworkLibrary::Init(const CTString &strGameID)
*/
void CNetworkLibrary::AddTimerHandler(void)
{
if (this==NULL || _bTempNetwork) {
ASSERT(this!=NULL);
if (_bTempNetwork) {
return; // this can happen during NET_MakeDefaultState_t()!
}
_pTimer->AddHandler(&ga_thTimerHandler);
Expand All @@ -912,7 +914,8 @@ void CNetworkLibrary::AddTimerHandler(void)
*/
void CNetworkLibrary::RemoveTimerHandler(void)
{
if (this==NULL || _bTempNetwork) {
ASSERT(this!=NULL);
if (_bTempNetwork) {
return; // this can happen during NET_MakeDefaultState_t()!
}
_pTimer->RemHandler(&ga_thTimerHandler);
Expand Down Expand Up @@ -1390,7 +1393,8 @@ void CNetworkLibrary::TogglePause(void)
// test if game is paused
BOOL CNetworkLibrary::IsPaused(void)
{
if (this==NULL || _bTempNetwork) {
ASSERT(this!=NULL);
if (_bTempNetwork) {
return TRUE; // this can happen during NET_MakeDefaultState_t()!
}
return ga_sesSessionState.ses_bPause;
Expand Down Expand Up @@ -1427,7 +1431,8 @@ void CNetworkLibrary::SetLocalPause(BOOL bPause)

BOOL CNetworkLibrary::GetLocalPause(void)
{
if (this==NULL || _bTempNetwork) {
ASSERT(this!=NULL);
if (_bTempNetwork) {
return TRUE; // this can happen during NET_MakeDefaultState_t()!
}
return ga_bLocalPause;
Expand Down Expand Up @@ -2033,7 +2038,8 @@ void CNetworkLibrary::SendActionsToServer(void)
*/
void CNetworkLibrary::TimerLoop(void)
{
if (this==NULL || _bTempNetwork) {
ASSERT(this!=NULL);
if (_bTempNetwork) {
return; // this can happen during NET_MakeDefaultState_t()!
}
_pfNetworkProfile.StartTimer(CNetworkProfile::PTI_TIMERLOOP);
Expand Down
10 changes: 4 additions & 6 deletions Sources/Engine/Sound/SoundData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,16 +252,14 @@ SLONG CSoundData::GetUsedMemory(void)
// Add one reference
void CSoundData::AddReference(void)
{
if (this!=NULL) {
MarkUsed();
}
ASSERT(this!=NULL);
MarkUsed();
}


// Remove one reference
void CSoundData::RemReference(void)
{
if (this!=NULL) {
_pSoundStock->Release(this);
}
ASSERT(this!=NULL);
_pSoundStock->Release(this);
}
3 changes: 2 additions & 1 deletion Sources/Engine/Sound/SoundLibrary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1233,6 +1233,7 @@ BOOL CSoundLibrary::SetEnvironment( INDEX iEnvNo, FLOAT fEnvSize/*=0*/)
// mute all sounds (erase playing buffer(s) and supress mixer)
void CSoundLibrary::Mute(void)
{
ASSERT(this!=NULL);
// stop all IFeel effects
IFeel_StopEffect(NULL);

Expand All @@ -1244,7 +1245,7 @@ void CSoundLibrary::Mute(void)

#ifdef PLATFORM_WIN32
// erase direct sound buffer (waveout will shut-up by itself), but skip if there's no more sound library
if( this==NULL || !sl_bUsingDirectSound) return;
if(!sl_bUsingDirectSound) return;

// synchronize access to sounds
CTSingleLock slSounds(&sl_csSound, TRUE);
Expand Down
9 changes: 5 additions & 4 deletions Sources/Engine/World/World.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -936,10 +936,11 @@ void CWorld::TriangularizeForVertices( CBrushVertexSelection &selVertex)
// add this entity to prediction
void CEntity::AddToPrediction(void)
{
// this function may be called even for NULLs - so ignore it
if (this==NULL) {
return;
}
// this function may be called even for NULLs - TODO: fix those cases
// (The compiler is free to assume that "this" is never NULL and optimize
// based on that assumption. For example, an "if (this==NULL) {...}" could
// be optimized away completely.)
ASSERT(this!=NULL);
// if already added
if (en_ulFlags&ENF_WILLBEPREDICTED) {
// do nothing
Expand Down
6 changes: 4 additions & 2 deletions Sources/Entities/Common/PathFinding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ CPathNode::~CPathNode(void)
// get name of this node
const CTString &CPathNode::GetName(void)
{
ASSERT(this!=NULL);
static CTString strNone="<none>";
if (this==NULL || pn_pnmMarker==NULL) {
if (pn_pnmMarker==NULL) {
return strNone;
} else {
return pn_pnmMarker->GetName();
Expand All @@ -46,7 +47,8 @@ const CTString &CPathNode::GetName(void)
// get link with given index or null if no more (for iteration along the graph)
CPathNode *CPathNode::GetLink(INDEX i)
{
if (this==NULL || pn_pnmMarker==NULL) {
ASSERT(this!=NULL);
if (pn_pnmMarker==NULL) {
ASSERT(FALSE);
return NULL;
}
Expand Down
8 changes: 3 additions & 5 deletions Sources/EntitiesMP/Common/PathFinding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,9 @@ CPathNode::~CPathNode(void)
// get name of this node
const CTString &CPathNode::GetName(void)
{
ASSERT(this!=NULL);
static CTString strNone="<none>";
if (this==NULL || pn_pnmMarker==NULL) {
if (pn_pnmMarker==NULL) {
return strNone;
} else {
return pn_pnmMarker->GetName();
Expand All @@ -61,10 +62,7 @@ const CTString &CPathNode::GetName(void)
// get link with given index or null if no more (for iteration along the graph)
CPathNode *CPathNode::GetLink(INDEX i)
{
if (this==NULL || pn_pnmMarker==NULL) {
ASSERT(FALSE);
return NULL;
}
ASSERT(this!=NULL && pn_pnmMarker!=NULL);
CNavigationMarker *pnm = pn_pnmMarker->GetLink(i);
if (pnm==NULL) {
return NULL;
Expand Down
2 changes: 1 addition & 1 deletion Sources/Modeler/DlgPgInfoAttachingPlacement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ INDEX CDlgPgInfoAttachingPlacement::GetCurrentAttachingPlacement(void)
void CDlgPgInfoAttachingPlacement::SetPlacementReferenceVertex(INDEX iCenter, INDEX iFront, INDEX iUp)
{
// patch for calling before page is refreshed
if(this == NULL) return;
ASSERT(this!=NULL);
CModelerView *pModelerView = CModelerView::GetActiveView();
if(pModelerView == NULL) return;
CModelerDoc* pDoc = pModelerView->GetDocument();
Expand Down

0 comments on commit 5badefa

Please sign in to comment.