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 ); void (*R_Reserved0)( void );
// static allocations // 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 ); void (*pfnMemFree)( void *mem, const char *filename, const int fileline );
// engine utils (not related with render API but placed here) // 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 _format(x) __attribute__((format(printf, x, x+1)))
#define NORETURN __attribute__((noreturn)) #define NORETURN __attribute__((noreturn))
#define NONNULL __attribute__((nonnull)) #define NONNULL __attribute__((nonnull))
#define ALLOC_CHECK(x) __attribute__((alloc_size(x)))
#elif defined(_MSC_VER) #elif defined(_MSC_VER)
#define EXPORT __declspec( dllexport ) #define EXPORT __declspec( dllexport )
#define GAME_EXPORT #define GAME_EXPORT
#define _format(x) #define _format(x)
#define NORETURN #define NORETURN
#define NONNULL #define NONNULL
#define ALLOC_CHECK(x)
#else #else
#define EXPORT #define EXPORT
#define GAME_EXPORT #define GAME_EXPORT
#define _format(x) #define _format(x)
#define NORETURN #define NORETURN
#define NONNULL #define NONNULL
#define ALLOC_CHECK(x)
#endif #endif
#if ( __GNUC__ >= 3 ) #if ( __GNUC__ >= 3 )

View File

@ -422,8 +422,8 @@ void Cmd_Escape( char *newCommand, const char *oldCommand, int len );
// zone.c // zone.c
// //
void Memory_Init( void ); void Memory_Init( void );
void *_Mem_Realloc( poolhandle_t poolptr, void *memptr, 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 ); 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 ); 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_FreePool( poolhandle_t *poolptr, const char *filename, int fileline );
void _Mem_EmptyPool( 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 void *(*pfnKeyGetState)( const char *name ); // for mlook, klook etc
// engine memory manager // 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 ); void (*pfnMemFree)( void *mem, const char *filename, const int fileline );
// collect info from engine // collect info from engine

View File

@ -86,7 +86,7 @@ typedef struct server_physics_api_s
const byte *(*pfnGetTextureData)( unsigned int texnum ); const byte *(*pfnGetTextureData)( unsigned int texnum );
// static allocations // 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 ); void (*pfnMemFree)( void *mem, const char *filename, const int fileline );
// trace & contents // trace & contents

View File

@ -361,8 +361,8 @@ typedef struct ref_api_s
// memory // memory
poolhandle_t (*_Mem_AllocPool)( const char *name, const char *filename, int fileline ); 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_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_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 ); 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 ); void (*_Mem_Free)( void *data, const char *filename, int fileline );
// library management // library management

View File

@ -210,8 +210,8 @@ typedef struct fs_interface_t
// memory // memory
poolhandle_t (*_Mem_AllocPool)( const char *name, const char *filename, int fileline ); 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_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_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 ); 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 ); void (*_Mem_Free)( void *data, const char *filename, int fileline );
// platform // platform