From 6f0d17bb74e8bccc16a2834829cb07c265f7086c Mon Sep 17 00:00:00 2001 From: s1lentq Date: Wed, 11 Dec 2024 23:30:27 +0700 Subject: [PATCH] fixed issues reported by static analyzer --- regamedll/dlls/bot/cs_bot_chatter.cpp | 1 + regamedll/dlls/career_tasks.cpp | 4 +-- regamedll/dlls/client.cpp | 4 ++- regamedll/dlls/combat.cpp | 2 -- regamedll/dlls/ehandle.h | 4 +++ regamedll/dlls/func_tank.cpp | 2 +- regamedll/dlls/hostage/hostage.cpp | 2 +- .../dlls/hostage/states/hostage_idle.cpp | 2 +- regamedll/dlls/player.cpp | 15 ++++------ regamedll/dlls/saverestore.cpp | 4 +-- regamedll/dlls/sound.cpp | 8 ++---- regamedll/dlls/triggers.cpp | 2 +- regamedll/dlls/vehicle.cpp | 28 +++++++++++++------ regamedll/dlls/weapons.h | 2 -- regamedll/dlls/wpn_shared/wpn_m3.cpp | 2 ++ regamedll/dlls/wpn_shared/wpn_xm1014.cpp | 2 ++ regamedll/game_shared/bot/nav_file.cpp | 2 +- 17 files changed, 48 insertions(+), 38 deletions(-) diff --git a/regamedll/dlls/bot/cs_bot_chatter.cpp b/regamedll/dlls/bot/cs_bot_chatter.cpp index 1476d8d58..f58759fe5 100644 --- a/regamedll/dlls/bot/cs_bot_chatter.cpp +++ b/regamedll/dlls/bot/cs_bot_chatter.cpp @@ -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; diff --git a/regamedll/dlls/career_tasks.cpp b/regamedll/dlls/career_tasks.cpp index 972ccca9b..050a9aab0 100644 --- a/regamedll/dlls/career_tasks.cpp +++ b/regamedll/dlls/career_tasks.cpp @@ -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++; } @@ -389,7 +389,6 @@ void CCareerTaskManager::Reset(bool deleteTasks) delete task; m_tasks.clear(); - m_nextId = 0; } else { @@ -397,6 +396,7 @@ void CCareerTaskManager::Reset(bool deleteTasks) task->Reset(); } + m_nextId = 0; m_finishedTaskTime = 0; m_finishedTaskRound = 0; m_shouldLatchRoundEndMessage = false; diff --git a/regamedll/dlls/client.cpp b/regamedll/dlls/client.cpp index 198afbfbe..08efa0391 100644 --- a/regamedll/dlls/client.cpp +++ b/regamedll/dlls/client.cpp @@ -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 diff --git a/regamedll/dlls/combat.cpp b/regamedll/dlls/combat.cpp index 17fe84e27..8c66a4754 100644 --- a/regamedll/dlls/combat.cpp +++ b/regamedll/dlls/combat.cpp @@ -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 diff --git a/regamedll/dlls/ehandle.h b/regamedll/dlls/ehandle.h index 9a8717826..61d22a5cc 100644 --- a/regamedll/dlls/ehandle.h +++ b/regamedll/dlls/ehandle.h @@ -130,6 +130,10 @@ inline edict_t *EntityHandle::Set(edict_t *pEdict) { m_serialnumber = pEdict->serialnumber; } + else + { + m_serialnumber = 0; + } return pEdict; } diff --git a/regamedll/dlls/func_tank.cpp b/regamedll/dlls/func_tank.cpp index e12c90768..14c2ef6fc 100644 --- a/regamedll/dlls/func_tank.cpp +++ b/regamedll/dlls/func_tank.cpp @@ -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); diff --git a/regamedll/dlls/hostage/hostage.cpp b/regamedll/dlls/hostage/hostage.cpp index e3ddd6750..91c430189 100644 --- a/regamedll/dlls/hostage/hostage.cpp +++ b/regamedll/dlls/hostage/hostage.cpp @@ -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 diff --git a/regamedll/dlls/hostage/states/hostage_idle.cpp b/regamedll/dlls/hostage/states/hostage_idle.cpp index c2c311a15..618848fc8 100644 --- a/regamedll/dlls/hostage/states/hostage_idle.cpp +++ b/regamedll/dlls/hostage/states/hostage_idle.cpp @@ -78,7 +78,7 @@ void HostageIdleState::OnUpdate(CHostageImprov *improv) } } - if (m_moveState && improv->IsAtMoveGoal()) + if (m_moveState != NotMoving && improv->IsAtMoveGoal()) { m_moveState = NotMoving; diff --git a/regamedll/dlls/player.cpp b/regamedll/dlls/player.cpp index 5295943a2..95acb8436 100644 --- a/regamedll/dlls/player.cpp +++ b/regamedll/dlls/player.cpp @@ -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; @@ -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; @@ -8470,7 +8467,7 @@ void CBasePlayer::__API_HOOK(SwitchTeam)() UpdateLocation(true); - if (m_iTeam) + if (m_iTeam != UNASSIGNED) { SetScoreboardAttributes(); } @@ -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; diff --git a/regamedll/dlls/saverestore.cpp b/regamedll/dlls/saverestore.cpp index 897452c4f..514ca64b8 100644 --- a/regamedll/dlls/saverestore.cpp +++ b/regamedll/dlls/saverestore.cpp @@ -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; diff --git a/regamedll/dlls/sound.cpp b/regamedll/dlls/sound.cpp index a4dc0a7d6..25e930e3d 100644 --- a/regamedll/dlls/sound.cpp +++ b/regamedll/dlls/sound.cpp @@ -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++; @@ -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; } } diff --git a/regamedll/dlls/triggers.cpp b/regamedll/dlls/triggers.cpp index 1bfd85b94..42e5cbdec 100644 --- a/regamedll/dlls/triggers.cpp +++ b/regamedll/dlls/triggers.cpp @@ -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; diff --git a/regamedll/dlls/vehicle.cpp b/regamedll/dlls/vehicle.cpp index 3ff84b941..7bf2d4184 100644 --- a/regamedll/dlls/vehicle.cpp +++ b/regamedll/dlls/vehicle.cpp @@ -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 @@ -343,15 +343,20 @@ 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) @@ -359,15 +364,20 @@ void CFuncVehicle::CheckTurning() 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; + } } } diff --git a/regamedll/dlls/weapons.h b/regamedll/dlls/weapons.h index 9266d8434..252c4c5f1 100644 --- a/regamedll/dlls/weapons.h +++ b/regamedll/dlls/weapons.h @@ -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 { @@ -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 { diff --git a/regamedll/dlls/wpn_shared/wpn_m3.cpp b/regamedll/dlls/wpn_shared/wpn_m3.cpp index 64ad7c5f0..e071c19c5 100644 --- a/regamedll/dlls/wpn_shared/wpn_m3.cpp +++ b/regamedll/dlls/wpn_shared/wpn_m3.cpp @@ -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() diff --git a/regamedll/dlls/wpn_shared/wpn_xm1014.cpp b/regamedll/dlls/wpn_shared/wpn_xm1014.cpp index a4e4304eb..fb63a0507 100644 --- a/regamedll/dlls/wpn_shared/wpn_xm1014.cpp +++ b/regamedll/dlls/wpn_shared/wpn_xm1014.cpp @@ -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() diff --git a/regamedll/game_shared/bot/nav_file.cpp b/regamedll/game_shared/bot/nav_file.cpp index 5c6d65c38..cf97f6f6a 100644 --- a/regamedll/game_shared/bot/nav_file.cpp +++ b/regamedll/game_shared/bot/nav_file.cpp @@ -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;