Remove redundant variable assignments

The assigned values are never used, so the assignments can be removed or variable scopes can be reduced.

According to cppcheck's `unreadVariable` error.
This commit is contained in:
Robert Müller 2022-10-30 13:30:12 +01:00
parent 0a0ddf2145
commit fd208eaa1a
9 changed files with 29 additions and 46 deletions

View file

@ -206,12 +206,10 @@ static void ParseVersionString(EBackendType BackendType, const char *pStr, int &
}
else if(LastWasNumber && (*pStr == '.' || *pStr == ' ' || *pStr == '\0'))
{
int CurNumber = 0;
if(CurNumberStrLen > 0)
{
aCurNumberStr[CurNumberStrLen] = 0;
CurNumber = str_toint(aCurNumberStr);
aNumbers[TotalNumbersPassed++] = CurNumber;
aNumbers[TotalNumbersPassed++] = str_toint(aCurNumberStr);
CurNumberStrLen = 0;
}

View file

@ -181,7 +181,6 @@ bool CDataFileReader::Open(class IStorage *pStorage, const char *pFilename, int
{
io_close(pTmpDataFile->m_File);
free(pTmpDataFile);
pTmpDataFile = 0;
dbg_msg("datafile", "couldn't load the whole thing, wanted=%d got=%d", Size, ReadSize);
return false;
}

View file

@ -213,12 +213,11 @@ int CHuffman::Decompress(const void *pInput, int InputSize, void *pOutput, int O
unsigned Bitcount = 0;
const CNode *pEof = &m_aNodes[HUFFMAN_EOF_SYMBOL];
const CNode *pNode = 0;
while(true)
{
// {A} try to load a node now, this will reduce dependency at location {D}
pNode = 0;
const CNode *pNode = 0;
if(Bitcount >= HUFFMAN_LUTBITS)
pNode = m_apDecodeLut[Bits & HUFFMAN_LUTMASK];

View file

@ -813,9 +813,10 @@ void CHud::RenderPlayerState(const int ClientID)
// pCharacter contains the predicted character for local players or the last snap for players who are spectated
CCharacterCore *pCharacter = &m_pClient->m_aClients[ClientID].m_Predicted;
CNetObj_Character *pPlayer = &m_pClient->m_aClients[ClientID].m_RenderCur;
int TotalJumpsToDisplay = 0, AvailableJumpsToDisplay = 0;
int TotalJumpsToDisplay = 0;
if(g_Config.m_ClShowhudJumpsIndicator)
{
int AvailableJumpsToDisplay;
if(m_pClient->m_Snap.m_aCharacters[ClientID].m_HasExtendedDisplayInfo)
{
bool Grounded = false;
@ -1409,7 +1410,7 @@ void CHud::RenderMovementInformation(const int ClientID)
float y = StartY + LineSpacer * 2;
float xl = StartX + 2;
float xr = m_Width - 2;
int DigitsIndex = 0;
int DigitsIndex;
static float s_TextWidth0 = TextRender()->TextWidth(0, Fontsize, "0.00", -1, -1.0f);
static float s_TextWidth00 = TextRender()->TextWidth(0, Fontsize, "00.00", -1, -1.0f);

View file

@ -282,11 +282,9 @@ void CMenuBackground::LoadMenuBackground(bool HasDayHint, bool HasNightHint)
if(Size >= pTLayer->m_Width * pTLayer->m_Height * TileSize)
{
int x = 0;
int y = 0;
for(y = 0; y < pTLayer->m_Height; ++y)
for(int y = 0; y < pTLayer->m_Height; ++y)
{
for(x = 0; x < pTLayer->m_Width; ++x)
for(int x = 0; x < pTLayer->m_Width; ++x)
{
unsigned char Index = ((CTile *)pTiles)[y * pTLayer->m_Width + x].m_Index;
if(Index >= TILE_TIME_CHECKPOINT_FIRST && Index <= TILE_TIME_CHECKPOINT_LAST)

View file

@ -193,7 +193,6 @@ void CPlayers::RenderHookCollLine(
vec2 NewPos = OldPos;
bool DoBreak = false;
int Hit = 0;
do
{
@ -207,7 +206,7 @@ void CPlayers::RenderHookCollLine(
}
int TeleNr = 0;
Hit = Collision()->IntersectLineTeleHook(OldPos, NewPos, &FinishPos, 0x0, &TeleNr);
int Hit = Collision()->IntersectLineTeleHook(OldPos, NewPos, &FinishPos, 0x0, &TeleNr);
if(!DoBreak && Hit)
{

View file

@ -2295,10 +2295,9 @@ void CGameClient::UpdatePrediction()
vec2 LocalCharPos = vec2(m_Snap.m_pLocalCharacter->m_X, m_Snap.m_pLocalCharacter->m_Y);
m_GameWorld.m_Core.m_aTuning[g_Config.m_ClDummy] = m_aTuning[g_Config.m_ClDummy];
int TuneZone = 0;
if(m_GameWorld.m_WorldConfig.m_UseTuneZones)
{
TuneZone = Collision()->IsTune(Collision()->GetMapIndex(LocalCharPos));
int TuneZone = Collision()->IsTune(Collision()->GetMapIndex(LocalCharPos));
if(TuneZone != m_aLocalTuneZone[g_Config.m_ClDummy])
{

View file

@ -294,13 +294,13 @@ int CCollision::IntersectLine(vec2 Pos0, vec2 Pos1, vec2 *pOutCollision, vec2 *p
float Distance = distance(Pos0, Pos1);
int End(Distance + 1);
vec2 Last = Pos0;
int ix = 0, iy = 0; // Temporary position for checking collision
for(int i = 0; i <= End; i++)
{
float a = i / (float)End;
vec2 Pos = mix(Pos0, Pos1, a);
ix = round_to_int(Pos.x);
iy = round_to_int(Pos.y);
// Temporary position for checking collision
int ix = round_to_int(Pos.x);
int iy = round_to_int(Pos.y);
if(CheckPoint(ix, iy))
{
@ -325,15 +325,15 @@ int CCollision::IntersectLineTeleHook(vec2 Pos0, vec2 Pos1, vec2 *pOutCollision,
float Distance = distance(Pos0, Pos1);
int End(Distance + 1);
vec2 Last = Pos0;
int ix = 0, iy = 0; // Temporary position for checking collision
int dx = 0, dy = 0; // Offset for checking the "through" tile
ThroughOffset(Pos0, Pos1, &dx, &dy);
for(int i = 0; i <= End; i++)
{
float a = i / (float)End;
vec2 Pos = mix(Pos0, Pos1, a);
ix = round_to_int(Pos.x);
iy = round_to_int(Pos.y);
// Temporary position for checking collision
int ix = round_to_int(Pos.x);
int iy = round_to_int(Pos.y);
int Index = GetPureMapIndex(Pos);
if(g_Config.m_SvOldTeleportHook)
@ -382,13 +382,13 @@ int CCollision::IntersectLineTeleWeapon(vec2 Pos0, vec2 Pos1, vec2 *pOutCollisio
float Distance = distance(Pos0, Pos1);
int End(Distance + 1);
vec2 Last = Pos0;
int ix = 0, iy = 0; // Temporary position for checking collision
for(int i = 0; i <= End; i++)
{
float a = i / (float)End;
vec2 Pos = mix(Pos0, Pos1, a);
ix = round_to_int(Pos.x);
iy = round_to_int(Pos.y);
// Temporary position for checking collision
int ix = round_to_int(Pos.x);
int iy = round_to_int(Pos.y);
int Index = GetPureMapIndex(Pos);
if(g_Config.m_SvOldTeleportWeapons)
@ -913,18 +913,14 @@ std::list<int> CCollision::GetMapIndices(vec2 PrevPos, vec2 Pos, unsigned MaxInd
}
else
{
float a = 0.0f;
vec2 Tmp = vec2(0, 0);
int Nx = 0;
int Ny = 0;
int Index, LastIndex = 0;
int LastIndex = 0;
for(int i = 0; i < End; i++)
{
a = i / d;
Tmp = mix(PrevPos, Pos, a);
Nx = clamp((int)Tmp.x / 32, 0, m_Width - 1);
Ny = clamp((int)Tmp.y / 32, 0, m_Height - 1);
Index = Ny * m_Width + Nx;
float a = i / d;
vec2 Tmp = mix(PrevPos, Pos, a);
int Nx = clamp((int)Tmp.x / 32, 0, m_Width - 1);
int Ny = clamp((int)Tmp.y / 32, 0, m_Height - 1);
int Index = Ny * m_Width + Nx;
if(TileExists(Index) && LastIndex != Index)
{
if(MaxIndices && Indices.size() > MaxIndices)
@ -997,17 +993,12 @@ int CCollision::GetIndex(vec2 PrevPos, vec2 Pos) const
}
}
float a = 0.0f;
vec2 Tmp = vec2(0, 0);
int Nx = 0;
int Ny = 0;
for(int i = 0, id = (int)ceilf(Distance); i < id; i++)
{
a = (float)i / Distance;
Tmp = mix(PrevPos, Pos, a);
Nx = clamp((int)Tmp.x / 32, 0, m_Width - 1);
Ny = clamp((int)Tmp.y / 32, 0, m_Height - 1);
float a = (float)i / Distance;
vec2 Tmp = mix(PrevPos, Pos, a);
int Nx = clamp((int)Tmp.x / 32, 0, m_Width - 1);
int Ny = clamp((int)Tmp.y / 32, 0, m_Height - 1);
if((m_pTele) ||
(m_pSpeedup && m_pSpeedup[Ny * m_Width + Nx].m_Force > 0))
{

View file

@ -138,11 +138,10 @@ void Run(unsigned short Port, NETADDR Dest)
}
}
SPacket *p = 0;
SPacket *pNext = g_pFirst;
while(true)
{
p = pNext;
SPacket *p = pNext;
if(!p)
break;
pNext = p->m_pNext;