feat(CI): add cppcheck (#15211)

Co-authored-by: Skjalf <47818697+Nyeriah@users.noreply.github.com>
This commit is contained in:
Stefano Borzì
2023-03-05 18:47:18 +01:00
committed by GitHub
parent a5b4aecd52
commit 034b521501
22 changed files with 91 additions and 41 deletions

36
.github/workflows/cpp-check.yml vendored Normal file
View File

@@ -0,0 +1,36 @@
name: cpp-check
on:
push:
branches:
- "master"
paths:
- src/**
- "!README.md"
- "!docs/**"
pull_request:
paths:
- src/**
- "!README.md"
- "!docs/**"
jobs:
cpp-check:
strategy:
fail-fast: false
runs-on: ubuntu-22.04
name: cpp check
steps:
- uses: actions/checkout@v2
- name: cpp check
run: |
sudo apt update -y
sudo apt install -y cppcheck
cppcheck --force --inline-suppr \
-i src/server/game/Achievements/AchievementMgr.cpp \
-i src/server/game/AuctionHouse/AuctionHouseMgr.cpp \
-i src/server/game/Battlegrounds/Zones/BattlegroundSA.cpp \
-i src/server/game/DungeonFinding/LFGMgr.cpp \
-i src/server/game/Entities/GameObject/GameObject.cpp \
-i src/server/game/Entities/Pet/Pet.cpp \
-i src/server/game/Entities/Player/Player.cpp \
src/

View File

@@ -26,6 +26,7 @@
void BIH::buildHierarchy(std::vector<uint32>& tempTree, buildData& dat, BuildStats& stats) void BIH::buildHierarchy(std::vector<uint32>& tempTree, buildData& dat, BuildStats& stats)
{ {
// create space for the first node // create space for the first node
// cppcheck-suppress integerOverflow
tempTree.push_back(uint32(3 << 30)); // dummy leaf tempTree.push_back(uint32(3 << 30)); // dummy leaf
tempTree.insert(tempTree.end(), 2, 0); tempTree.insert(tempTree.end(), 2, 0);
//tempTree.add(0); //tempTree.add(0);

View File

@@ -187,9 +187,9 @@ public:
while (true) while (true)
{ {
uint32 tn = tree[node]; uint32 tn = tree[node];
uint32 axis = (tn & (3 << 30)) >> 30; uint32 axis = (tn & (3 << 30)) >> 30; // cppcheck-suppress integerOverflow
bool BVH2 = tn & (1 << 29); bool BVH2 = tn & (1 << 29); // cppcheck-suppress integerOverflow
int offset = tn & ~(7 << 29); int offset = tn & ~(7 << 29); // cppcheck-suppress integerOverflow
if (!BVH2) if (!BVH2)
{ {
if (axis < 3) if (axis < 3)
@@ -297,9 +297,9 @@ public:
while (true) while (true)
{ {
uint32 tn = tree[node]; uint32 tn = tree[node];
uint32 axis = (tn & (3 << 30)) >> 30; uint32 axis = (tn & (3 << 30)) >> 30; // cppcheck-suppress integerOverflow
bool BVH2 = tn & (1 << 29); bool BVH2 = tn & (1 << 29); // cppcheck-suppress integerOverflow
int offset = tn & ~(7 << 29); int offset = tn & ~(7 << 29); // cppcheck-suppress integerOverflow
if (!BVH2) if (!BVH2)
{ {
if (axis < 3) if (axis < 3)
@@ -425,7 +425,7 @@ protected:
void createNode(std::vector<uint32>& tempTree, int nodeIndex, uint32 left, uint32 right) const void createNode(std::vector<uint32>& tempTree, int nodeIndex, uint32 left, uint32 right) const
{ {
// write leaf node // write leaf node
tempTree[nodeIndex + 0] = (3 << 30) | left; tempTree[nodeIndex + 0] = (3 << 30) | left; // cppcheck-suppress integerOverflow
tempTree[nodeIndex + 1] = right - left + 1; tempTree[nodeIndex + 1] = right - left + 1;
} }

View File

@@ -42,6 +42,7 @@ SERVICE_STATUS serviceStatus;
SERVICE_STATUS_HANDLE serviceStatusHandle = 0; SERVICE_STATUS_HANDLE serviceStatusHandle = 0;
// cppcheck-suppress syntaxError
typedef WINADVAPI BOOL (WINAPI* CSD_T)(SC_HANDLE, DWORD, LPCVOID); typedef WINADVAPI BOOL (WINAPI* CSD_T)(SC_HANDLE, DWORD, LPCVOID);
bool WinServiceInstall() bool WinServiceInstall()

View File

@@ -110,7 +110,7 @@ bool TransactionTask::Execute()
// Make sure only 1 async thread retries a transaction so they don't keep dead-locking each other // Make sure only 1 async thread retries a transaction so they don't keep dead-locking each other
std::lock_guard<std::mutex> lock(_deadlockLock); std::lock_guard<std::mutex> lock(_deadlockLock);
for (Milliseconds loopDuration = 0s, startMSTime = GetTimeMS(); loopDuration <= DEADLOCK_MAX_RETRY_TIME_MS; loopDuration = GetMSTimeDiffToNow(startMSTime)) for (Milliseconds loopDuration{}, startMSTime = GetTimeMS(); loopDuration <= DEADLOCK_MAX_RETRY_TIME_MS; loopDuration = GetMSTimeDiffToNow(startMSTime))
{ {
if (!TryExecute()) if (!TryExecute())
return true; return true;
@@ -157,7 +157,7 @@ bool TransactionWithResultTask::Execute()
// Make sure only 1 async thread retries a transaction so they don't keep dead-locking each other // Make sure only 1 async thread retries a transaction so they don't keep dead-locking each other
std::lock_guard<std::mutex> lock(_deadlockLock); std::lock_guard<std::mutex> lock(_deadlockLock);
for (Milliseconds loopDuration = 0s, startMSTime = GetTimeMS(); loopDuration <= DEADLOCK_MAX_RETRY_TIME_MS; loopDuration = GetMSTimeDiffToNow(startMSTime)) for (Milliseconds loopDuration{}, startMSTime = GetTimeMS(); loopDuration <= DEADLOCK_MAX_RETRY_TIME_MS; loopDuration = GetMSTimeDiffToNow(startMSTime))
{ {
if (!TryExecute()) if (!TryExecute())
{ {

View File

@@ -129,12 +129,12 @@ void AutobroadcastMgr::SendAutobroadcasts()
LOG_DEBUG("autobroadcast", "AutobroadcastMgr::SendAutobroadcasts: '{}'", msg); LOG_DEBUG("autobroadcast", "AutobroadcastMgr::SendAutobroadcasts: '{}'", msg);
} }
void AutobroadcastMgr::SendWorldAnnouncement(std::string_view msg) void AutobroadcastMgr::SendWorldAnnouncement(std::string msg)
{ {
sWorld->SendWorldTextOptional(LANG_AUTO_BROADCAST, ANNOUNCER_FLAG_DISABLE_AUTOBROADCAST, msg.data()); sWorld->SendWorldTextOptional(LANG_AUTO_BROADCAST, ANNOUNCER_FLAG_DISABLE_AUTOBROADCAST, msg.data());
} }
void AutobroadcastMgr::SendNotificationAnnouncement(std::string_view msg) void AutobroadcastMgr::SendNotificationAnnouncement(std::string msg)
{ {
WorldPacket data(SMSG_NOTIFICATION, (msg.size() + 1)); WorldPacket data(SMSG_NOTIFICATION, (msg.size() + 1));
data << msg.data(); data << msg.data();

View File

@@ -37,8 +37,8 @@ public:
void SendAutobroadcasts(); void SendAutobroadcasts();
private: private:
void SendWorldAnnouncement(std::string_view msg); void SendWorldAnnouncement(std::string msg);
void SendNotificationAnnouncement(std::string_view msg); void SendNotificationAnnouncement(std::string msg);
typedef std::map<uint8, std::string> AutobroadcastsMap; typedef std::map<uint8, std::string> AutobroadcastsMap;
typedef std::map<uint8, uint8> AutobroadcastsWeightMap; typedef std::map<uint8, uint8> AutobroadcastsWeightMap;

View File

@@ -895,8 +895,8 @@ void BattlegroundQueue::BattlegroundQueueUpdate(uint32 diff, BattlegroundTypeId
{ {
if (!(*itr3)->IsInvitedToBGInstanceGUID if (!(*itr3)->IsInvitedToBGInstanceGUID
&& (((*itr3)->ArenaMatchmakerRating >= arenaMinRating && (*itr3)->ArenaMatchmakerRating <= arenaMaxRating) || (int32)(*itr3)->JoinTime < discardTime) && (((*itr3)->ArenaMatchmakerRating >= arenaMinRating && (*itr3)->ArenaMatchmakerRating <= arenaMaxRating) || (int32)(*itr3)->JoinTime < discardTime)
&& ((*itr_teams[0])->ArenaTeamId != (*itr3)->PreviousOpponentsTeamId || ((int32)(*itr3)->JoinTime < discardOpponentsTime)) && ((*(itr_teams[0]))->ArenaTeamId != (*itr3)->PreviousOpponentsTeamId || ((int32)(*itr3)->JoinTime < discardOpponentsTime))
&& (*itr_teams[0])->ArenaTeamId != (*itr3)->ArenaTeamId) && (*(itr_teams[0]))->ArenaTeamId != (*itr3)->ArenaTeamId)
{ {
itr_teams[found++] = itr3; itr_teams[found++] = itr3;
break; break;
@@ -907,8 +907,8 @@ void BattlegroundQueue::BattlegroundQueueUpdate(uint32 diff, BattlegroundTypeId
//if we have 2 teams, then start new arena and invite players! //if we have 2 teams, then start new arena and invite players!
if (found == 2) if (found == 2)
{ {
GroupQueueInfo* aTeam = *itr_teams[TEAM_ALLIANCE]; GroupQueueInfo* aTeam = *(itr_teams[TEAM_ALLIANCE]);
GroupQueueInfo* hTeam = *itr_teams[TEAM_HORDE]; GroupQueueInfo* hTeam = *(itr_teams[TEAM_HORDE]);
Battleground* arena = sBattlegroundMgr->CreateNewBattleground(bgTypeId, bracketEntry, arenaType, true); Battleground* arena = sBattlegroundMgr->CreateNewBattleground(bgTypeId, bracketEntry, arenaType, true);
if (!arena) if (!arena)

View File

@@ -1310,6 +1310,7 @@ bool Player::SatisfyQuestSeasonal(Quest const* qInfo, bool /*msg*/) const
if (!qInfo->IsSeasonal() || m_seasonalquests.empty()) if (!qInfo->IsSeasonal() || m_seasonalquests.empty())
return true; return true;
// cppcheck-suppress mismatchingContainers
Player::SeasonalEventQuestMap::iterator itr = ((Player*)this)->m_seasonalquests.find(qInfo->GetEventIdForQuest()); Player::SeasonalEventQuestMap::iterator itr = ((Player*)this)->m_seasonalquests.find(qInfo->GetEventIdForQuest());
if (itr == m_seasonalquests.end() || itr->second.empty()) if (itr == m_seasonalquests.end() || itr->second.empty())

