Fix misleading indentation on several controlled statements

The C++ standard doesn't require us to stuff multiple statements
onto the same line, so we should avoid this for readability reasons.
This is especially true if one of the statements is controlled and
others aren't.
master
Nicolas Hake 2018-12-31 13:45:43 +01:00
parent dca6d2caaf
commit 3edc6d9ead
20 changed files with 125 additions and 57 deletions

View File

@ -19,6 +19,7 @@
#include "C4Version.h"
#include "lib/C4InputValidation.h"
#include <utility>
struct C4GameVersion
{
@ -51,8 +52,11 @@ struct C4GameVersion
inline int CompareVersion(int iVer1, int iVer2,
int iRVer1 = C4XVER1, int iRVer2 = C4XVER2)
{
if (iVer1 > iRVer1) return 1; if (iVer1 < iRVer1) return -1;
if (iVer2 > iRVer2) return 1; if (iVer2 < iRVer2) return -1;
auto ver = std::make_pair(iVer1, iVer2);
auto rVer = std::make_pair(iRVer1, iRVer2);
if (ver < rVer) return -1;
if (ver > rVer) return 1;
return 0;
}

View File

@ -58,8 +58,14 @@ bool C4FacetSurface::Create(int iWdt, int iHgt, int iWdt2, int iHgt2)
Face.Default();
if (!Face.Create(iWdt,iHgt)) return false;
// Set facet
if (iWdt2==C4FCT_Full) iWdt2=Face.Wdt; if (iWdt2==C4FCT_Height) iWdt2=Face.Hgt; if (iWdt2==C4FCT_Width) iWdt2=Face.Wdt;
if (iHgt2==C4FCT_Full) iHgt2=Face.Hgt; if (iHgt2==C4FCT_Height) iHgt2=Face.Hgt; if (iHgt2==C4FCT_Width) iHgt2=Face.Wdt;
if (iWdt2 == C4FCT_Full || iWdt2 == C4FCT_Width)
iWdt2 = Face.Wdt;
else if (iWdt2 == C4FCT_Height)
iWdt2 = Face.Hgt;
if (iHgt2 == C4FCT_Full || iHgt2 == C4FCT_Height)
iHgt2 = Face.Hgt;
else if (iHgt2 == C4FCT_Width)
iHgt2 = Face.Wdt;
Set(&Face,0,0,iWdt2,iHgt2);
return true;
}
@ -96,8 +102,14 @@ bool C4FacetSurface::Load(C4Group &hGroup, const char *szName, int iWdt, int iHg
// Load surface
if (!Face.Load(hGroup,szFilename,false,fNoErrIfNotFound, iFlags)) return false;
// Set facet
if (iWdt==C4FCT_Full) iWdt=Face.Wdt; if (iWdt==C4FCT_Height) iWdt=Face.Hgt; if (iWdt==C4FCT_Width) iWdt=Face.Wdt;
if (iHgt==C4FCT_Full) iHgt=Face.Hgt; if (iHgt==C4FCT_Height) iHgt=Face.Hgt; if (iHgt==C4FCT_Width) iHgt=Face.Wdt;
if (iWdt == C4FCT_Full || iWdt == C4FCT_Width)
iWdt = Face.Wdt;
else if (iWdt == C4FCT_Height)
iWdt = Face.Hgt;
if (iHgt == C4FCT_Full || iHgt == C4FCT_Height)
iHgt = Face.Hgt;
else if (iHgt == C4FCT_Width)
iHgt = Face.Wdt;
Set(&Face,0,0,iWdt,iHgt);
return true;
}

View File

@ -140,7 +140,9 @@ void CPNGFile::Clear()
// clear internal png ptrs
ClearPngStructs();
// free file ptr if owned
if (pFile && fpFileOwned) delete [] pFile; pFile=nullptr;
if (fpFileOwned)
delete [] pFile;
pFile=nullptr;
// reset fields
fpFileOwned=false;
pFilePtr=nullptr;

View File

