Skip to content

Commit

Permalink
fix(Core/Player): SpellQueue avoid possible undefined behavior by cop…
Browse files Browse the repository at this point in the history
…ying instead of move (azerothcore#21444)
  • Loading branch information
sogladev authored Feb 14, 2025
1 parent 3854d00 commit 75441dd
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/server/game/Handlers/SpellHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 75441dd

Please sign in to comment.