diff --git a/src/3rdparty/squirrel/squirrel/sqstate.cpp b/src/3rdparty/squirrel/squirrel/sqstate.cpp index 09341d84dd..42df3c5e71 100644 --- a/src/3rdparty/squirrel/squirrel/sqstate.cpp +++ b/src/3rdparty/squirrel/squirrel/sqstate.cpp @@ -538,7 +538,7 @@ void SQStringTable::AllocNodes(SQInteger size) { _numofslots = size; _strings = (SQString**)SQ_MALLOC(sizeof(SQString*)*_numofslots); - memset(_strings,0,sizeof(SQString*)*(size_t)_numofslots); + std::fill_n(_strings, _numofslots, nullptr); } static const std::hash string_table_hash{}; diff --git a/src/blitter/8bpp_base.cpp b/src/blitter/8bpp_base.cpp index a936138a1a..fceb5c4adf 100644 --- a/src/blitter/8bpp_base.cpp +++ b/src/blitter/8bpp_base.cpp @@ -43,9 +43,10 @@ void Blitter_8bppBase::DrawLine(void *video, int x, int y, int x2, int y2, int s void Blitter_8bppBase::DrawRect(void *video, int width, int height, uint8_t colour) { + std::byte *p = static_cast(video); do { - memset(video, colour, width); - video = (uint8_t *)video + _screen.pitch; + std::fill_n(p, width, static_cast(colour)); + p += _screen.pitch; } while (--height); } diff --git a/src/mixer.cpp b/src/mixer.cpp index 81205cf398..0e92cd5333 100644 --- a/src/mixer.cpp +++ b/src/mixer.cpp @@ -131,7 +131,7 @@ void MxMixSamples(void *buffer, uint samples) } /* Clear the buffer */ - memset(buffer, 0, sizeof(int16_t) * 2 * samples); + std::fill_n(static_cast(buffer), 2 * samples, 0); { std::lock_guard lock{ _music_stream_mutex }; diff --git a/src/settings.cpp b/src/settings.cpp index 41e6b026da..1522cac8eb 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -281,15 +281,15 @@ static std::optional> ParseIntList(std::string_view str) static bool LoadIntList(std::optional str, void *array, int nelems, VarType type) { size_t elem_size = SlVarSize(type); + std::byte *p = static_cast(array); if (!str.has_value()) { - memset(array, 0, nelems * elem_size); + std::fill_n(p, nelems * elem_size, static_cast(0)); return true; } auto opt_items = ParseIntList(*str); if (!opt_items.has_value() || opt_items->size() != (size_t)nelems) return false; - std::byte *p = static_cast(array); for (auto item : *opt_items) { WriteValue(p, type, item); p += elem_size; diff --git a/src/spritecache.cpp b/src/spritecache.cpp index 50f274b2ce..e196ad202b 100644 --- a/src/spritecache.cpp +++ b/src/spritecache.cpp @@ -448,7 +448,7 @@ static void *ReadRecolourSprite(SpriteFile &file, size_t file_pos, uint num, Spr uint8_t *dest_tmp = new uint8_t[std::max(RECOLOUR_SPRITE_SIZE, num)]; /* Only a few recolour sprites are less than 257 bytes */ - if (num < RECOLOUR_SPRITE_SIZE) memset(dest_tmp, 0, RECOLOUR_SPRITE_SIZE); + if (num < RECOLOUR_SPRITE_SIZE) std::fill_n(dest_tmp, RECOLOUR_SPRITE_SIZE, 0); file.ReadBlock(dest_tmp, num); /* The data of index 0 is never used; "literal 00" according to the (New)GRF specs. */ diff --git a/src/video/allegro_v.cpp b/src/video/allegro_v.cpp index faf4091151..424fafa2a9 100644 --- a/src/video/allegro_v.cpp +++ b/src/video/allegro_v.cpp @@ -203,7 +203,7 @@ static bool CreateMainSurface(uint w, uint h) _screen.dst_ptr = _allegro_screen->line[0]; /* Initialise the screen so we don't blit garbage to the screen */ - memset(_screen.dst_ptr, 0, static_cast(_screen.height) * _screen.pitch); + std::fill_n(static_cast(_screen.dst_ptr), static_cast(_screen.height) * _screen.pitch, static_cast(0)); /* Set the mouse at the place where we expect it */ poll_mouse();