add __alloc_size__ attribute

Sun, 03 Oct 2021 13:07:48 +0200

author
Mike Becker <universe@uap-core.de>
date
Sun, 03 Oct 2021 13:07:48 +0200
changeset 452
a10c3e127050
parent 451
db06dda7ac4d
child 453
bb144d08cd44

add __alloc_size__ attribute

src/allocator.c file | annotate | diff | comparison | revisions
src/cx/allocator.h file | annotate | diff | comparison | revisions
--- 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 <stdlib.h>
 
-__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);
 }
--- 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" */

mercurial