fix(Core/Player): SpellQueue avoid possible undefined behavior by copying instead of move (#21444)
This commit is contained in:
@@ -110,11 +110,12 @@ void WorldSession::HandleUseItemOpcode(WorldPacket& recvPacket)
|
|||||||
if (!_player->CanExecutePendingSpellCastRequest(spellInfo))
|
if (!_player->CanExecutePendingSpellCastRequest(spellInfo))
|
||||||
if (_player->CanRequestSpellCast(spellInfo))
|
if (_player->CanRequestSpellCast(spellInfo))
|
||||||
{
|
{
|
||||||
recvPacket.rpos(0); // Reset read position to the start of the buffer.
|
WorldPacket packetCopy(recvPacket); // Copy the packet
|
||||||
|
packetCopy.rpos(0); // Reset read position to the start of the buffer.
|
||||||
_player->SpellQueue.emplace_back(
|
_player->SpellQueue.emplace_back(
|
||||||
spellId,
|
spellId,
|
||||||
spellInfo->GetCategory(),
|
spellInfo->GetCategory(),
|
||||||
std::move(recvPacket), // Move ownership of recvPacket
|
std::move(packetCopy), // Move ownership of copied packet
|
||||||
true // itemCast
|
true // itemCast
|
||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
@@ -424,11 +425,12 @@ void WorldSession::HandleCastSpellOpcode(WorldPacket& recvPacket)
|
|||||||
{
|
{
|
||||||
if (_player->CanRequestSpellCast(spellInfo))
|
if (_player->CanRequestSpellCast(spellInfo))
|
||||||
{
|
{
|
||||||
recvPacket.rpos(0); // Reset read position to the start of the buffer.
|
WorldPacket packetCopy(recvPacket); // Copy the packet
|
||||||
|
packetCopy.rpos(0); // Reset read position to the start of the buffer.
|
||||||
_player->SpellQueue.emplace_back(
|
_player->SpellQueue.emplace_back(
|
||||||
spellId,
|
spellId,
|
||||||
spellInfo->GetCategory(),
|
spellInfo->GetCategory(),
|
||||||
std::move(recvPacket) // Move ownership of recvPacket
|
std::move(packetCopy) // Move ownership of copied packet
|
||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user