# HG changeset patch # User Mike Becker # Date 1633259268 -7200 # Node ID a10c3e12705050082d640f894acb4202dc8e849c # Parent db06dda7ac4d9aedaa25809cda3b7ff0cf2e2b16 add __alloc_size__ attribute diff -r db06dda7ac4d -r a10c3e127050 src/allocator.c --- a/src/allocator.c Sun Oct 03 12:04:27 2021 +0200 +++ b/src/allocator.c Sun Oct 03 13:07:48 2021 +0200 @@ -30,17 +30,17 @@ #include -__attribute__((__malloc__)) +__attribute__((__malloc__, __alloc_size__(2))) static void *cx_malloc_stdlib(__attribute__((__unused__)) void *d, size_t n) { return malloc(n); } -__attribute__((__warn_unused_result__)) +__attribute__((__warn_unused_result__, __alloc_size__(3))) static void *cx_realloc_stdlib(__attribute__((__unused__)) void *d, void *mem, size_t n) { return realloc(mem, n); } -__attribute__((__malloc__)) +__attribute__((__malloc__, __alloc_size__(2, 3))) static void *cx_calloc_stdlib(__attribute__((__unused__)) void *d, size_t nelem, size_t n) { return calloc(nelem, n); } diff -r db06dda7ac4d -r a10c3e127050 src/cx/allocator.h --- a/src/cx/allocator.h Sun Oct 03 12:04:27 2021 +0200 +++ b/src/cx/allocator.h Sun Oct 03 13:07:48 2021 +0200 @@ -121,7 +121,7 @@ * @return a pointer to the allocated memory */ void *cxMalloc(CxAllocator allocator, size_t n) -__attribute__((__malloc__)); +__attribute__((__malloc__, __alloc_size__(2))); /** * Re-allocate the previously allocated block in \p mem, making the new block \p n bytes long. @@ -136,7 +136,7 @@ * @return a pointer to the re-allocated memory */ void *cxRealloc(CxAllocator allocator, void *mem, size_t n) -__attribute__((warn_unused_result)); +__attribute__((__warn_unused_result__, __alloc_size__(3))); /** * Re-allocate a previously allocated block and changes the pointer in-place, if necessary. @@ -154,7 +154,7 @@ * @return zero on success, non-zero on failure */ int cxReallocate(CxAllocator allocator, void **mem, size_t n) -__attribute__((nonnull)); +__attribute__((__nonnull__)); /** * Allocate \p nelem elements of \p n bytes each, all initialized to zero. @@ -165,7 +165,7 @@ * @return a pointer to the allocated memory */ void *cxCalloc(CxAllocator allocator, size_t nelem, size_t n) -__attribute__((malloc)); +__attribute__((__malloc__, __alloc_size__(2, 3))); /** * Free a block allocated by this allocator. @@ -176,7 +176,7 @@ * @param mem a pointer to the block to free */ void cxFree(CxAllocator allocator, void *mem) -__attribute__((nonnull)); +__attribute__((__nonnull__)); #ifdef __cplusplus } /* extern "C" */