Change remaining "if (this!=NULL)" to "ASSERT(this!=NULL)"

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"
This commit is contained in:
Emil Laine 2016-04-24 00:17:29 +03:00 committed by Daniel Gibson
parent 24d61d1ccc
commit 5badefaf90
12 changed files with 58 additions and 81 deletions

View File

@ -173,16 +173,14 @@ BOOL CAnimData::IsAutoFreed(void)
// Reference counting functions
void CAnimData::AddReference(void)
{
if (this!=NULL) {
ASSERT(this!=NULL);
MarkUsed();
}
}
void CAnimData::RemReference(void)
{
if (this!=NULL) {
ASSERT(this!=NULL);
RemReference_internal();
}
}
void CAnimData::RemReference_internal(void)

View File

@ -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;
@ -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;
}
@ -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
@ -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 "";
}
@ -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
@ -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(
@ -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);
@ -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);
}

View File

@ -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

View File

@ -694,19 +694,17 @@ inline CEntity& CEntityPointer::operator*(void) const { return *ep_pen; }
/////////////////////////////////////////////////////////////////////
// Reference counting functions
inline void CEntity::AddReference(void) {
if (this!=NULL) {
ASSERT(this!=NULL);
ASSERT(en_ctReferences>=0);
en_ctReferences++;
}
};
inline void CEntity::RemReference(void) {
if (this!=NULL) {
ASSERT(this!=NULL);
ASSERT(en_ctReferences>0);
en_ctReferences--;
if(en_ctReferences==0) {
delete this;
}
}
};
/*

View File

@ -64,14 +64,12 @@ CEntityClass::~CEntityClass(void)
/////////////////////////////////////////////////////////////////////
// Reference counting functions
void CEntityClass::AddReference(void) {
if (this!=NULL) {
ASSERT(this!=NULL);
MarkUsed();
}
};
void CEntityClass::RemReference(void) {
if (this!=NULL) {
ASSERT(this!=NULL);
_pEntityClassStock->Release(this);
}
};
/*

View File

@ -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
@ -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);
@ -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);
@ -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;
@ -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;
@ -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);

View File

@ -252,16 +252,14 @@ SLONG CSoundData::GetUsedMemory(void)
// Add one reference
void CSoundData::AddReference(void)
{
if (this!=NULL) {
ASSERT(this!=NULL);
MarkUsed();
}
}
// Remove one reference
void CSoundData::RemReference(void)
{
if (this!=NULL) {
ASSERT(this!=NULL);
_pSoundStock->Release(this);
}
}

View File

@ -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);
@ -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);

View File

@ -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

View File

@ -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();
@ -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;
}

View File

@ -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();
@ -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;

View File

@ -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();