View File

@@ -190,6 +190,7 @@ uint32 LootStore::LoadLootTable()
// Looking for the template of the entry // Looking for the template of the entry
// often entries are put together // often entries are put together
// cppcheck-suppress eraseDereference
if (m_LootTemplates.empty() || tab->first != entry) if (m_LootTemplates.empty() || tab->first != entry)
{ {
// Searching the template (in case template Id changed) // Searching the template (in case template Id changed)

View File

@@ -121,13 +121,13 @@ public:
}; };
}; };
struct Wave struct WaveCreature
{ {
uint32 entry; uint32 entry;
uint32 amount; uint32 amount;
}; };
static Wave RingMobs[] = // different amounts based on the type static WaveCreature RingMobs[] = // different amounts based on the type
{ {
{NPC_DREDGE_WORM, 3}, {NPC_DREDGE_WORM, 3},
{NPC_DEEP_STINGER, 3}, {NPC_DEEP_STINGER, 3},

View File

@@ -49,18 +49,18 @@ enum Rinji
GO_RINJI_CAGE = 142036 GO_RINJI_CAGE = 142036
}; };
struct Location struct LocationXYZ
{ {
float posX, posY, posZ; float x, y, z;
}; };
Location AmbushSpawn[] = LocationXYZ AmbushSpawn[] =
{ {
{ 191.296204f, -2839.329346f, 107.388f }, { 191.296204f, -2839.329346f, 107.388f },
{ 70.972466f, -2848.674805f, 109.459f } { 70.972466f, -2848.674805f, 109.459f }
}; };
Location AmbushMoveTo[] = LocationXYZ AmbushMoveTo[] =
{ {
{ 166.630386f, -2824.780273f, 108.153f }, { 166.630386f, -2824.780273f, 108.153f },
{ 70.886589f, -2874.335449f, 116.675f } { 70.886589f, -2874.335449f, 116.675f }
@@ -118,12 +118,12 @@ public:
if (!_first) if (!_first)
spawnId = 1; spawnId = 1;
me->SummonCreature(NPC_RANGER, AmbushSpawn[spawnId].posX, AmbushSpawn[spawnId].posY, AmbushSpawn[spawnId].posZ, 0.0f, me->SummonCreature(NPC_RANGER, AmbushSpawn[spawnId].x, AmbushSpawn[spawnId].y, AmbushSpawn[spawnId].z, 0.0f,
TEMPSUMMON_TIMED_OR_CORPSE_DESPAWN, 60000); TEMPSUMMON_TIMED_OR_CORPSE_DESPAWN, 60000);
for (int i = 0; i < 2; ++i) for (int i = 0; i < 2; ++i)
{ {
me->SummonCreature(NPC_OUTRUNNER, AmbushSpawn[spawnId].posX, AmbushSpawn[spawnId].posY, AmbushSpawn[spawnId].posZ, 0.0f, me->SummonCreature(NPC_OUTRUNNER, AmbushSpawn[spawnId].x, AmbushSpawn[spawnId].y, AmbushSpawn[spawnId].z, 0.0f,
TEMPSUMMON_TIMED_OR_CORPSE_DESPAWN, 60000); TEMPSUMMON_TIMED_OR_CORPSE_DESPAWN, 60000);
} }
} }
@@ -131,7 +131,7 @@ public:
void JustSummoned(Creature* summoned) override void JustSummoned(Creature* summoned) override
{ {
summoned->SetWalk(false); summoned->SetWalk(false);
summoned->GetMotionMaster()->MovePoint(0, AmbushMoveTo[spawnId].posX, AmbushMoveTo[spawnId].posY, AmbushMoveTo[spawnId].posZ); summoned->GetMotionMaster()->MovePoint(0, AmbushMoveTo[spawnId].x, AmbushMoveTo[spawnId].y, AmbushMoveTo[spawnId].z);
} }
void sQuestAccept(Player* player, Quest const* quest) override void sQuestAccept(Player* player, Quest const* quest) override

