1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-15 11:03:00 +01:00

Fix memset byte value too big (#7447)

`memset` takes an integer as argument which gets converted to an unsigned byte. `SPRITE_INDEX_NULL` has a value of 0xFFFF, essentially cutting it to 0xFF. Calling `std::fill_n` instead of `memcpy` assigns the given value to each element in its range rather than setting the bytes. In this case, the result is the same.

None of the other calls to `memset` in the project use values bigger than 0xFF.
This commit is contained in:
Hielke Morsink
2018-04-25 14:47:03 +02:00
committed by GitHub
parent 3aac52cf44
commit 49cf840f28

View File

@@ -14,11 +14,13 @@
*****************************************************************************/
#pragma endregion
#include <algorithm>
#include <cmath>
#include "../audio/audio.h"
#include "../Cheats.h"
#include "../core/Guard.hpp"
#include "../core/Math.hpp"
#include "../core/Util.hpp"
#include "../Game.h"
#include "../interface/Viewport.h"
#include "../localisation/Date.h"
@@ -176,7 +178,7 @@ void reset_sprite_list()
*/
void reset_sprite_spatial_index()
{
memset(gSpriteSpatialIndex, SPRITE_INDEX_NULL, sizeof(gSpriteSpatialIndex));
std::fill_n(gSpriteSpatialIndex, Util::CountOf(gSpriteSpatialIndex), SPRITE_INDEX_NULL);
for (size_t i = 0; i < MAX_SPRITES; i++) {
rct_sprite *spr = get_sprite(i);
if (spr->unknown.sprite_identifier != SPRITE_IDENTIFIER_NULL) {