ThePhrozenKeep / D2MOO

Reimplementation of the Diablo2 game coupled with patching facilities for modders.
MIT License
93 stars 29 forks source link

`MONSTERREGION_InitializeAll` Uses Incorrect Sizes #158

Closed Necrolis closed 3 months ago

Necrolis commented 4 months ago

The following 2 calls to memcpy in MONSTERREGION_InitializeAll use the incorrect size, as the monster id's are a uint16_t but memcpy takes a byte count: https://github.com/ThePhrozenKeep/D2MOO/blob/923506cbed938f21656e0562efa854f8d8fb9f8b/source/D2Game/src/MONSTER/MonsterRegion.cpp#L960 https://github.com/ThePhrozenKeep/D2MOO/blob/923506cbed938f21656e0562efa854f8d8fb9f8b/source/D2Game/src/MONSTER/MonsterRegion.cpp#L967

these calls should be pLevelsTxtRecord->nNumNMon * sizeof(uint16_t) and pLevelsTxtRecord->nNumNormMon * sizeof(uint16_t) respectively, else std::copy should be used in place of memcpy.

Additionally the default array initializer of monsterIds does not exist in the assembly code (apart from being redundant due to the memcpy). the compiler should elide this, but there may be scenarios where a pointless memset may be done.