mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-16 07:30:42 +01:00
Core/Misc: Fixed coverity issues
Uninitialized fields: CID 1354593, 1354595, 1354738 Unchecked return value: CID 1354558 Out of bounds access: CID 1352989, 1352993 Null pointer dereference: CID 1296286
This commit is contained in:
@@ -647,7 +647,7 @@ bool Battlenet::Session::ReadHeaderHandler()
|
||||
bool Battlenet::Session::ReadDataHandler()
|
||||
{
|
||||
Header header;
|
||||
header.ParseFromArray(_headerBuffer.GetReadPointer(), _headerBuffer.GetActiveSize());
|
||||
ASSERT(header.ParseFromArray(_headerBuffer.GetReadPointer(), _headerBuffer.GetActiveSize()));
|
||||
|
||||
if (header.service_id() != 0xFE)
|
||||
{
|
||||
|
||||
@@ -302,7 +302,7 @@ void Player::UpdateAttackPowerAndDamage(bool ranged)
|
||||
float val2 = 0.0f;
|
||||
float level = float(getLevel());
|
||||
|
||||
ChrClassesEntry const* entry = sChrClassesStore.LookupEntry(getClass());
|
||||
ChrClassesEntry const* entry = sChrClassesStore.AssertEntry(getClass());
|
||||
UnitMods unitMod = ranged ? UNIT_MOD_ATTACK_POWER_RANGED : UNIT_MOD_ATTACK_POWER;
|
||||
|
||||
uint16 index = UNIT_FIELD_ATTACK_POWER;
|
||||
|
||||
@@ -2210,8 +2210,8 @@ void WorldSession::HandleCharRaceOrFactionChangeCallback(PreparedQueryResult res
|
||||
uint32 title_alliance = it->first;
|
||||
uint32 title_horde = it->second;
|
||||
|
||||
CharTitlesEntry const* atitleInfo = sCharTitlesStore.LookupEntry(title_alliance);
|
||||
CharTitlesEntry const* htitleInfo = sCharTitlesStore.LookupEntry(title_horde);
|
||||
CharTitlesEntry const* atitleInfo = sCharTitlesStore.AssertEntry(title_alliance);
|
||||
CharTitlesEntry const* htitleInfo = sCharTitlesStore.AssertEntry(title_horde);
|
||||
// new team
|
||||
if (newTeamId == TEAM_ALLIANCE)
|
||||
{
|
||||
|
||||
@@ -515,10 +515,9 @@ void WorldSession::HandlePetSetAction(WorldPackets::Pet::PetSetAction& packet)
|
||||
void WorldSession::HandlePetRename(WorldPackets::Pet::PetRename& packet)
|
||||
{
|
||||
ObjectGuid petguid = packet.RenameData.PetGUID;
|
||||
bool isdeclined = packet.RenameData.HasDeclinedNames;
|
||||
|
||||
std::string name = packet.RenameData.NewName;
|
||||
DeclinedName declinedname = packet.RenameData.DeclinedNames;
|
||||
DeclinedName* declinedname = packet.RenameData.DeclinedNames.get_ptr();
|
||||
|
||||
Pet* pet = ObjectAccessor::GetPet(*_player, petguid);
|
||||
// check it!
|
||||
@@ -546,21 +545,21 @@ void WorldSession::HandlePetRename(WorldPackets::Pet::PetRename& packet)
|
||||
|
||||
pet->RemoveByteFlag(UNIT_FIELD_BYTES_2, 2, UNIT_CAN_BE_RENAMED);
|
||||
|
||||
if (isdeclined)
|
||||
if (declinedname)
|
||||
{
|
||||
std::wstring wname;
|
||||
if (!Utf8toWStr(name, wname))
|
||||
return;
|
||||
|
||||
if (!ObjectMgr::CheckDeclinedNames(wname, declinedname))
|
||||
if (!ObjectMgr::CheckDeclinedNames(wname, *declinedname))
|
||||
{
|
||||
SendPetNameInvalid(PET_NAME_DECLENSION_DOESNT_MATCH_BASE_NAME, name, &declinedname);
|
||||
SendPetNameInvalid(PET_NAME_DECLENSION_DOESNT_MATCH_BASE_NAME, name, declinedname);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
SQLTransaction trans = CharacterDatabase.BeginTransaction();
|
||||
if (isdeclined)
|
||||
if (declinedname)
|
||||
{
|
||||
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_CHAR_PET_DECLINEDNAME);
|
||||
stmt->setUInt32(0, pet->GetCharmInfo()->GetPetNumber());
|
||||
@@ -571,7 +570,7 @@ void WorldSession::HandlePetRename(WorldPackets::Pet::PetRename& packet)
|
||||
stmt->setUInt64(1, _player->GetGUID().GetCounter());
|
||||
|
||||
for (uint8 i = 0; i < 5; i++)
|
||||
stmt->setString(i + 2, declinedname.name[i]);
|
||||
stmt->setString(i + 2, declinedname->name[i]);
|
||||
|
||||
trans->Append(stmt);
|
||||
}
|
||||
@@ -717,8 +716,8 @@ void WorldSession::SendPetNameInvalid(uint32 error, const std::string& name, Dec
|
||||
WorldPackets::Pet::PetNameInvalid petNameInvalid;
|
||||
petNameInvalid.Result = error;
|
||||
petNameInvalid.RenameData.NewName = name;
|
||||
for (int i = 0; i < MAX_DECLINED_NAME_CASES; i++)
|
||||
petNameInvalid.RenameData.DeclinedNames.name[i] = declinedName[i].name[i];
|
||||
if (declinedName)
|
||||
petNameInvalid.RenameData.DeclinedNames = *declinedName;
|
||||
|
||||
SendPacket(petNameInvalid.Write());
|
||||
}
|
||||
|
||||
@@ -76,8 +76,8 @@ namespace WorldPackets
|
||||
|
||||
WorldPacket const* Write() override;
|
||||
|
||||
uint32 Token;
|
||||
bool Allow;
|
||||
uint32 Token = 0;
|
||||
bool Allow = false;
|
||||
ByteBuffer Ticket;
|
||||
};
|
||||
|
||||
|
||||
@@ -99,19 +99,19 @@ WorldPacket const* WorldPackets::Pet::PetNameInvalid::Write()
|
||||
|
||||
_worldPacket << uint8(RenameData.NewName.length());
|
||||
|
||||
_worldPacket.WriteBit(RenameData.HasDeclinedNames);
|
||||
_worldPacket.WriteBit(RenameData.DeclinedNames.is_initialized());
|
||||
_worldPacket.FlushBits();
|
||||
|
||||
if (RenameData.HasDeclinedNames)
|
||||
if (RenameData.DeclinedNames)
|
||||
{
|
||||
for (int32 i = 0; i < MAX_DECLINED_NAME_CASES; i++)
|
||||
{
|
||||
_worldPacket.WriteBits(RenameData.DeclinedNames.name[i].length(), 7);
|
||||
_worldPacket.WriteBits(RenameData.DeclinedNames->name[i].length(), 7);
|
||||
_worldPacket.FlushBits();
|
||||
}
|
||||
|
||||
for (int32 i = 0; i < MAX_DECLINED_NAME_CASES; i++)
|
||||
_worldPacket << RenameData.DeclinedNames.name[i];
|
||||
_worldPacket << RenameData.DeclinedNames->name[i];
|
||||
}
|
||||
|
||||
_worldPacket.WriteString(RenameData.NewName);
|
||||
@@ -126,15 +126,15 @@ void WorldPackets::Pet::PetRename::Read()
|
||||
int8 nameLen = 0;
|
||||
_worldPacket >> nameLen;
|
||||
|
||||
RenameData.HasDeclinedNames = _worldPacket.ReadBit();
|
||||
if (RenameData.HasDeclinedNames)
|
||||
if (_worldPacket.ReadBit())
|
||||
{
|
||||
RenameData.DeclinedNames = boost::in_place();
|
||||
int32 count[MAX_DECLINED_NAME_CASES];
|
||||
for (int32 i = 0; i < MAX_DECLINED_NAME_CASES; i++)
|
||||
count[i] = _worldPacket.ReadBits(7);
|
||||
|
||||
for (int32 i = 0; i < MAX_DECLINED_NAME_CASES; i++)
|
||||
RenameData.DeclinedNames.name[i] = _worldPacket.ReadString(count[i]);
|
||||
RenameData.DeclinedNames->name[i] = _worldPacket.ReadString(count[i]);
|
||||
}
|
||||
|
||||
RenameData.NewName = _worldPacket.ReadString(nameLen);
|
||||
|
||||
@@ -163,8 +163,7 @@ namespace WorldPackets
|
||||
ObjectGuid PetGUID;
|
||||
int32 PetNumber = 0;
|
||||
std::string NewName;
|
||||
bool HasDeclinedNames = false;
|
||||
DeclinedName DeclinedNames;
|
||||
Optional<DeclinedName> DeclinedNames;
|
||||
};
|
||||
|
||||
class PetNameInvalid final : public ServerPacket
|
||||
|
||||
@@ -118,6 +118,7 @@ WorldSession::WorldSession(uint32 id, std::string&& name, uint32 battlenetAccoun
|
||||
_battlenetAccountId(battlenetAccountId),
|
||||
m_expansion(expansion),
|
||||
_os(os),
|
||||
_battlenetRequestToken(0),
|
||||
_warden(NULL),
|
||||
_logoutTime(0),
|
||||
m_inQueue(false),
|
||||
|
||||
@@ -200,7 +200,7 @@ public:
|
||||
if (zombie)
|
||||
{
|
||||
zombieToBeEatenGUID = zombie->GetGUID(); // save for later use
|
||||
|
||||
|
||||
// the soon-to-be-eaten zombie should stop moving and stop attacking
|
||||
zombie->AI()->SetData(DATA_ZOMBIE_STATE, STATE_ZOMBIE_TOBE_EATEN);
|
||||
|
||||
@@ -225,7 +225,7 @@ public:
|
||||
case EVENT_KILL_ZOMBIE_SINGLE:
|
||||
{
|
||||
Creature* zombieToBeEaten = ObjectAccessor::GetCreature(*me, zombieToBeEatenGUID);
|
||||
if (zombieToBeEaten && zombieToBeEaten->IsAlive() && zombieToBeEaten->IsWithinDistInMap(me, 10.0))
|
||||
if (zombieToBeEaten && zombieToBeEaten->IsAlive() && zombieToBeEaten->IsWithinDistInMap(me, 10.0))
|
||||
DoCast(zombieToBeEaten, SPELL_ZOMBIE_CHOW_SEARCH_SINGLE); // do the killing + healing in done inside by spell script see below.
|
||||
|
||||
zombieToBeEatenGUID = ObjectGuid::Empty;
|
||||
@@ -249,11 +249,11 @@ public:
|
||||
if (zombie && zombie->IsAlive() && zombie->GetExactDist2d(me) > 18.0)
|
||||
zombie = nullptr;
|
||||
}
|
||||
|
||||
|
||||
if (zombie) // cast the aoe spell only if at least one zombie is found nearby
|
||||
{
|
||||
Talk(EMOTE_DEVOURS_ALL);
|
||||
DoCastAOE(SPELL_ZOMBIE_CHOW_SEARCH_MULTI);
|
||||
DoCastAOE(SPELL_ZOMBIE_CHOW_SEARCH_MULTI);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -269,7 +269,7 @@ public:
|
||||
me->GetMotionMaster()->MoveIdle();
|
||||
events.ScheduleEvent(EVENT_KILL_ZOMBIE_SINGLE, Seconds(1));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
void DoAction(int32 action) override
|
||||
@@ -405,17 +405,19 @@ public:
|
||||
if (state == STATE_ZOMBIE_DECIMATED)
|
||||
{
|
||||
timer += diff;
|
||||
Creature* gluth = ObjectAccessor::GetCreature(*me, GluthGUID);
|
||||
// Putting this in the UpdateAI loop fixes an issue where death gripping a decimated zombie would make the zombie stand still until the rest of the fight.
|
||||
// Also fix the issue where if one or more zombie is rooted when decimates hits (and MovePoint() is called), the zombie teleport to the boss. pretty weird behavior.
|
||||
if (gluth && timer>1600 && me->GetExactDist2d(gluth) > 10.0 && me->CanFreeMove()) // it takes about 1600 ms for the animation to cycle. This way, the animation looks relatively smooth.
|
||||
if (Creature* gluth = ObjectAccessor::GetCreature(*me, GluthGUID))
|
||||
{
|
||||
me->GetMotionMaster()->MovePoint(0, gluth->GetPosition()); // isn't dynamic. So, to take into account Gluth's movement, it must be called periodicly.
|
||||
timer = 0;
|
||||
}
|
||||
if (timer > 1600 && me->GetExactDist2d(gluth) > 10.0 && me->CanFreeMove()) // it takes about 1600 ms for the animation to cycle. This way, the animation looks relatively smooth.
|
||||
{
|
||||
me->GetMotionMaster()->MovePoint(0, gluth->GetPosition()); // isn't dynamic. So, to take into account Gluth's movement, it must be called periodicly.
|
||||
timer = 0;
|
||||
}
|
||||
|
||||
if (me->GetExactDist2d(gluth) <= 10.0)
|
||||
me->StopMoving();
|
||||
if (me->GetExactDist2d(gluth) <= 10.0)
|
||||
me->StopMoving();
|
||||
}
|
||||
}
|
||||
else if (state == STATE_ZOMBIE_NORMAL)
|
||||
DoMeleeAttackIfReady();
|
||||
@@ -430,10 +432,10 @@ public:
|
||||
{
|
||||
me->SetReactState(ReactStates::REACT_PASSIVE);
|
||||
me->AttackStop();
|
||||
me->SetTarget(ObjectGuid::Empty);
|
||||
me->SetTarget(ObjectGuid::Empty);
|
||||
// at this point, the zombie should be non attacking and non moving.
|
||||
|
||||
me->SetWalk(true); // it doesnt seem to work with MoveFollow() (but it does work with MovePoint()).
|
||||
me->SetWalk(true); // it doesnt seem to work with MoveFollow() (but it does work with MovePoint()).
|
||||
|
||||
timer = 1000;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user