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"

(cherry picked from commit 661f554b9e)
This commit is contained in:
Giacomo Pozzoni
2021-01-24 16:04:47 +01:00
committed by Shauren
parent 91d7a8b069
commit a66b968f91
16 changed files with 103 additions and 70 deletions

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

@@ -305,7 +305,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

@@ -1076,18 +1076,18 @@ struct GameObjectTemplate
// From `gameobject_template_addon`, `gameobject_overrides`
struct GameObjectOverride
{
uint32 Faction;
uint32 Flags;
uint32 Faction = 0;
uint32 Flags = 0;
};
// From `gameobject_template_addon`
struct GameObjectTemplateAddon : public GameObjectOverride
{
uint32 Mingold;
uint32 Maxgold;
uint32 Mingold = 0;
uint32 Maxgold = 0;
std::array<uint32, 5> ArtKits = { };
uint32 WorldEffectID;
uint32 AIAnimKitID;
uint32 WorldEffectID = 0;
uint32 AIAnimKitID = 0;
};
struct GameObjectLocale

View File

@@ -51,9 +51,9 @@ struct EquipmentSetInfo
int32 AssignedSpecIndex = -1; ///< Index of character specialization that this set is automatically equipped for
std::string SetName;
std::string SetIcon;
std::array<ObjectGuid, EQUIPMENT_SET_SLOTS> Pieces;
std::array<int32, EQUIPMENT_SET_SLOTS> Appearances; ///< ItemModifiedAppearanceID
std::array<int32, 2> Enchants; ///< SpellItemEnchantmentID
std::array<ObjectGuid, EQUIPMENT_SET_SLOTS> Pieces = {};
std::array<int32, EQUIPMENT_SET_SLOTS> Appearances = {};///< ItemModifiedAppearanceID
std::array<int32, 2> Enchants = {}; ///< SpellItemEnchantmentID
int32 SecondaryShoulderApparanceID = 0; ///< Secondary shoulder appearance
int32 SecondaryShoulderSlot = 0; ///< Always 2 if secondary shoulder apperance is used
int32 SecondaryWeaponAppearanceID = 0; ///< For legion artifacts: linked child item appearance

View File

@@ -678,16 +678,10 @@ struct PlayerInfo
struct PetLevelInfo
{
PetLevelInfo() : health(0), mana(0), armor(0)
{
for (uint16& stat : stats)
stat = 0;
}
uint16 stats[MAX_STATS];
uint16 health;
uint16 mana;
uint16 armor;
uint16 stats[MAX_STATS] = {};
uint16 health = 0;
uint16 mana = 0;
uint16 armor = 0;
};
struct MailLevelReward

View File

@@ -820,7 +820,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

@@ -741,7 +741,7 @@ void WorldSession::HandleTimeSyncResponse(WorldPackets::Misc::TimeSyncResponse&
using the following relation:
serverTime = clockDelta + clientTime
*/
int64 clockDelta = (int64)(serverTimeAtSent + lagDelay) - (int64)timeSyncResponse.ClientTime;
int64 clockDelta = (int64)serverTimeAtSent + (int64)lagDelay - (int64)timeSyncResponse.ClientTime;
_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

@@ -86,15 +86,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

@@ -330,49 +330,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(OpcodeServer(opcode), 0);
while (!parsedStream.eof())
while (!parsedStream.eof() && !parsedStream.fail())
{
std::string type;
parsedStream >> type;
@@ -382,38 +396,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 == "goguid")
@@ -423,7 +458,6 @@ public:
{
handler->PSendSysMessage(LANG_COMMAND_OBJNOTFOUND, "0");
handler->SetSentErrorMessage(true);
ifs.close();
return false;
}
data << 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)