diff --git a/src/base/system.cpp b/src/base/system.cpp index a65651211..3e70e8d68 100644 --- a/src/base/system.cpp +++ b/src/base/system.cpp @@ -208,21 +208,39 @@ void dbg_msg(const char *sys, const char *fmt, ...) /* */ -void mem_copy(void *dest, const void *source, unsigned size) +void mem_copy(void *dest, const void *source, size_t size) { memcpy(dest, source, size); } -void mem_move(void *dest, const void *source, unsigned size) +void mem_move(void *dest, const void *source, size_t size) { memmove(dest, source, size); } -void mem_zero(void *block, unsigned size) +void mem_zero(void *block, size_t size) { memset(block, 0, size); } +int mem_comp(const void *a, const void *b, size_t size) +{ + return memcmp(a, b, size); +} + +bool mem_has_null(const void *block, size_t size) +{ + const unsigned char *bytes = (const unsigned char *)block; + for(size_t i = 0; i < size; i++) + { + if(bytes[i] == 0) + { + return true; + } + } + return false; +} + IOHANDLE io_open_impl(const char *filename, int flags) { dbg_assert(flags == (IOFLAG_READ | IOFLAG_SKIP_BOM) || flags == IOFLAG_READ || flags == IOFLAG_WRITE || flags == IOFLAG_APPEND, "flags must be read, read+skipbom, write or append"); @@ -3426,25 +3444,6 @@ void str_escape(char **dst, const char *src, const char *end) **dst = 0; } -int mem_comp(const void *a, const void *b, int size) -{ - return memcmp(a, b, size); -} - -int mem_has_null(const void *block, unsigned size) -{ - const unsigned char *bytes = (const unsigned char *)block; - unsigned i; - for(i = 0; i < size; i++) - { - if(bytes[i] == 0) - { - return 1; - } - } - return 0; -} - void net_stats(NETSTATS *stats_inout) { *stats_inout = network_stats; diff --git a/src/base/system.h b/src/base/system.h index 6ffcb1d6e..4b2a3ea7c 100644 --- a/src/base/system.h +++ b/src/base/system.h @@ -131,7 +131,7 @@ void dbg_msg(const char *sys, const char *fmt, ...) * * @see mem_move */ -void mem_copy(void *dest, const void *source, unsigned size); +void mem_copy(void *dest, const void *source, size_t size); /** * Copies a a memory block. @@ -146,7 +146,7 @@ void mem_copy(void *dest, const void *source, unsigned size); * * @see mem_copy */ -void mem_move(void *dest, const void *source, unsigned size); +void mem_move(void *dest, const void *source, size_t size); /** * Sets a complete memory block to 0. @@ -156,7 +156,7 @@ void mem_move(void *dest, const void *source, unsigned size); * @param block Pointer to the block to zero out. * @param size Size of the block. */ -void mem_zero(void *block, unsigned size); +void mem_zero(void *block, size_t size); /** * Compares two blocks of memory @@ -171,7 +171,7 @@ void mem_zero(void *block, unsigned size); * @return 0 - Block a is equal to block b. * @return > 0 - Block a is greater than block b. */ -int mem_comp(const void *a, const void *b, int size); +int mem_comp(const void *a, const void *b, size_t size); /** * Checks whether a block of memory contains null bytes. @@ -181,10 +181,9 @@ int mem_comp(const void *a, const void *b, int size); * @param block Pointer to the block to check for nulls. * @param size Size of the block. * - * @return 1 - The block has a null byte. - * @return 0 - The block does not have a null byte. + * @return true if the block has a null byte, false otherwise. */ -int mem_has_null(const void *block, unsigned size); +bool mem_has_null(const void *block, size_t size); /** * @defgroup File-IO diff --git a/src/engine/client/text.cpp b/src/engine/client/text.cpp index 443e624d8..3c8e0df41 100644 --- a/src/engine/client/text.cpp +++ b/src/engine/client/text.cpp @@ -540,7 +540,7 @@ class CTextRender : public IEngineTextRender if(Width > 0 && Height > 0) { // prepare glyph data - mem_zero(ms_aGlyphData, Width * Height); + mem_zero(ms_aGlyphData, (size_t)Width * Height); for(py = 0; py < pBitmap->rows; py++) for(px = 0; px < pBitmap->width; px++) diff --git a/src/game/editor/io.cpp b/src/game/editor/io.cpp index b5fd115a5..63eebb7a9 100644 --- a/src/game/editor/io.cpp +++ b/src/game/editor/io.cpp @@ -511,8 +511,9 @@ bool CEditorMap::Load(class IStorage *pStorage, const char *pFileName, int Stora // copy image data void *pData = DataFile.GetData(pItem->m_ImageData); - pImg->m_pData = malloc((size_t)pImg->m_Width * pImg->m_Height * 4); - mem_copy(pImg->m_pData, pData, pImg->m_Width * pImg->m_Height * 4); + const size_t DataSize = (size_t)pImg->m_Width * pImg->m_Height * 4; + pImg->m_pData = malloc(DataSize); + mem_copy(pImg->m_pData, pData, DataSize); int TextureLoadFlag = m_pEditor->Graphics()->HasTextureArrays() ? IGraphics::TEXLOAD_TO_2D_ARRAY_TEXTURE : IGraphics::TEXLOAD_TO_3D_TEXTURE; if(pImg->m_Width % 16 != 0 || pImg->m_Height % 16 != 0) TextureLoadFlag = 0; diff --git a/src/tools/map_optimize.cpp b/src/tools/map_optimize.cpp index 9602703ca..c0ac1b8bf 100644 --- a/src/tools/map_optimize.cpp +++ b/src/tools/map_optimize.cpp @@ -250,7 +250,7 @@ int main(int argc, const char **argv) } else if(aImageFlags[ImageIndex] == 0) { - mem_zero(pImgBuff, Width * Height * 4); + mem_zero(pImgBuff, (size_t)Width * Height * 4); } else {