fix(Core/Player): SpellQueue avoid possible undefined behavior by copying instead of move (#21444)

This commit is contained in:
Jelle Meeus
2025-02-14 15:45:36 +01:00
committed by GitHub
parent 3854d00dee
commit 75441ddb3b

View File

@@ -110,11 +110,12 @@ void WorldSession::HandleUseItemOpcode(WorldPacket& recvPacket)
if (!_player->CanExecutePendingSpellCastRequest(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(
spellId,
spellInfo->GetCategory(),
std::move(recvPacket), // Move ownership of recvPacket
std::move(packetCopy), // Move ownership of copied packet
true // itemCast
);
return;
@@ -424,11 +425,12 @@ void WorldSession::HandleCastSpellOpcode(WorldPacket& recvPacket)
{
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(
spellId,
spellInfo->GetCategory(),
std::move(recvPacket) // Move ownership of recvPacket
std::move(packetCopy) // Move ownership of copied packet
);
return;
}