Skip to content

Commit

Permalink
fixed issues reported by static analyzer
Browse files Browse the repository at this point in the history
  • Loading branch information
s1lentq committed Dec 11, 2024
1 parent 8a77bba commit 6f0d17b
Show file tree
Hide file tree
Showing 17 changed files with 48 additions and 38 deletions.
1 change: 1 addition & 0 deletions regamedll/dlls/bot/cs_bot_chatter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,7 @@ bool BotPhraseManager::Initialize(const char *filename, int bankIndex)
phraseData = SharedParse(phraseData);
if (!phraseData)
{
if (phrase) delete phrase;
CONSOLE_ECHO("Error parsing '%s' - expected identifier\n", filename);
FREE_FILE(phraseDataFile);
return false;
Expand Down
4 changes: 2 additions & 2 deletions regamedll/dlls/career_tasks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ void CCareerTask::OnEvent(GameEventType event, CBasePlayer *pVictim, CBasePlayer

while ((pHostage = UTIL_FindEntityByClassname(pHostage, "hostage_entity")))
{
if (pHostage && pHostage->IsDead())
if (pHostage->IsDead())
hostagesCount++;
}

Expand Down Expand Up @@ -389,14 +389,14 @@ void CCareerTaskManager::Reset(bool deleteTasks)
delete task;

m_tasks.clear();
m_nextId = 0;
}
else
{
for (auto task : m_tasks)
task->Reset();
}

m_nextId = 0;
m_finishedTaskTime = 0;
m_finishedTaskRound = 0;
m_shouldLatchRoundEndMessage = false;
Expand Down
4 changes: 3 additions & 1 deletion regamedll/dlls/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -811,7 +811,9 @@ void Host_Say(edict_t *pEntity, BOOL teamonly)
if (*p == '"')
{
p++;
p[Q_strlen(p) - 1] = '\0';
size_t len = Q_strlen(p);
if (len > 0)
p[len - 1] = '\0';
}

// Check if buffer contains an invalid unicode sequence
Expand Down
2 changes: 0 additions & 2 deletions regamedll/dlls/combat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -285,8 +285,6 @@ void RadiusDamage(Vector vecSrc, entvars_t *pevInflictor, entvars_t *pevAttacker
damageRatio = GetAmountOfPlayerVisible(vecSrc, pEntity);
}

damageRatio = GetAmountOfPlayerVisible(vecSrc, pEntity);

float length;
#ifdef REGAMEDLL_ADD
// allow to damage breakable objects
Expand Down
4 changes: 4 additions & 0 deletions regamedll/dlls/ehandle.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,10 @@ inline edict_t *EntityHandle<T>::Set(edict_t *pEdict)
{
m_serialnumber = pEdict->serialnumber;
}
else
{
m_serialnumber = 0;
}

return pEdict;
}
Expand Down
2 changes: 1 addition & 1 deletion regamedll/dlls/func_tank.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ void CFuncTank::ControllerPostFrame()

Assert(m_pController != nullptr);

if (m_pController->pev->button & IN_ATTACK)
if (m_pController && m_pController->pev->button & IN_ATTACK)
{
Vector vecForward;
UTIL_MakeVectorsPrivate(pev->angles, vecForward, nullptr, nullptr);
Expand Down
2 changes: 1 addition & 1 deletion regamedll/dlls/hostage/hostage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,7 @@ void CHostage::TraceAttack(entvars_t *pevAttacker, float flDamage, Vector vecDir
BOOL CHostage::TakeDamage(entvars_t *pevInflictor, entvars_t *pevAttacker, float flDamage, int bitsDamageType)
{
#ifdef REGAMEDLL_ADD
if (!CanTakeDamage(pevAttacker))
if (pevAttacker && !CanTakeDamage(pevAttacker))
return FALSE;
#endif

Expand Down
2 changes: 1 addition & 1 deletion regamedll/dlls/hostage/states/hostage_idle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ void HostageIdleState::OnUpdate(CHostageImprov *improv)
}
}

if (m_moveState && improv->IsAtMoveGoal())
if (m_moveState != NotMoving && improv->IsAtMoveGoal())
{
m_moveState = NotMoving;

Expand Down
15 changes: 6 additions & 9 deletions regamedll/dlls/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5158,12 +5158,9 @@ void CBasePlayer::UpdatePlayerSound()
m_iExtraSoundTypes = 0;
}

if (pSound)
{
pSound->m_vecOrigin = pev->origin;
pSound->m_iVolume = iVolume;
pSound->m_iType |= (bits_SOUND_PLAYER | m_iExtraSoundTypes);
}
pSound->m_vecOrigin = pev->origin;
pSound->m_iVolume = iVolume;
pSound->m_iType |= (bits_SOUND_PLAYER | m_iExtraSoundTypes);

// keep track of virtual muzzle flash
m_iWeaponFlash -= 256 * gpGlobals->frametime;
Expand Down Expand Up @@ -5913,7 +5910,7 @@ void EXT_FUNC CBasePlayer::__API_HOOK(Spawn)()
TheBots->OnEvent(EVENT_PLAYER_SPAWNED, this);
}