@ -142,7 +142,8 @@ namespace
d = 2 * dx - dy; aincr = 2 * (dx - dy); bincr = 2 * dx; x = x1; y = y1;
if (!fnCallback(x, y))
{
if (lastx) *lastx = x; if (lasty) *lasty = y;
if (lastx) *lastx = x;
if (lasty) *lasty = y;
return false;
}
for (y = y1 + 1; y <= y2; ++y)
@ -151,7 +152,8 @@ namespace
else d += bincr;
if (!fnCallback(x, y))
{
if (lastx) *lastx = x; if (lasty) *lasty = y;
if (lastx) *lastx = x;
if (lasty) *lasty = y;
return false;
}
}
@ -164,7 +166,8 @@ namespace
d = 2 * dy - dx; aincr = 2 * (dy - dx); bincr = 2 * dy; x = x1; y = y1;
if (!fnCallback(x, y))
{
if (lastx) *lastx = x; if (lasty) *lasty = y;
if (lastx) *lastx = x;
if (lasty) *lasty = y;
return false;
}
for (x = x1 + 1; x <= x2; ++x)
@ -173,7 +176,8 @@ namespace
else d += bincr;
if (!fnCallback(x, y))
{
if (lastx) *lastx = x; if (lasty) *lasty = y;
if (lastx) *lastx = x;
if (lasty) *lasty = y;
return false;
}
}

View File

@ -944,7 +944,7 @@ C4MCParser::~C4MCParser()
void C4MCParser::Clear()
{
// clear code if present
if (Code) delete [] Code; Code=nullptr; BPos = nullptr; CPos=nullptr;
delete [] Code; Code=nullptr; BPos = nullptr; CPos=nullptr;
// reset filename
*Filename=0;
}

View File

@ -373,7 +373,8 @@ C4MapScriptAlgoTurbulence::C4MapScriptAlgoTurbulence(const C4PropList *props) :
if (!seed) seed = Random(65536);
GetXYProps(props, P_Amplitude, amp, true);
GetXYProps(props, P_Scale, scale, true);
if (!scale[0]) scale[0] = 10; if (!scale[1]) scale[1] = 10;
if (!scale[0]) scale[0] = 10;
if (!scale[1]) scale[1] = 10;
if (!amp[0] && !amp[1]) { amp[0] = amp[1] = 10; }
iterations = props->GetPropertyInt(P_Iterations);
if (!iterations) iterations = 2;

View File

@ -312,7 +312,7 @@ C4MaterialMap::~C4MaterialMap()
void C4MaterialMap::Clear()
{
if (Map) delete [] Map; Map=nullptr; Num=0;
delete [] Map; Map=nullptr; Num=0;
delete [] ppReactionMap; ppReactionMap = nullptr;
}

View File

@ -107,8 +107,10 @@ bool OpenExtraLogs()
bool CloseLog()
{
// close
if (C4ShaderLogFile) fclose(C4ShaderLogFile); C4ShaderLogFile = nullptr;
if (C4LogFile) fclose(C4LogFile); C4LogFile = nullptr;
if (C4ShaderLogFile) fclose(C4ShaderLogFile);
C4ShaderLogFile = nullptr;
if (C4LogFile) fclose(C4LogFile);
C4LogFile = nullptr;
// ok
return true;
}

View File

@ -152,7 +152,9 @@ int32_t StrToI32(const char *str, int base, const char **scan_end)
void SCopy(const char *szSource, char *sTarget, size_t iMaxL)
{
if (szSource == sTarget) return;
if (!sTarget) return; *sTarget=0; if (!szSource) return;
if (!sTarget) return;
*sTarget=0;
if (!szSource) return;
while (*szSource && (iMaxL>0))
{ *sTarget=*szSource; iMaxL--; szSource++; sTarget++; }
*sTarget=0;
@ -161,14 +163,18 @@ void SCopy(const char *szSource, char *sTarget, size_t iMaxL)
void SCopy(const char *szSource, char *sTarget)
{
if (szSource == sTarget) return;
if (!sTarget) return; *sTarget=0; if (!szSource) return;
strcpy(sTarget,szSource);
if (!sTarget) return;
*sTarget=0;
if (!szSource) return;
strcpy(sTarget,szSource);
}
void SCopyUntil(const char *szSource, char *sTarget, char cUntil, int iMaxL, int iIndex)
{
if (szSource == sTarget) return;
if (!sTarget) return; *sTarget=0; if (!szSource) return;
if (!sTarget) return;
*sTarget=0;
if (!szSource) return;
while ( *szSource && ((*szSource!=cUntil) || (iIndex>0)) && (iMaxL!=0) )
{ *sTarget=*szSource; if (*szSource==cUntil) iIndex--; szSource++; sTarget++; iMaxL--; }
*sTarget=0;

View File

@ -139,7 +139,9 @@ inline DWORD GetClrModulation(DWORD dwSrcClr, DWORD dwDstClr, DWORD &dwBack)
int bB=sB+(cB*255)/diffN;
dwBack=RGBA(bR, bG, bB, 255);
}
if (!sR) sR=1; if (!sG) sG=1; if (!sB) sB=1;
if (!sR) sR=1;
if (!sG) sG=1;
if (!sB) sB=1;
return RGBA(std::min((int)dR*256/sR, 255), std::min((int)dG*256/sG, 255), std::min((int)dB*256/sB, 255), 255-diffN);
}

