Skip to content

Commit

Permalink
Get rid of more critical 'this' comparisons with NULL.
Browse files Browse the repository at this point in the history
  • Loading branch information
DreamyCecil committed Sep 9, 2024
1 parent d69b6f9 commit 8ae5d8a
Show file tree
Hide file tree
Showing 21 changed files with 41 additions and 69 deletions.
2 changes: 1 addition & 1 deletion Sources/Engine/Base/CTString.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ CTStream &operator<<(CTStream &strmStream, const CTString &strString)
*/
BOOL CTString::IsValid(void) const
{
ASSERT(this!=NULL && str_String!=NULL);
ASSERT(str_String != NULL);
return TRUE;
}
#endif // NDEBUG
Expand Down
15 changes: 0 additions & 15 deletions Sources/Engine/Base/Console.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,21 +99,17 @@ void CConsole::Initialize(const CTFileName &fnmLog, INDEX ctCharsPerLine, INDEX
// Get current console buffer.
const char *CConsole::GetBuffer(void)
{
ASSERT(this != NULL);
return con_strBuffer+(con_ctLines-con_ctLinesPrinted)*(con_ctCharsPerLine+1);
}

INDEX CConsole::GetBufferSize(void)
{
ASSERT(this != NULL);
return (con_ctCharsPerLine+1)*con_ctLines+1;
}

// Discard timing info for last lines
void CConsole::DiscardLastLineTimes(void)
{
ASSERT(this != NULL);

for(INDEX i=0; i<con_ctLines; i++) {
con_atmLines[i] = -10000.0f;
}
Expand All @@ -122,8 +118,6 @@ void CConsole::DiscardLastLineTimes(void)
// Get number of lines newer than given time
INDEX CConsole::NumberOfLinesAfter(TIME tmLast)
{
ASSERT(this != NULL);

// clamp console variable
con_iLastLines = Clamp( con_iLastLines, 0L, (INDEX)CONSOLE_MAXLASTLINES);
// find number of last console lines to be displayed on screen
Expand All @@ -138,8 +132,6 @@ INDEX CConsole::NumberOfLinesAfter(TIME tmLast)
// Get one of last lines
CTString CConsole::GetLastLine(INDEX iLine)
{
ASSERT(this != NULL);

if (iLine>=con_ctLinesPrinted) {
return "";
}
Expand All @@ -157,8 +149,6 @@ CTString CConsole::GetLastLine(INDEX iLine)
// clear one given line in buffer
void CConsole::ClearLine(INDEX iLine)
{
ASSERT(this != NULL);

// line must be valid
ASSERT(iLine>=0 && iLine<con_ctLines);
// get start of line
Expand All @@ -173,7 +163,6 @@ void CConsole::ClearLine(INDEX iLine)
// scroll buffer up, discarding lines at the start
void CConsole::ScrollBufferUp(INDEX ctLines)
{
ASSERT(this != NULL);
ASSERT(ctLines>0 && ctLines<con_ctLines);
// move buffer up
memmove(
Expand All @@ -195,8 +184,6 @@ void CConsole::ScrollBufferUp(INDEX ctLines)
// Add a line of text to console
void CConsole::PutString(const char *strString)
{
ASSERT(this != NULL);

// synchronize access to console
CTSingleLock slConsole(&con_csConsole, TRUE);

Expand Down Expand Up @@ -251,8 +238,6 @@ void CConsole::PutString(const char *strString)
// Close console log file buffers (call only when force-exiting!)
void CConsole::CloseLog(void)
{
ASSERT(this != NULL);

if (con_fLog!=NULL) {
fclose(con_fLog);
}
Expand Down
3 changes: 0 additions & 3 deletions Sources/Engine/Base/Lists.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
*/
void CListHead::Clear(void)
{
ASSERT(this!=NULL);
lh_Head = (CListNode *) &(lh_NULL);
lh_NULL = (CListNode *) NULL;
lh_Tail = (CListNode *) &(lh_Head);
Expand All @@ -38,7 +37,6 @@ void CListHead::Clear(void)
*/
BOOL CListHead::IsValid(void) const
{
ASSERT(this!=NULL);
ASSERT(lh_NULL == NULL);
ASSERT((lh_Head == (CListNode *) &lh_NULL) && (lh_Tail == (CListNode *) &lh_Head)
|| lh_Tail->IsValid() && lh_Head->IsValid() );
Expand Down Expand Up @@ -207,7 +205,6 @@ void CListHead::Sort(int (*pCompare)(const void *p0, const void *p1), size_t iNo
*/
BOOL CListNode::IsValid(void) const
{
ASSERT(this!=NULL);
ASSERT((ln_Pred==NULL && ln_Succ==NULL) || (ln_Pred!=NULL && ln_Succ!=NULL));
// it is valid if it is cleared or if it is linked
return (ln_Pred==NULL && ln_Succ==NULL)
Expand Down
12 changes: 0 additions & 12 deletions Sources/Engine/Base/Timer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -421,8 +421,6 @@ void CTimer::AddHandler(CTimerHandler *pthNew)
{
// access to the list of handlers must be locked
CTSingleLock slHooks(&tm_csHooks, TRUE);

ASSERT(this!=NULL);
tm_lhHooks.AddTail(pthNew->th_Node);
}

Expand All @@ -433,8 +431,6 @@ void CTimer::RemHandler(CTimerHandler *pthOld)
{
// access to the list of handlers must be locked
CTSingleLock slHooks(&tm_csHooks, TRUE);

ASSERT(this!=NULL);
pthOld->th_Node.Remove();
}

Expand All @@ -453,7 +449,6 @@ void CTimer::HandleTimerHandlers(void)
*/
void CTimer::SetRealTimeTick(TIME tNewRealTimeTick)
{
ASSERT(this!=NULL);
tm_RealTimeTimer = tNewRealTimeTick;
}

Expand All @@ -462,45 +457,38 @@ void CTimer::SetRealTimeTick(TIME tNewRealTimeTick)
*/
TIME CTimer::GetRealTimeTick(void) const
{
ASSERT(this!=NULL);
return tm_RealTimeTimer;
}

/*
* Set the current game tick used for time dependent tasks (animations etc.).
*/
void CTimer::SetCurrentTick(TIME tNewCurrentTick) {
ASSERT(this!=NULL);
_CurrentTickTimer = tNewCurrentTick;
}

/*
* Get current game time, always valid for the currently active task.
*/
const TIME CTimer::CurrentTick(void) const {
ASSERT(this!=NULL);
return _CurrentTickTimer;
}
const TIME CTimer::GetLerpedCurrentTick(void) const {
ASSERT(this!=NULL);
return _CurrentTickTimer+tm_fLerpFactor*TickQuantum;
}
// Set factor for lerping between ticks.
void CTimer::SetLerp(FLOAT fFactor) // sets both primary and secondary
{
ASSERT(this!=NULL);
tm_fLerpFactor = fFactor;
tm_fLerpFactor2 = fFactor;
}
void CTimer::SetLerp2(FLOAT fFactor) // sets only secondary
{
ASSERT(this!=NULL);
tm_fLerpFactor2 = fFactor;
}
// Disable lerping factor (set both factors to 1)
void CTimer::DisableLerp(void)
{
ASSERT(this!=NULL);
tm_fLerpFactor =1.0f;
tm_fLerpFactor2=1.0f;
}
Expand Down
1 change: 1 addition & 0 deletions Sources/Engine/Entities/Entity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2036,6 +2036,7 @@ static CStaticStackArray<CSentEvent> _aseSentEvents; // delayed events
/* Send an event to this entity. */
void CEntity::SendEvent(const CEntityEvent &ee)
{
// [Cecil] FIXME: I can't be bothered to modify all entity sources right now, so it stays
if (this==NULL) {
ASSERT(FALSE);
return;
Expand Down
1 change: 0 additions & 1 deletion Sources/Engine/Entities/PlayerCharacter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,6 @@ void CPlayerCharacter::SetTeam(CTString strTeam)
/* Assignment operator. */
CPlayerCharacter &CPlayerCharacter::operator=(const CPlayerCharacter &pcOther)
{
ASSERT(this!=NULL && &pcOther!=NULL);
pc_strName = pcOther.pc_strName;
pc_strTeam = pcOther.pc_strTeam;
memcpy(pc_aubGUID, pcOther.pc_aubGUID, PLAYERGUIDSIZE);
Expand Down
2 changes: 0 additions & 2 deletions Sources/Engine/Graphics/GfxLibrary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1069,8 +1069,6 @@ CGfxLibrary::~CGfxLibrary()
/* Initialize library for application main window. */
void CGfxLibrary::Init(void)
{
ASSERT( this!=NULL);

// report desktop settings
CPutString(TRANS("Desktop settings...\n"));

Expand Down
2 changes: 0 additions & 2 deletions Sources/Engine/Graphics/Raster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ void CRaster::RecalculateDrawPortsDimensions(void)
*/
BOOL CRaster::Lock()
{
ASSERT( this!=NULL);
ASSERT( ra_LockCount>=0);

// if raster size is too small in some axis
Expand Down Expand Up @@ -116,7 +115,6 @@ BOOL CRaster::Lock()
*/
void CRaster::Unlock()
{
ASSERT( this!=NULL);
ASSERT( ra_LockCount>0);

// decrement counter
Expand Down
1 change: 0 additions & 1 deletion Sources/Engine/Graphics/ShadowMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,6 @@ void CShadowMap::WriteLayers_t( CTStream *pstrm) // throw char *
void CShadowMap::Prepare(void)
{
// determine probing
ASSERT(this!=NULL);
extern BOOL ProbeMode( CTimerValue tvLast);
BOOL bUseProbe = ProbeMode(sm_tvLastDrawn);

Expand Down
16 changes: 9 additions & 7 deletions Sources/Engine/Network/Network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,7 @@ extern void FreeUnusedStock(void)
*/
void CNetworkTimerHandler::HandleTimer(void)
{
if (this==NULL || _bTempNetwork) {
if (_bTempNetwork) {
return; // this can happen during NET_MakeDefaultState_t()!
}

Expand All @@ -656,7 +656,9 @@ void CNetworkTimerHandler::HandleTimer(void)
#endif

// do the timer loop
_pNetwork->TimerLoop();
if (_pNetwork != NULL) {
_pNetwork->TimerLoop();
}

#if !SE1_SINGLE_THREAD
} CTSTREAM_END;
Expand Down Expand Up @@ -899,7 +901,7 @@ void CNetworkLibrary::Init(void)
*/
void CNetworkLibrary::AddTimerHandler(void)
{
if (this==NULL || _bTempNetwork) {
if (_bTempNetwork) {
return; // this can happen during NET_MakeDefaultState_t()!
}
_pTimer->AddHandler(&ga_thTimerHandler);
Expand All @@ -909,7 +911,7 @@ void CNetworkLibrary::AddTimerHandler(void)
*/
void CNetworkLibrary::RemoveTimerHandler(void)
{
if (this==NULL || _bTempNetwork) {
if (_bTempNetwork) {
return; // this can happen during NET_MakeDefaultState_t()!
}
_pTimer->RemHandler(&ga_thTimerHandler);
Expand Down Expand Up @@ -1387,7 +1389,7 @@ void CNetworkLibrary::TogglePause(void)
// test if game is paused
BOOL CNetworkLibrary::IsPaused(void)
{
if (this==NULL || _bTempNetwork) {
if (_bTempNetwork) {
return TRUE; // this can happen during NET_MakeDefaultState_t()!
}
return ga_sesSessionState.ses_bPause;
Expand Down Expand Up @@ -1424,7 +1426,7 @@ void CNetworkLibrary::SetLocalPause(BOOL bPause)

BOOL CNetworkLibrary::GetLocalPause(void)
{
if (this==NULL || _bTempNetwork) {
if (_bTempNetwork) {
return TRUE; // this can happen during NET_MakeDefaultState_t()!
}
return ga_bLocalPause;
Expand Down Expand Up @@ -2031,7 +2033,7 @@ void CNetworkLibrary::SendActionsToServer(void)
*/
void CNetworkLibrary::TimerLoop(void)
{
if (this==NULL || _bTempNetwork) {
if (_bTempNetwork) {
return; // this can happen during NET_MakeDefaultState_t()!
}
_pfNetworkProfile.StartTimer(CNetworkProfile::PTI_TIMERLOOP);
Expand Down
2 changes: 1 addition & 1 deletion Sources/Engine/Network/NetworkMessage.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ class ENGINE_API CNetworkMessage {
void Dump(void);

/* Get the type of this message. */
inline MESSAGETYPE GetType(void) const { ASSERT(this!=NULL); return MESSAGETYPE(nm_mtType&0x3F); };
inline MESSAGETYPE GetType(void) const { return MESSAGETYPE(nm_mtType&0x3F); };
/* Check if end of message. */
BOOL EndOfMessage(void);
// rewind message to start, so that written message can be read again
Expand Down
2 changes: 0 additions & 2 deletions Sources/Engine/Network/SessionState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -906,7 +906,6 @@ void CSessionState::ProcessGameTick(CNetworkMessage &nmMessage, TIME tmCurrentTi
ses_tmLastPredictionProcessed = -1;

_pfPhysicsProfile.StartTimer(CPhysicsProfile::PTI_PROCESSGAMETICK);
ASSERT(this!=NULL);

#if DEBUG_SYNCSTREAMDUMPING
try
Expand Down Expand Up @@ -1027,7 +1026,6 @@ void CSessionState::ProcessGameTick(CNetworkMessage &nmMessage, TIME tmCurrentTi
void CSessionState::ProcessPredictedGameTick(INDEX iPredictionStep, FLOAT fFactor, TIME tmCurrentTick)
{
_pfPhysicsProfile.StartTimer(CPhysicsProfile::PTI_PROCESSGAMETICK);
ASSERT(this!=NULL);

//CPrintF("predicted: %.2f\n", tmCurrentTick);

Expand Down
1 change: 0 additions & 1 deletion Sources/Engine/Ska/ModelInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,6 @@ CModelInstance *CModelInstance::GetChild(INDEX iChildID, BOOL bRecursive/*=FALSE
// returns parent that is not included in his parents smc file
CModelInstance *CModelInstance::GetFirstNonReferencedParent(CModelInstance *pmiRoot)
{
ASSERT(this!=NULL);
ASSERT(pmiRoot!=NULL);
CModelInstance *pmiParent = this->GetParent(pmiRoot);
CModelInstance *pmiLast = this;
Expand Down
8 changes: 4 additions & 4 deletions Sources/Engine/World/World.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -929,10 +929,10 @@ 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;
}
// [Cecil] NOTE: On Linux, clients with prediction crash here if it's called on empty
// entity pointers (but only on Release configurations for some reason, not Debug)
// 'this == NULL' check that exited the function has been removed to avoid confusion

// if already added
if (en_ulFlags&ENF_WILLBEPREDICTED) {
// do nothing
Expand Down
9 changes: 7 additions & 2 deletions Sources/EntitiesMP/Common/PathFinding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ CPathNode::~CPathNode(void)
const CTString &CPathNode::GetName(void)
{
static CTString strNone="<none>";
if (this==NULL || pn_pnmMarker==NULL) {

// [Cecil] NOTE: Removed questionable 'this == NULL' check that hopefully
// isn't needed in the single place where this function is being called from
if (pn_pnmMarker==NULL) {
return strNone;
} else {
return pn_pnmMarker->GetName();
Expand All @@ -61,7 +64,9 @@ 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) {
// [Cecil] NOTE: Removed questionable 'this == NULL' check that hopefully
// isn't needed in the single place where this function is being called from
if (pn_pnmMarker==NULL) {
ASSERT(FALSE);
return NULL;
}
Expand Down
7 changes: 3 additions & 4 deletions Sources/EntitiesMP/EnemyBase.es
Original file line number Diff line number Diff line change
Expand Up @@ -570,10 +570,9 @@ functions:
// add to prediction any entities that this entity depends on
void AddDependentsToPrediction(void)
{
m_penSpray->AddToPrediction();
if (m_penWatcher!=NULL) {
GetWatcher()->AddToPrediction();
}
// [Cecil] Don't call this on NULL
if (m_penSpray != NULL) { m_penSpray->AddToPrediction(); }
if (m_penWatcher != NULL) { m_penWatcher->AddToPrediction(); }
}

// create a checksum value for sync-check
Expand Down
3 changes: 2 additions & 1 deletion Sources/EntitiesMP/Flame.es
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ functions:
// add to prediction any entities that this entity depends on
void AddDependentsToPrediction(void)
{
m_penOwner->AddToPrediction();
// [Cecil] Don't call this on NULL
if (m_penOwner != NULL) { m_penOwner->AddToPrediction(); }
}
// postmoving
void PostMoving(void) {
Expand Down
Loading

0 comments on commit 8ae5d8a

Please sign in to comment.