m_allowAutoFollowTime = false;
m_allowAutoFollowTime = 0.0f;

for (i = 0; i < COMMANDS_TO_TRACK; i++)
m_flLastCommandTime[i] = -1;
Expand Down Expand Up @@ -8470,7 +8467,7 @@ void CBasePlayer::__API_HOOK(SwitchTeam)()

UpdateLocation(true);

if (m_iTeam)
if (m_iTeam != UNASSIGNED)
{
SetScoreboardAttributes();
}
Expand Down Expand Up @@ -9682,7 +9679,7 @@ void CBasePlayer::PrioritizeAutoBuyString(char (&autobuyString)[MAX_AUTOBUY_LENG
int newStringPos = 0;
char priorityToken[32];

if (!priorityString || !autobuyString)
if (!priorityString)
return;

const char *priorityChar = priorityString;
Expand Down
4 changes: 2 additions & 2 deletions regamedll/dlls/saverestore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -250,10 +250,10 @@ edict_t *CSaveRestoreBuffer::EntityFromIndex(int entityIndex)

int CSaveRestoreBuffer::EntityFlagsSet(int entityIndex, int flags)
{
if (!m_pData || entityIndex < 0)
if (!m_pData)
return 0;

if (!m_pData || entityIndex < 0 || entityIndex > m_pData->tableCount)
if (entityIndex < 0 || entityIndex > m_pData->tableCount)
return 0;

m_pData->pTable[entityIndex].flags |= flags;
Expand Down
8 changes: 2 additions & 6 deletions regamedll/dlls/sound.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1362,7 +1362,7 @@ void SENTENCEG_Init()

i = 0;

while (rgsentenceg[i].count && i < MAX_SENTENCE_GROUPS)
while (i < MAX_SENTENCE_GROUPS && rgsentenceg[i].count)
{
USENTENCEG_InitLRU(&(rgsentenceg[i].rgblru[0]), rgsentenceg[i].count);
i++;
Expand All @@ -1380,11 +1380,7 @@ int SENTENCEG_Lookup(const char *sample, char (&sentencenum)[32])
{
if (!Q_stricmp(gszallsentencenames[i], sample + 1))
{
if (sentencenum)
{
Q_snprintf(sentencenum, sizeof(sentencenum), "!%d", i);
}

Q_snprintf(sentencenum, sizeof(sentencenum), "!%d", i);
return i;
}
}
Expand Down
2 changes: 1 addition & 1 deletion regamedll/dlls/triggers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,7 @@ void PlayCDTrack(edict_t *pClient, int iTrack)
if (!pClient)
return;

if (iTrack < -1 || iTrack > 30)
if (iTrack < -1 || iTrack >= (int)ARRAYSIZE(g_szMP3trackFileMap))
{
ALERT(at_console, "TriggerCDAudio - Track %d out of range\n", iTrack);
return;
Expand Down
28 changes: 19 additions & 9 deletions regamedll/dlls/vehicle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ void CFuncVehicle::Blocked(CBaseEntity *pOther)

float minz = pev->origin.z;
#ifdef REGAMEDLL_FIXES
float maxz = pev->origin.z + (2 * Q_abs(pev->mins.z - pev->maxs.z));
float maxz = pev->origin.z + (2 * Q_abs(pev->mins.z - pev->maxs.z));
#else
float maxz = pev->origin.z + (2 * Q_abs(int(pev->mins.z - pev->maxs.z)));
#endif
Expand Down Expand Up @@ -343,31 +343,41 @@ void CFuncVehicle::CheckTurning()
if (pev->speed > 0)
{
UTIL_TraceLine(m_vFrontRight, m_vFrontRight - (gpGlobals->v_right * 16.0), ignore_monsters, dont_ignore_glass, ENT(pev), &tr);

if (tr.flFraction != 1.0f)
{
m_iTurnAngle = 1;
}
}
else if (pev->speed < 0)
{
UTIL_TraceLine(m_vBackLeft, m_vBackLeft + (gpGlobals->v_right * 16.0), ignore_monsters, dont_ignore_glass, ENT(pev), &tr);
}

if (tr.flFraction != 1.0f)
{
m_iTurnAngle = 1;
if (tr.flFraction != 1.0f)
{
m_iTurnAngle = 1;
}
}
}
else if (m_iTurnAngle > 0)
{
if (pev->speed > 0)
{
UTIL_TraceLine(m_vFrontLeft, m_vFrontLeft + (gpGlobals->v_right * 16.0), ignore_monsters, dont_ignore_glass, ENT(pev), &tr);

if (tr.flFraction != 1.0f)
{
m_iTurnAngle = -1;
}
}
else if (pev->speed < 0)
{
UTIL_TraceLine(m_vBackRight, m_vBackRight - (gpGlobals->v_right * 16.0), ignore_monsters, dont_ignore_glass, ENT(pev), &tr);
}

if (tr.flFraction != 1.0f)
{
m_iTurnAngle = -1;
if (tr.flFraction != 1.0f)
{
m_iTurnAngle = -1;
}
}
}

Expand Down
2 changes: 0 additions & 2 deletions regamedll/dlls/weapons.h
Original file line number Diff line number Diff line change
Expand Up @@ -1333,7 +1333,6 @@ class CM249: public CBasePlayerWeapon

const float M3_MAX_SPEED = 230.0f;
const float M3_DAMAGE = 20.0f;
const Vector M3_CONE_VECTOR = Vector(0.0675, 0.0675, 0.0); // special shotgun spreads

enum m3_e
{
Expand Down Expand Up @@ -1764,7 +1763,6 @@ class CTMP: public CBasePlayerWeapon

const float XM1014_MAX_SPEED = 240.0f;
const float XM1014_DAMAGE = 20.0f;
const Vector XM1014_CONE_VECTOR = Vector(0.0725, 0.0725, 0.0); // special shotgun spreads

enum xm1014_e
{
Expand Down
2 changes: 2 additions & 0 deletions regamedll/dlls/wpn_shared/wpn_m3.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "precompiled.h"

const Vector M3_CONE_VECTOR = {0.0675, 0.0675, 0.0}; // special shotgun spreads

LINK_ENTITY_TO_CLASS(weapon_m3, CM3, CCSM3)

void CM3::Spawn()
Expand Down
2 changes: 2 additions & 0 deletions regamedll/dlls/wpn_shared/wpn_xm1014.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "precompiled.h"

const Vector XM1014_CONE_VECTOR = {0.0725, 0.0725, 0.0}; // special shotgun spreads

LINK_ENTITY_TO_CLASS(weapon_xm1014, CXM1014, CCSXM1014)

void CXM1014::Spawn()
Expand Down
2 changes: 1 addition & 1 deletion regamedll/game_shared/bot/nav_file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ Place PlaceDirectory::EntryToPlace(EntryType entry) const
return UNDEFINED_PLACE;

unsigned int i = entry - 1;
if (i > m_directory.size())
if (i >= m_directory.size())
{
DbgAssert(false && "PlaceDirectory::EntryToPlace: Invalid entry");
return UNDEFINED_PLACE;
Expand Down

0 comments on commit 6f0d17b

Please sign in to comment.