Browse Source

Fix ASAN alignment issues related to spawned monster deltas

pull/7987/head
staphen 11 months ago committed by Stephen C. Wills
parent
commit
8cf2380960
  1. 20
      Source/msg.cpp

20
Source/msg.cpp

@ -618,13 +618,13 @@ const std::byte *DeltaImportMonster(const std::byte *src, const std::byte *end,
std::byte *DeltaExportSpawnedMonsters(std::byte *dst, const ankerl::unordered_dense::map<size_t, DSpawnedMonster> &spawnedMonsters) std::byte *DeltaExportSpawnedMonsters(std::byte *dst, const ankerl::unordered_dense::map<size_t, DSpawnedMonster> &spawnedMonsters)
{ {
auto &size = *reinterpret_cast<uint16_t *>(dst); uint16_t size = SDL_SwapLE16(static_cast<uint16_t>(spawnedMonsters.size()));
size = static_cast<uint16_t>(spawnedMonsters.size()); memcpy(dst, &size, sizeof(uint16_t));
dst += sizeof(uint16_t); dst += sizeof(uint16_t);
for (const auto &deltaSpawnedMonster : spawnedMonsters) { for (const auto &deltaSpawnedMonster : spawnedMonsters) {
auto &monsterId = *reinterpret_cast<uint16_t *>(dst); uint16_t monsterId = SDL_SwapLE16(static_cast<uint16_t>(deltaSpawnedMonster.first));
monsterId = static_cast<uint16_t>(deltaSpawnedMonster.first); memcpy(dst, &monsterId, sizeof(uint16_t));
dst += sizeof(uint16_t); dst += sizeof(uint16_t);
memcpy(dst, &deltaSpawnedMonster.second, sizeof(DSpawnedMonster)); memcpy(dst, &deltaSpawnedMonster.second, sizeof(DSpawnedMonster));
@ -639,7 +639,10 @@ const std::byte *DeltaImportSpawnedMonsters(const std::byte *src, const std::byt
if (src == nullptr || src + sizeof(uint16_t) > end) if (src == nullptr || src + sizeof(uint16_t) > end)
return nullptr; return nullptr;
uint16_t size = *reinterpret_cast<const uint16_t *>(src); uint16_t size;
memcpy(&size, src, sizeof(uint16_t));
size = SDL_SwapLE16(size);
src += sizeof(uint16_t);
if (size > MaxMonsters) if (size > MaxMonsters)
return nullptr; return nullptr;
@ -647,11 +650,12 @@ const std::byte *DeltaImportSpawnedMonsters(const std::byte *src, const std::byt
if (src + requiredBytes > end) if (src + requiredBytes > end)
return nullptr; return nullptr;
src += sizeof(uint16_t);
for (size_t i = 0; i < size; i++) { for (size_t i = 0; i < size; i++) {
uint16_t monsterId = *reinterpret_cast<const uint16_t *>(src); uint16_t monsterId;
memcpy(&monsterId, src, sizeof(uint16_t));
monsterId = SDL_SwapLE16(monsterId);
src += sizeof(uint16_t); src += sizeof(uint16_t);
DSpawnedMonster spawnedMonster; DSpawnedMonster spawnedMonster;
memcpy(&spawnedMonster, src, sizeof(DSpawnedMonster)); memcpy(&spawnedMonster, src, sizeof(DSpawnedMonster));
src += sizeof(DSpawnedMonster); src += sizeof(DSpawnedMonster);

Loading…
Cancel
Save