mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-19 22:48:18 +00:00
Merge #6347
6347: Minor refactoring of base `mem_*` functions r=Chairn a=Robyt3 ## Checklist - [X] Tested the change ingame - [ ] Provided screenshots if it is a visual change - [ ] Tested in combination with possibly related configuration options - [ ] Written a unit test (especially base/) or added coverage to integration test - [ ] Considered possible null pointers and out of bounds array indexing - [ ] Changed no physics that affect existing maps - [ ] Tested the change with [ASan+UBSan or valgrind's memcheck](https://github.com/ddnet/ddnet/#using-addresssanitizer--undefinedbehavioursanitizer-or-valgrinds-memcheck) (optional) Co-authored-by: Robert Müller <robytemueller@gmail.com>
This commit is contained in:
commit
9532e23c87
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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++)
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue