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
     1.1 --- a/src/allocator.c	Sun Oct 03 12:04:27 2021 +0200
     1.2 +++ b/src/allocator.c	Sun Oct 03 13:07:48 2021 +0200
     1.3 @@ -30,17 +30,17 @@
     1.4  
     1.5  #include <stdlib.h>
     1.6  
     1.7 -__attribute__((__malloc__))
     1.8 +__attribute__((__malloc__, __alloc_size__(2)))
     1.9  static void *cx_malloc_stdlib(__attribute__((__unused__)) void *d, size_t n) {
    1.10      return malloc(n);
    1.11  }
    1.12  
    1.13 -__attribute__((__warn_unused_result__))
    1.14 +__attribute__((__warn_unused_result__, __alloc_size__(3)))
    1.15  static void *cx_realloc_stdlib(__attribute__((__unused__)) void *d, void *mem, size_t n) {
    1.16      return realloc(mem, n);
    1.17  }
    1.18  
    1.19 -__attribute__((__malloc__))
    1.20 +__attribute__((__malloc__, __alloc_size__(2, 3)))
    1.21  static void *cx_calloc_stdlib(__attribute__((__unused__)) void *d, size_t nelem, size_t n) {
    1.22      return calloc(nelem, n);
    1.23  }
     2.1 --- a/src/cx/allocator.h	Sun Oct 03 12:04:27 2021 +0200
     2.2 +++ b/src/cx/allocator.h	Sun Oct 03 13:07:48 2021 +0200
     2.3 @@ -121,7 +121,7 @@
     2.4   * @return a pointer to the allocated memory
     2.5   */
     2.6  void *cxMalloc(CxAllocator allocator, size_t n)
     2.7 -__attribute__((__malloc__));
     2.8 +__attribute__((__malloc__, __alloc_size__(2)));
     2.9  
    2.10  /**
    2.11   * Re-allocate the previously allocated block in \p mem, making the new block \p n bytes long.
    2.12 @@ -136,7 +136,7 @@
    2.13   * @return a pointer to the re-allocated memory
    2.14   */
    2.15  void *cxRealloc(CxAllocator allocator, void *mem, size_t n)
    2.16 -__attribute__((warn_unused_result));
    2.17 +__attribute__((__warn_unused_result__, __alloc_size__(3)));
    2.18  
    2.19  /**
    2.20   * Re-allocate a previously allocated block and changes the pointer in-place, if necessary.
    2.21 @@ -154,7 +154,7 @@
    2.22   * @return zero on success, non-zero on failure
    2.23   */
    2.24  int cxReallocate(CxAllocator allocator, void **mem, size_t n)
    2.25 -__attribute__((nonnull));
    2.26 +__attribute__((__nonnull__));
    2.27  
    2.28  /**
    2.29   * Allocate \p nelem elements of \p n bytes each, all initialized to zero.
    2.30 @@ -165,7 +165,7 @@
    2.31   * @return a pointer to the allocated memory
    2.32   */
    2.33  void *cxCalloc(CxAllocator allocator, size_t nelem, size_t n)
    2.34 -__attribute__((malloc));
    2.35 +__attribute__((__malloc__, __alloc_size__(2, 3)));
    2.36  
    2.37  /**
    2.38   * Free a block allocated by this allocator.
    2.39 @@ -176,7 +176,7 @@
    2.40   * @param mem a pointer to the block to free
    2.41   */
    2.42  void cxFree(CxAllocator allocator, void *mem)
    2.43 -__attribute__((nonnull));
    2.44 +__attribute__((__nonnull__));
    2.45  
    2.46  #ifdef __cplusplus
    2.47  } /* extern "C" */

mercurial