Core/Misc: Fix static analysis issues (#25924)

* Core/Misc: Fix static analysis issues

* Fix infinite loop in ".debug send opcode"
Fix using uninitialized memory in ".debug send opcode"
This commit is contained in:
Giacomo Pozzoni
2021-01-24 16:04:47 +01:00
committed by GitHub
parent 62320b1efa
commit 661f554b9e
18 changed files with 103 additions and 71 deletions

View File

@@ -92,8 +92,8 @@ private:
bool VerifyVersion(uint8 const* a, int32 aLength, Trinity::Crypto::SHA1::Digest const& versionProof, bool isReconnect);
Optional<Trinity::Crypto::SRP6> _srp6;
SessionKey _sessionKey;
std::array<uint8, 16> _reconnectProof;
SessionKey _sessionKey = {};
std::array<uint8, 16> _reconnectProof = {};
AuthStatus _status;
AccountInfo _accountInfo;

View File

@@ -42,7 +42,7 @@ enum BattlegroundBEGameObjects
BG_BE_OBJECT_TYPE_BUFF_2 = 184664
};
constexpr Seconds BG_BE_REMOVE_DOORS_TIMER = 5s;
inline constexpr Seconds BG_BE_REMOVE_DOORS_TIMER = 5s;
enum BattlegroundBEEvents
{

View File

@@ -73,11 +73,11 @@ enum BattlegroundDSData
};
// These values are NOT blizzlike... need the correct data!
constexpr Seconds BG_DS_WATERFALL_TIMER_MIN = 30s;
constexpr Seconds BG_DS_WATERFALL_TIMER_MAX = 60s;
constexpr Seconds BG_DS_WATERFALL_WARNING_DURATION = 5s;
constexpr Seconds BG_DS_WATERFALL_DURATION = 30s;
constexpr Milliseconds BG_DS_WATERFALL_KNOCKBACK_TIMER = 1500ms;
inline constexpr Seconds BG_DS_WATERFALL_TIMER_MIN = 30s;
inline constexpr Seconds BG_DS_WATERFALL_TIMER_MAX = 60s;
inline constexpr Seconds BG_DS_WATERFALL_WARNING_DURATION = 5s;
inline constexpr Seconds BG_DS_WATERFALL_DURATION = 30s;
inline constexpr Milliseconds BG_DS_WATERFALL_KNOCKBACK_TIMER = 1500ms;
enum BattlegroundDSEvents
{

View File

@@ -41,7 +41,7 @@ enum BattlegroundNAGameObjects
BG_NA_OBJECT_TYPE_BUFF_2 = 184664
};
constexpr Seconds BG_NA_REMOVE_DOORS_TIMER = 5s;
inline constexpr Seconds BG_NA_REMOVE_DOORS_TIMER = 5s;
enum BattlegroundNAEvents
{

View File

@@ -37,7 +37,7 @@ enum BattlegroundRLGameObjects
BG_RL_OBJECT_TYPE_BUFF_2 = 184664
};
constexpr Seconds BG_RL_REMOVE_DOORS_TIMER = 5s;
inline constexpr Seconds BG_RL_REMOVE_DOORS_TIMER = 5s;
enum BattlegroundRLEvents
{

View File

@@ -328,7 +328,7 @@ bool IsDisabledFor(DisableType type, uint32 entry, WorldObject const* ref, uint8
{
if (spellFlags & (SPELL_DISABLE_ARENAS | SPELL_DISABLE_BATTLEGROUNDS))
{
if (Map const* map = ref->GetMap())
if (Map const* map = ref->FindMap())
{
if (spellFlags & SPELL_DISABLE_ARENAS && map->IsBattleArena())
return true; // Current map is Arena and this spell is disabled here

View File

@@ -631,8 +631,8 @@ struct GameObjectOverride
// From `gameobject_template_addon`
struct GameObjectTemplateAddon : public GameObjectOverride
{
uint32 Mingold;
uint32 Maxgold;
uint32 Mingold = 0;
uint32 Maxgold = 0;
std::array<uint32, 4> artKits = {};
};

View File

@@ -43,7 +43,7 @@ struct EquipmentSetInfo
std::string SetName;
std::string SetIcon;
uint32 IgnoreMask = 0; ///< Mask of EquipmentSlot
std::array<ObjectGuid, EQUIPMENT_SET_SLOTS> Pieces;
std::array<ObjectGuid, EQUIPMENT_SET_SLOTS> Pieces = {};
} Data;
/// Server-side data

View File

@@ -710,18 +710,12 @@ typedef std::pair<ExclusiveQuestGroups::const_iterator, ExclusiveQuestGroups::co
struct PetLevelInfo
{
PetLevelInfo() : health(0), mana(0), armor(0), minDamage(0), maxDamage(0)
{
for (uint16& stat : stats)
stat = 0;
}
uint16 stats[MAX_STATS];
uint16 health;
uint16 mana;
uint32 armor;
uint16 minDamage;
uint16 maxDamage;
uint16 stats[MAX_STATS] = {};
uint16 health = 0;
uint16 mana = 0;
uint32 armor = 0;
uint16 minDamage = 0;
uint16 maxDamage = 0;
};
struct MailLevelReward

View File

@@ -778,7 +778,7 @@ void Group::ConvertLeaderInstancesToGroup(Player* player, Group* group, bool swi
/* if group leader is in a non-raid dungeon map and nobody is actually bound to this map then the group can "take over" the instance *
* (example: two-player group disbanded by disconnect where the player reconnects within 60 seconds and the group is reformed) */
if (Map* playerMap = player->GetMap())
if (Map* playerMap = player->FindMap())
if (!switchLeader && playerMap->IsNonRaidDungeon())
if (InstanceSave* save = sInstanceSaveMgr->GetInstanceSave(playerMap->GetInstanceId()))
if (save->GetGroupCount() == 0 && save->GetPlayerCount() == 0)

View File

@@ -685,7 +685,7 @@ void WorldSession::HandleTimeSyncResponse(WorldPacket& recvData)
using the following relation:
serverTime = clockDelta + clientTime
*/
int64 clockDelta = (int64)(serverTimeAtSent + lagDelay) - (int64)clientTimestamp;
int64 clockDelta = (int64)serverTimeAtSent + (int64)lagDelay - (int64)clientTimestamp;
_timeSyncClockDeltaQueue.push_back(std::pair<int64, uint32>(clockDelta, roundTripDuration));
ComputeNewClockDelta();
}

View File

@@ -93,7 +93,7 @@ class TC_GAME_API OutdoorPvPMgr
OutdoorPvPMap m_OutdoorPvPMap;
// Holds the outdoor PvP templates
OutdoorPvPScriptIds m_OutdoorPvPDatas;
OutdoorPvPScriptIds m_OutdoorPvPDatas = {};
// update interval
uint32 m_UpdateTimer;

View File

@@ -233,11 +233,11 @@ struct AuthSession
uint32 LoginServerType = 0;
uint32 RealmID = 0;
uint32 Build = 0;
std::array<uint8, 4> LocalChallenge;
std::array<uint8, 4> LocalChallenge = {};
uint32 LoginServerID = 0;
uint32 RegionID = 0;
uint64 DosResponse = 0;
Trinity::Crypto::SHA1::Digest Digest;
Trinity::Crypto::SHA1::Digest Digest = {};
std::string Account;
ByteBuffer AddonInfo;
};

View File

@@ -87,15 +87,15 @@ constexpr WorldIntConfigs GetWardenCategoryCountConfig(WardenCheckCategory categ
struct WardenCheck
{
uint16 CheckId;
uint16 CheckId = 0;
WardenCheckType Type = NONE_CHECK;
std::vector<uint8> Data;
uint32 Address; // PROC_CHECK, MEM_CHECK, PAGE_CHECK
uint8 Length; // PROC_CHECK, MEM_CHECK, PAGE_CHECK
uint32 Address = 0; // PROC_CHECK, MEM_CHECK, PAGE_CHECK
uint8 Length = 0; // PROC_CHECK, MEM_CHECK, PAGE_CHECK
std::string Str; // LUA, MPQ, DRIVER
std::string Comment;
std::array<char, 4> IdStr = {}; // LUA
WardenActions Action;
WardenActions Action = WARDEN_ACTION_LOG;
};
constexpr uint8 WARDEN_MAX_LUA_CHECK_LENGTH = 170;

View File

@@ -272,49 +272,63 @@ public:
std::stringstream parsedStream;
while (!ifs.eof())
{
char commentToken[2];
char commentToken[2] = {};
ifs.get(commentToken[0]);
if (commentToken[0] == '/' && !ifs.eof())
if (ifs.eof())
break;
if (commentToken[0] == '/')
{
ifs.get(commentToken[1]);
// /* comment
if (commentToken[1] == '*')
if (!ifs.eof())
{
while (!ifs.eof())
// /* comment
if (commentToken[1] == '*')
{
ifs.get(commentToken[0]);
if (commentToken[0] == '*' && !ifs.eof())
while (!ifs.eof())
{
ifs.get(commentToken[1]);
if (commentToken[1] == '/')
ifs.get(commentToken[0]);
if (ifs.eof())
break;
else
ifs.putback(commentToken[1]);
if (commentToken[0] == '*')
{
ifs.get(commentToken[1]);
if (ifs.eof())
break;
if (commentToken[1] == '/')
break;
else
ifs.putback(commentToken[1]);
}
}
continue;
}
continue;
// line comment
else if (commentToken[1] == '/')
{
std::string str;
std::getline(ifs, str);
if (ifs.eof())
break;
continue;
}
// regular data
else
ifs.putback(commentToken[1]);
}
// line comment
else if (commentToken[1] == '/')
{
std::string str;
std::getline(ifs, str);
continue;
}
// regular data
else
ifs.putback(commentToken[1]);
}
parsedStream.put(commentToken[0]);
}
ifs.close();
uint32 opcode;
uint32 opcode = 0;
parsedStream >> opcode;
if (!opcode)
return false;
WorldPacket data(opcode, 0);
while (!parsedStream.eof())
while (!parsedStream.eof() && !parsedStream.fail())
{
std::string type;
parsedStream >> type;
@@ -324,38 +338,59 @@ public:
if (type == "uint8")
{
uint16 val1;
if (parsedStream.eof())
return false;
uint16 val1 = 0;
parsedStream >> val1;
if (parsedStream.fail())
return false;
data << uint8(val1);
}
else if (type == "uint16")
{
uint16 val2;
if (parsedStream.eof())
return false;
uint16 val2 = 0;
parsedStream >> val2;
if (parsedStream.fail())
return false;
data << val2;
}
else if (type == "uint32")
{
uint32 val3;
if (parsedStream.eof())
return false;
uint32 val3 = 0;
parsedStream >> val3;
if (parsedStream.fail())
return false;
data << val3;
}
else if (type == "uint64")
{
uint64 val4;
if (parsedStream.eof())
return false;
uint64 val4 = 0;
parsedStream >> val4;
if (parsedStream.fail())
return false;
data << val4;
}
else if (type == "float")
{
float val5;
if (parsedStream.eof())
return false;
float val5 = 0.0f;
parsedStream >> val5;
if (parsedStream.fail())
return false;
data << val5;
}
else if (type == "string")
{
std::string val6;
parsedStream >> val6;
// empty string is allowed so no need to check eof/fail here
data << val6;
}
else if (type == "appitsguid")
@@ -373,7 +408,6 @@ public:
{
handler->PSendSysMessage(LANG_COMMAND_OBJNOTFOUND, 0);
handler->SetSentErrorMessage(true);
ifs.close();
return false;
}
data << obj->GetPackGUID();
@@ -385,7 +419,6 @@ public:
{
handler->PSendSysMessage(LANG_COMMAND_OBJNOTFOUND, 0);
handler->SetSentErrorMessage(true);
ifs.close();
return false;
}
data << uint64(obj->GetGUID());

View File

@@ -25,6 +25,11 @@
#include "ScriptMgr.h"
#include "TemporarySummon.h"
Position const BunnySpawnPosition = { 1776.27f, 1348.74f, 19.20f };
Position const EarthBunnySpawnPosition = { 1765.28f, 1347.46f, 18.55f, 6.17f };
Position const HeadlessHorsemanSpawnPosition = { 1765.00f, 1347.00f, 15.00f };
Position const HeadlessHorsemanHeadSpawnPosition = { 1788.54f, 1348.05f, 18.88f }; // Guessed
ObjectData const creatureData[] =
{
{ NPC_HEADLESS_HORSEMAN_HEAD, DATA_HORSEMAN_HEAD },

View File

@@ -26,10 +26,10 @@
uint32 const EncounterCount = 9;
Position const BunnySpawnPosition = { 1776.27f, 1348.74f, 19.20f };
Position const EarthBunnySpawnPosition = { 1765.28f, 1347.46f, 18.55f, 6.17f };
Position const HeadlessHorsemanSpawnPosition = { 1765.00f, 1347.00f, 15.00f };
Position const HeadlessHorsemanHeadSpawnPosition = { 1788.54f, 1348.05f, 18.88f }; // Guessed
extern Position const BunnySpawnPosition;
extern Position const EarthBunnySpawnPosition;
extern Position const HeadlessHorsemanSpawnPosition;
extern Position const HeadlessHorsemanHeadSpawnPosition;
enum SMDataTypes
{

View File

@@ -88,7 +88,7 @@ enum GDSpellIds
SPELL_FIRE_BEAM_ELEMENTAL = 57072
};
constexpr Milliseconds TIMER_STATUE_ACTIVATION = 3500ms;
inline constexpr Milliseconds TIMER_STATUE_ACTIVATION = 3500ms;
template <class AI, class T>
inline AI* GetGundrakAI(T* obj)