View File

@@ -748,12 +748,11 @@ enum Worldstates
WORLD_STATE_FAIL_H = 3878 WORLD_STATE_FAIL_H = 3878
}; };
struct Location struct LocationXYZO {
{
float x, y, z, o; float x, y, z, o;
}; };
static Location AllianceSpawn[] = static LocationXYZO AllianceSpawn[] =
{ {
{ 1603.97f, 718.02f, 65.10f, 0 }, // guardian // sewers { 1603.97f, 718.02f, 65.10f, 0 }, // guardian // sewers
{ 1604.78f, 657.22f, 40.80f, 0 }, // wave 1 { 1604.78f, 657.22f, 40.80f, 0 }, // wave 1
@@ -788,7 +787,7 @@ static Location AllianceSpawn[] =
{ 1307.92f, 395.53f, -63.24f, 4.472f }, { 1307.92f, 395.53f, -63.24f, 4.472f },
}; };
static Location AllianceWP[] = static LocationXYZO AllianceWP[] =
{ {
{ 1737.06f, 734.176f, 48.8f, 0 }, // Jaina sewers UNUSED { 1737.06f, 734.176f, 48.8f, 0 }, // Jaina sewers UNUSED
{ 1682.92f, 730.89f, 76.84f, 0 }, // UNUSED { 1682.92f, 730.89f, 76.84f, 0 }, // UNUSED
@@ -802,12 +801,12 @@ static Location AllianceWP[] =
{ 1300.75f, 347.39f, -65.02f, 0 }, // jaina throne room { 1300.75f, 347.39f, -65.02f, 0 }, // jaina throne room
}; };
static Location HordeSpawn[] = static LocationXYZO HordeSpawn[] =
{ {
{ 1581.94f, 383.22f, -62.22f, 0 } // Khanok { 1581.94f, 383.22f, -62.22f, 0 } // Khanok
}; };
static Location ThrallSpawn[] = static LocationXYZO ThrallSpawn[] =
{ {
// Vortex // Vortex
{ 1880.0001f, 237.8242f, 59.472f, 3.060f }, { 1880.0001f, 237.8242f, 59.472f, 3.060f },

View File

@@ -1078,7 +1078,7 @@ public:
bool GossipSelect(Player* player, uint32 sender, uint32 action) override bool GossipSelect(Player* player, uint32 sender, uint32 action) override
{ {
Seconds respawnTimer = 0s; Seconds respawnTimer{};
player->PlayerTalkClass->SendCloseGossip(); player->PlayerTalkClass->SendCloseGossip();
Creature* lastSpawn = ObjectAccessor::GetCreature(*me, _creatureGuid); Creature* lastSpawn = ObjectAccessor::GetCreature(*me, _creatureGuid);

View File

@@ -1008,9 +1008,12 @@ public:
break; break;
} }
if (Aura* aura = target->GetAura(uint32(GetSpellInfo()->Effects[stage].CalcValue()))) if (target)
if (aura->GetOwner() == target) // avoid assert(false) at any cost {
aura->UpdateOwner(5000, target); // update whole aura so previous periodic ticks before refreshed by new one if (Aura* aura = target->GetAura(uint32(GetSpellInfo()->Effects[stage].CalcValue())))
if (aura->GetOwner() == target) // avoid assert(false) at any cost
aura->UpdateOwner(5000, target); // update whole aura so previous periodic ticks before refreshed by new one
}
GetCaster()->CastSpell(target, uint32(GetSpellInfo()->Effects[stage].CalcValue()), true, nullptr, nullptr, GetCaster()->GetGUID()); GetCaster()->CastSpell(target, uint32(GetSpellInfo()->Effects[stage].CalcValue()), true, nullptr, nullptr, GetCaster()->GetGUID());
} }

View File

@@ -870,13 +870,13 @@ static Location SpawnLocation[] =
{-4627.1240f, 1378.8752f, 139.9f, 2.544f} //Torloth The Magnificent {-4627.1240f, 1378.8752f, 139.9f, 2.544f} //Torloth The Magnificent
}; };
struct WaveData struct WaveDataCreature
{ {
uint8 SpawnCount, UsedSpawnPoint; uint8 SpawnCount, UsedSpawnPoint;
uint32 CreatureId, SpawnTimer, YellTimer; uint32 CreatureId, SpawnTimer, YellTimer;
}; };
static WaveData WavesInfo[] = static WaveDataCreature WavesInfo[] =
{ {
{9, 0, 22075, 10000, 7000}, //Illidari Soldier {9, 0, 22075, 10000, 7000}, //Illidari Soldier
{2, 9, 22074, 10000, 7000}, //Illidari Mind Breaker {2, 9, 22074, 10000, 7000}, //Illidari Mind Breaker

View File

@@ -122,7 +122,10 @@ char* DBCDatabaseLoader::Load(uint32& records, char**& indexTable)
// insert new records to index table // insert new records to index table
for (uint32 i = 0; i < newRecords; ++i) for (uint32 i = 0; i < newRecords; ++i)
{
// cppcheck-suppress autoVariables
indexTable[newIndexes[i]] = &dataTable[i * _recordSize]; indexTable[newIndexes[i]] = &dataTable[i * _recordSize];
}
records = indexTableSize; records = indexTableSize;

View File

@@ -57,6 +57,7 @@
#endif #endif
extern ArchiveSet gOpenArchives; extern ArchiveSet gOpenArchives;
// cppcheck-suppress ctuOneDefinitionRuleViolation
typedef struct typedef struct
{ {
char name[64]; char name[64];

View File

@@ -21,6 +21,7 @@
#include <string> #include <string>
#include <utility> #include <utility>
// cppcheck-suppress ctuOneDefinitionRuleViolation
class DBCFile class DBCFile
{ {
public: public:
@@ -48,8 +49,8 @@ public:
{ } { }
}; };
// Iteration over database // Iteration over database
class Iterator; class Iterator; // cppcheck-suppress ctuOneDefinitionRuleViolation
class Record class Record // cppcheck-suppress ctuOneDefinitionRuleViolation
{ {
public: public:
[[nodiscard]] float getFloat(size_t field) const [[nodiscard]] float getFloat(size_t field) const

View File

@@ -32,6 +32,7 @@ union u_map_fcc
// //
// File version chunk // File version chunk
// //
// cppcheck-suppress ctuOneDefinitionRuleViolation
struct file_MVER struct file_MVER
{ {
union union

View File

@@ -28,6 +28,7 @@
using namespace std; using namespace std;
// cppcheck-suppress ctuOneDefinitionRuleViolation
class MPQArchive class MPQArchive
{ {
public: public:
@@ -69,6 +70,7 @@ public:
}; };
typedef std::deque<MPQArchive*> ArchiveSet; typedef std::deque<MPQArchive*> ArchiveSet;
// cppcheck-suppress ctuOneDefinitionRuleViolation
class MPQFile class MPQFile
{ {
//MPQHANDLE handle; //MPQHANDLE handle;

View File

@@ -340,7 +340,7 @@ namespace MMAP
{ {
fclose(file); fclose(file);
delete[] verts; delete[] verts;
delete[] inds; delete[] inds; // cppcheck-suppress uninitdata
return; return;
} }