View File

@ -2053,7 +2053,8 @@ bool C4Network2::InitLeague(bool *pCancel)
MasterServerAddress.Clear();
Game.Parameters.League.Clear();
Game.Parameters.LeagueAddress.Clear();
if (pLeagueClient) delete pLeagueClient; pLeagueClient = nullptr;
delete pLeagueClient;
pLeagueClient = nullptr;
// Not needed?
if (!Config.Network.MasterServerSignUp && !Config.Network.LeagueServerSignUp)

View File

@ -527,7 +527,8 @@ C4Network2ClientListDlg::C4Network2ClientListDlg()
C4Network2ClientListDlg::~C4Network2ClientListDlg()
{
if (this==pInstance) pInstance=nullptr; Application.Remove(this);
if (this==pInstance) pInstance=nullptr;
Application.Remove(this);
}
void C4Network2ClientListDlg::Update()

View File

@ -831,7 +831,8 @@ bool C4Network2IO::doAutoAccept(const C4ClientCore &CCore, const C4Network2IOCon
bool C4Network2IO::HandlePacket(const C4NetIOPacket &rPacket, C4Network2IOConnection *pConn, bool fThread)
{
// security: add connection reference
if (!pConn) return false; pConn->AddRef();
if (!pConn) return false;
pConn->AddRef();
// accept only PID_Conn and PID_Ping on non-accepted connections
if(!pConn->isHalfAccepted())

View File

@ -625,7 +625,8 @@ bool C4Network2Res::GetStandalone(char *pTo, int32_t iMaxL, bool fSetOfficial, b
if (!fSetOfficial && iSize != Core.getFileSize())
{
// remove file
if (!SEqual(szFile, szStandalone)) EraseItem(szStandalone); szStandalone[0] = '\0';
if (!SEqual(szFile, szStandalone)) EraseItem(szStandalone);
szStandalone[0] = '\0';
// sorry, this version isn't good enough :(
return false;
}
@ -638,7 +639,8 @@ bool C4Network2Res::GetStandalone(char *pTo, int32_t iMaxL, bool fSetOfficial, b
if (!fSetOfficial && iCRC32 != Core.getFileCRC())
{
// remove file, return
if (!SEqual(szFile, szStandalone)) EraseItem(szStandalone); szStandalone[0] = '\0';
if (!SEqual(szFile, szStandalone)) EraseItem(szStandalone);
szStandalone[0] = '\0';
return false;
}

View File

@ -221,7 +221,8 @@ void C4IDPacket::Default()
void C4IDPacket::Clear()
{
if (fOwnPkt) delete pPkt; pPkt = nullptr;
if (fOwnPkt) delete pPkt;
pPkt = nullptr;
eID = PID_None;
}
@ -235,7 +236,8 @@ void C4IDPacket::CompileFunc(StdCompiler *pComp)
if (!pComp->Name(getPktName()))
{ pComp->excCorrupt("C4IDPacket: Data value needed! Packet data missing!"); return; }
// Delete old packet
if (fOwnPkt) delete pPkt; pPkt = nullptr;
if (fOwnPkt) delete pPkt;
pPkt = nullptr;
if (eID == PID_None) return;
// Search unpacking function
for (const C4PktHandlingData *pPData = PktHandlingData; pPData->ID != PID_None; pPData++)

View File

@ -1464,7 +1464,8 @@ void C4Command::Clear()
Ty=0;
Target=Target2=nullptr;
UpdateInterval=0;
if (Text) Text->DecRef(); Text=nullptr;
if (Text) Text->DecRef();
Text=nullptr;
BaseMode=C4CMD_Mode_SilentSub;
}

View File

@ -327,9 +327,19 @@ void C4Def::Clear()
Graphics.Clear();
StringTable.Clear();
if (pClonkNames && fClonkNamesOwned) delete pClonkNames; pClonkNames=nullptr;
if (pRankNames && fRankNamesOwned) delete pRankNames; pRankNames=nullptr;
if (pRankSymbols && fRankSymbolsOwned) delete pRankSymbols; pRankSymbols=nullptr;
if (fClonkNamesOwned)
delete pClonkNames;
pClonkNames = nullptr;
if (fRankNamesOwned)
delete pRankNames;
pRankNames = nullptr;
if (fRankSymbolsOwned)
delete pRankSymbols;
pRankSymbols = nullptr;
fClonkNamesOwned = fRankNamesOwned = fRankSymbolsOwned = false;
delete pSolidMask; pSolidMask = nullptr;
}
@ -528,7 +538,7 @@ void C4Def::LoadScript(C4Group &hGroup, const char* szLanguage)
void C4Def::LoadClonkNames(C4Group &hGroup, C4ComponentHost* pClonkNames, const char* szLanguage)
{
// clear any previous
if (pClonkNames) delete pClonkNames; pClonkNames = nullptr;
delete pClonkNames; pClonkNames = nullptr;
if (hGroup.FindEntry(C4CFN_ClonkNameFiles))
{
// create new
@ -545,7 +555,7 @@ void C4Def::LoadClonkNames(C4Group &hGroup, C4ComponentHost* pClonkNames, const
void C4Def::LoadRankNames(C4Group &hGroup, const char* szLanguage)
{
// clear any previous
if (pRankNames) delete pRankNames; pRankNames = nullptr;
delete pRankNames; pRankNames = nullptr;
if (hGroup.FindEntry(C4CFN_RankNameFiles))
{
// create new
@ -563,7 +573,7 @@ void C4Def::LoadRankNames(C4Group &hGroup, const char* szLanguage)
void C4Def::LoadRankFaces(C4Group &hGroup)
{
// clear any previous
if (pRankSymbols) delete pRankSymbols; pRankSymbols = nullptr;
delete pRankSymbols; pRankSymbols = nullptr;
// load new
if (hGroup.AccessEntry(C4CFN_RankFacesPNG))
{

View File

@ -2437,19 +2437,19 @@ void C4Object::Clear()
{
ClearParticleLists();
if (pEffects) { delete pEffects; pEffects=nullptr; }
if (pSolidMaskData) { delete pSolidMaskData; pSolidMaskData=nullptr; }
if (Menu) delete Menu; Menu=nullptr;
if (MaterialContents) delete MaterialContents; MaterialContents=nullptr;
delete pEffects; pEffects = nullptr;
delete pSolidMaskData; pSolidMaskData = nullptr;
delete Menu; Menu = nullptr;
delete MaterialContents; MaterialContents = nullptr;
// clear commands!
C4Command *pCom, *pNext;
for (pCom=Command; pCom; pCom=pNext)
{
pNext=pCom->Next; delete pCom; pCom=pNext;
}
if (pDrawTransform) { delete pDrawTransform; pDrawTransform=nullptr; }
if (pGfxOverlay) { delete pGfxOverlay; pGfxOverlay=nullptr; }
if (pMeshInstance) { delete pMeshInstance; pMeshInstance = nullptr; }
delete pDrawTransform; pDrawTransform = nullptr;
delete pGfxOverlay; pGfxOverlay = nullptr;
delete pMeshInstance; pMeshInstance = nullptr;
}
bool C4Object::MenuCommand(const char *szCommand)
@ -2504,7 +2504,7 @@ void C4Object::SyncClearance()
// Menu
CloseMenu(true);
// Material contents
if (MaterialContents) delete MaterialContents; MaterialContents=nullptr;
delete MaterialContents; MaterialContents=nullptr;
// reset speed of staticback-objects
if (Category & C4D_StaticBack)
{
@ -3430,11 +3430,13 @@ void C4Object::ExecAction()
case COMD_Up: case COMD_UpRight: case COMD_UpLeft:
if (ydir > 0) ydir -= decel;
else ydir -= accel;
if (ydir < -limit) ydir = -limit; break;
if (ydir < -limit) ydir = -limit;
break;
case COMD_Down: case COMD_DownRight: case COMD_DownLeft:
if (ydir < 0) ydir += decel;
else ydir += accel;
if (ydir > +limit) ydir = +limit; break;
if (ydir > +limit) ydir = +limit;
break;
case COMD_Left: case COMD_Right: case COMD_Stop:
if (ydir < 0) ydir += decel;
if (ydir > 0) ydir -= decel;
@ -3561,8 +3563,8 @@ void C4Object::ExecAction()
// xdir/ydir bounds, don't apply if COMD_None
if (Action.ComDir != COMD_None)
{
if (ydir<-limit) ydir=-limit; if (ydir>+limit) ydir=+limit;
if (xdir>+limit) xdir=+limit; if (xdir<-limit) xdir=-limit;
ydir = Clamp(ydir, -limit, limit);
xdir = Clamp(xdir, -limit, limit);
}
// Surface dir bound
if (!GBackLiquid(GetX(),GetY()-1+Def->Float*Con/FullCon-1)) if (ydir<0) ydir=0;
@ -3635,8 +3637,17 @@ void C4Object::ExecAction()
if (GetY()-iPushDistance > say+sahgt && iTXDir) { if (iTXDir>0) sax+=sawdt/2; sawdt/=2; }
// Horizontal follow
iTargetX=Clamp(GetX(),sax-iPushDistance,sax+sawdt-1+iPushDistance);
if (GetX()==iTargetX) xdir=0;
else { if (GetX()<iTargetX) xdir=+limit; if (GetX()>iTargetX) xdir=-limit; }
if (GetX()==iTargetX)
{
xdir=0;
}
else
{
if (GetX()<iTargetX)
xdir=+limit;
else if (GetX()>iTargetX)
xdir=-limit;
}
// Phase by XDir
iPhaseAdvance=0;
if (xdir<0) { iPhaseAdvance=-fixtoi(xdir*10); SetDir(DIR_Left); }
@ -3794,8 +3805,8 @@ void C4Object::ExecAction()
// xdir/ydir bounds, don't apply if COMD_None
if (Action.ComDir != COMD_None)
{
if (ydir<-limit) ydir=-limit; if (ydir>+limit) ydir=+limit;
if (xdir>+limit) xdir=+limit; if (xdir<-limit) xdir=-limit;
ydir = Clamp(ydir, -limit, limit);
xdir = Clamp(xdir, -limit, limit);
}
Mobile=true;
@ -4111,7 +4122,8 @@ bool C4Object::IsInLiquidCheck() const
void C4Object::SetRotation(int32_t nr)
{
while (nr<0) nr+=360; nr%=360;
while (nr<0) nr+=360;
nr%=360;
// remove solid mask
if (pSolidMaskData) pSolidMaskData->Remove(false);
// set rotation
@ -4194,7 +4206,8 @@ bool C4Object::Collect(C4Object *pObj)
bool C4Object::GrabInfo(C4Object *pFrom)
{
// safety
if (!pFrom) return false; if (!Status || !pFrom->Status) return false;
if (!pFrom) return false;
if (!Status || !pFrom->Status) return false;
// even more safety (own info: success)
if (pFrom == this) return true;
// only if other object has info

View File

@ -115,7 +115,8 @@ static bool FnPunch(C4Object *Obj, C4Object *target, long punch)
static bool FnKill(C4PropList * _this, C4Object *pObj, bool fForced)
{
if (!pObj) pObj=Object(_this); if (!pObj) return false;
if (!pObj) pObj=Object(_this);
if (!pObj) return false;
if (!pObj->GetAlive()) return false;
// Trace kills by player-owned objects
// Do not trace for NO_OWNER, because that would include e.g. the Suicide-rule
@ -1274,7 +1275,8 @@ static long FnSetTransferZone(C4Object *Obj, long iX, long iY, long iWdt, long i
static long FnObjectDistance(C4PropList * _this, C4Object *pObj2, C4Object *pObj)
{
if (!pObj) pObj=Object(_this); if (!pObj || !pObj2) return 0;
if (!pObj) pObj=Object(_this);
if (!pObj || !pObj2) return 0;
return Distance(pObj->GetX(),pObj->GetY(),pObj2->GetX(),pObj2->GetY());
}
@ -1286,7 +1288,8 @@ static long FnObjectNumber(C4Object *Obj)
static long FnShowInfo(C4Object *Obj, C4Object *pObj)
{
if (!pObj) pObj=Obj; if (!pObj) return false;
if (!pObj) pObj=Obj;
if (!pObj) return false;
return Obj->ActivateMenu(C4MN_Info,0,0,0,pObj);
}

View File

@ -1515,7 +1515,8 @@ int32_t C4Player::GetSelectedCrewCount()
void C4Player::EvaluateLeague(bool fDisconnected, bool fWon)
{
// already evaluated?
if (LeagueEvaluated) return; LeagueEvaluated=true;
if (LeagueEvaluated) return;
LeagueEvaluated=true;
// set fate
C4PlayerInfo *pInfo = GetInfo();
if (pInfo)