2
0
mirror of https://github.com/FWGS/xash3d-fwgs synced 2024-11-22 01:45:19 +01:00

common: add ALLOC_CHECK macro that enables attribute alloc_size on GCC that allows to prevent suspicious allocation sizes

This commit is contained in:
Alibek Omarov 2023-12-09 19:00:25 +03:00
parent 20ced857b4
commit 683c4874f8
7 changed files with 12 additions and 9 deletions

View File

@ -229,7 +229,7 @@ typedef struct render_api_s
void (*R_Reserved0)( void );
// static allocations
void *(*pfnMemAlloc)( size_t cb, const char *filename, const int fileline );
void *(*pfnMemAlloc)( size_t cb, const char *filename, const int fileline ) ALLOC_CHECK( 1 );
void (*pfnMemFree)( void *mem, const char *filename, const int fileline );
// engine utils (not related with render API but placed here)

View File

@ -88,18 +88,21 @@ typedef uint64_t longtime_t;
#define _format(x) __attribute__((format(printf, x, x+1)))
#define NORETURN __attribute__((noreturn))
#define NONNULL __attribute__((nonnull))
#define ALLOC_CHECK(x) __attribute__((alloc_size(x)))
#elif defined(_MSC_VER)
#define EXPORT __declspec( dllexport )
#define GAME_EXPORT
#define _format(x)
#define NORETURN
#define NONNULL
#define ALLOC_CHECK(x)
#else
#define EXPORT
#define GAME_EXPORT
#define _format(x)
#define NORETURN
#define NONNULL
#define ALLOC_CHECK(x)
#endif
#if ( __GNUC__ >= 3 )

View File

@ -422,8 +422,8 @@ void Cmd_Escape( char *newCommand, const char *oldCommand, int len );
// zone.c
//
void Memory_Init( void );
void *_Mem_Realloc( poolhandle_t poolptr, void *memptr, size_t size, qboolean clear, const char *filename, int fileline );
void *_Mem_Alloc( poolhandle_t poolptr, size_t size, qboolean clear, const char *filename, int fileline );
void *_Mem_Realloc( poolhandle_t poolptr, void *memptr, size_t size, qboolean clear, const char *filename, int fileline ) ALLOC_CHECK( 3 );
void *_Mem_Alloc( poolhandle_t poolptr, size_t size, qboolean clear, const char *filename, int fileline ) ALLOC_CHECK( 2 );
poolhandle_t _Mem_AllocPool( const char *name, const char *filename, int fileline );
void _Mem_FreePool( poolhandle_t *poolptr, const char *filename, int fileline );
void _Mem_EmptyPool( poolhandle_t poolptr, const char *filename, int fileline );

View File

@ -143,7 +143,7 @@ typedef struct ui_enginefuncs_s
void *(*pfnKeyGetState)( const char *name ); // for mlook, klook etc
// engine memory manager
void* (*pfnMemAlloc)( size_t cb, const char *filename, const int fileline );
void* (*pfnMemAlloc)( size_t cb, const char *filename, const int fileline ) ALLOC_CHECK( 1 );
void (*pfnMemFree)( void *mem, const char *filename, const int fileline );
// collect info from engine

View File

@ -86,7 +86,7 @@ typedef struct server_physics_api_s
const byte *(*pfnGetTextureData)( unsigned int texnum );
// static allocations
void *(*pfnMemAlloc)( size_t cb, const char *filename, const int fileline );
void *(*pfnMemAlloc)( size_t cb, const char *filename, const int fileline ) ALLOC_CHECK( 1 );
void (*pfnMemFree)( void *mem, const char *filename, const int fileline );
// trace & contents

View File

@ -361,8 +361,8 @@ typedef struct ref_api_s
// memory
poolhandle_t (*_Mem_AllocPool)( const char *name, const char *filename, int fileline );
void (*_Mem_FreePool)( poolhandle_t *poolptr, const char *filename, int fileline );
void *(*_Mem_Alloc)( poolhandle_t poolptr, size_t size, qboolean clear, const char *filename, int fileline );
void *(*_Mem_Realloc)( poolhandle_t poolptr, void *memptr, size_t size, qboolean clear, const char *filename, int fileline );
void *(*_Mem_Alloc)( poolhandle_t poolptr, size_t size, qboolean clear, const char *filename, int fileline ) ALLOC_CHECK( 2 );
void *(*_Mem_Realloc)( poolhandle_t poolptr, void *memptr, size_t size, qboolean clear, const char *filename, int fileline ) ALLOC_CHECK( 3 );
void (*_Mem_Free)( void *data, const char *filename, int fileline );
// library management

View File

@ -210,8 +210,8 @@ typedef struct fs_interface_t
// memory
poolhandle_t (*_Mem_AllocPool)( const char *name, const char *filename, int fileline );
void (*_Mem_FreePool)( poolhandle_t *poolptr, const char *filename, int fileline );
void *(*_Mem_Alloc)( poolhandle_t poolptr, size_t size, qboolean clear, const char *filename, int fileline );
void *(*_Mem_Realloc)( poolhandle_t poolptr, void *memptr, size_t size, qboolean clear, const char *filename, int fileline );
void *(*_Mem_Alloc)( poolhandle_t poolptr, size_t size, qboolean clear, const char *filename, int fileline ) ALLOC_CHECK( 2 );
void *(*_Mem_Realloc)( poolhandle_t poolptr, void *memptr, size_t size, qboolean clear, const char *filename, int fileline ) ALLOC_CHECK( 3 );
void (*_Mem_Free)( void *data, const char *filename, int fileline );
// platform