fix: remove reinterpret_cast UB in trade slot delegation

The TradeSlot structs differ between GameHandler (has bag/slot fields)
and InventoryHandler (no bag/slot). The reinterpret_cast was undefined
behavior that corrupted memory, potentially causing the teleport bug.

Now properly copies fields between the two struct layouts.

NOTE: 113 stale getters remain in GameHandler that read duplicate member
variables never updated by domain handlers. These need systematic fixing.
This commit is contained in:
Kelsi 2026-03-28 12:02:08 -07:00
parent f37994cc1b
commit 2633a490eb

View file

@ -5090,11 +5090,32 @@ const std::string& GameHandler::getTradePeerName() const {
return tradePeerName_;
}
const std::array<GameHandler::TradeSlot, GameHandler::TRADE_SLOT_COUNT>& GameHandler::getMyTradeSlots() const {
if (inventoryHandler_) return reinterpret_cast<const std::array<TradeSlot, TRADE_SLOT_COUNT>&>(inventoryHandler_->getMyTradeSlots());
if (inventoryHandler_) {
// Convert InventoryHandler::TradeSlot → GameHandler::TradeSlot (different struct layouts)
static std::array<TradeSlot, TRADE_SLOT_COUNT> converted{};
const auto& src = inventoryHandler_->getMyTradeSlots();
for (size_t i = 0; i < TRADE_SLOT_COUNT; i++) {
converted[i].itemId = src[i].itemId;
converted[i].displayId = src[i].displayId;
converted[i].stackCount = src[i].stackCount;
converted[i].itemGuid = src[i].itemGuid;
}
return converted;
}
return myTradeSlots_;
}
const std::array<GameHandler::TradeSlot, GameHandler::TRADE_SLOT_COUNT>& GameHandler::getPeerTradeSlots() const {
if (inventoryHandler_) return reinterpret_cast<const std::array<TradeSlot, TRADE_SLOT_COUNT>&>(inventoryHandler_->getPeerTradeSlots());
if (inventoryHandler_) {
static std::array<TradeSlot, TRADE_SLOT_COUNT> converted{};
const auto& src = inventoryHandler_->getPeerTradeSlots();
for (size_t i = 0; i < TRADE_SLOT_COUNT; i++) {
converted[i].itemId = src[i].itemId;
converted[i].displayId = src[i].displayId;
converted[i].stackCount = src[i].stackCount;
converted[i].itemGuid = src[i].itemGuid;
}
return converted;
}
return peerTradeSlots_;
}
uint64_t GameHandler::getMyTradeGold() const {