diff options
author | Campbell Barton <ideasman42@gmail.com> | 2013-08-06 00:57:13 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2013-08-06 00:57:13 +0400 |
commit | ce2e2b141e67e5be8cc85bc394dc6ca9e15f774b (patch) | |
tree | 50508e0df59ab92fce66648e354a337d5de20fce | |
parent | b438c2840cbf533830ecb29b1ef65325d3f77f73 (diff) |
use gcc malloc attribute for low level allocation functions, prevents gcc from checking if resulting pointers alias existing pointers, also use sentinel attribute for uiButGetStrInfo so incorrect usage gives a warning.
-rw-r--r-- | intern/guardedalloc/MEM_guardedalloc.h | 6 | ||||
-rw-r--r-- | source/blender/blenlib/BLI_memarena.h | 2 | ||||
-rw-r--r-- | source/blender/blenlib/BLI_mempool.h | 5 | ||||
-rw-r--r-- | source/blender/blenlib/BLI_string.h | 8 | ||||
-rw-r--r-- | source/blender/editors/include/UI_interface.h | 6 |
5 files changed, 25 insertions, 2 deletions
diff --git a/intern/guardedalloc/MEM_guardedalloc.h b/intern/guardedalloc/MEM_guardedalloc.h index d46d7ad67bc..0939fe1cf86 100644 --- a/intern/guardedalloc/MEM_guardedalloc.h +++ b/intern/guardedalloc/MEM_guardedalloc.h @@ -98,6 +98,7 @@ extern "C" { * newly allocated block. */ void *MEM_dupallocN(const void *vmemh) #if MEM_GNU_ATTRIBUTES + __attribute__((malloc)) __attribute__((warn_unused_result)) #endif ; @@ -109,6 +110,7 @@ extern "C" { * over from existing memory. */ void *MEM_reallocN_id(void *vmemh, size_t len, const char *str) #if MEM_GNU_ATTRIBUTES + __attribute__((malloc)) __attribute__((warn_unused_result)) __attribute__((alloc_size(2))) #endif @@ -119,6 +121,7 @@ extern "C" { */ void *MEM_recallocN_id(void *vmemh, size_t len, const char *str) #if MEM_GNU_ATTRIBUTES + __attribute__((malloc)) __attribute__((warn_unused_result)) __attribute__((alloc_size(2))) #endif @@ -133,6 +136,7 @@ extern "C" { * pointer to it is stored ! */ void *MEM_callocN(size_t len, const char *str) #if MEM_GNU_ATTRIBUTES + __attribute__((malloc)) __attribute__((warn_unused_result)) __attribute__((nonnull(2))) __attribute__((alloc_size(1))) @@ -145,6 +149,7 @@ extern "C" { * */ void *MEM_mallocN(size_t len, const char *str) #if MEM_GNU_ATTRIBUTES + __attribute__((malloc)) __attribute__((warn_unused_result)) __attribute__((nonnull(2))) __attribute__((alloc_size(1))) @@ -157,6 +162,7 @@ extern "C" { * */ void *MEM_mapallocN(size_t len, const char *str) #if MEM_GNU_ATTRIBUTES + __attribute__((malloc)) __attribute__((warn_unused_result)) __attribute__((nonnull(2))) __attribute__((alloc_size(1))) diff --git a/source/blender/blenlib/BLI_memarena.h b/source/blender/blenlib/BLI_memarena.h index 092bb639b91..d54dab42e05 100644 --- a/source/blender/blenlib/BLI_memarena.h +++ b/source/blender/blenlib/BLI_memarena.h @@ -55,6 +55,7 @@ typedef struct MemArena MemArena; struct MemArena *BLI_memarena_new(const int bufsize, const char *name) #if MEM_GNU_ATTRIBUTES +__attribute__((malloc)) __attribute__((warn_unused_result)) __attribute__((nonnull(2))) #endif @@ -85,6 +86,7 @@ __attribute__((nonnull(1))) void *BLI_memarena_alloc(struct MemArena *ma, int size) #if MEM_GNU_ATTRIBUTES +__attribute__((malloc)) __attribute__((warn_unused_result)) __attribute__((nonnull(1))) __attribute__((alloc_size(2))) diff --git a/source/blender/blenlib/BLI_mempool.h b/source/blender/blenlib/BLI_mempool.h index f8775342e94..1c470d59062 100644 --- a/source/blender/blenlib/BLI_mempool.h +++ b/source/blender/blenlib/BLI_mempool.h @@ -50,17 +50,20 @@ typedef struct BLI_mempool BLI_mempool; BLI_mempool *BLI_mempool_create(int esize, int totelem, int pchunk, int flag) #ifdef __GNUC__ +__attribute__((malloc)) __attribute__((warn_unused_result)) #endif ; void *BLI_mempool_alloc(BLI_mempool *pool) #ifdef __GNUC__ +__attribute__((malloc)) __attribute__((warn_unused_result)) __attribute__((nonnull(1))) #endif ; void *BLI_mempool_calloc(BLI_mempool *pool) #ifdef __GNUC__ +__attribute__((malloc)) __attribute__((warn_unused_result)) __attribute__((nonnull(1))) #endif @@ -94,6 +97,7 @@ __attribute__((nonnull(1, 2))) void **BLI_mempool_as_tableN(BLI_mempool *pool, const char *allocstr) #ifdef __GNUC__ +__attribute__((malloc)) __attribute__((warn_unused_result)) __attribute__((nonnull(1, 2))) #endif @@ -107,6 +111,7 @@ __attribute__((nonnull(1, 2))) void *BLI_mempool_as_arrayN(BLI_mempool *pool, const char *allocstr) #ifdef __GNUC__ +__attribute__((malloc)) __attribute__((warn_unused_result)) __attribute__((nonnull(1, 2))) #endif diff --git a/source/blender/blenlib/BLI_string.h b/source/blender/blenlib/BLI_string.h index 4816ac19fce..6c66d2f4e18 100644 --- a/source/blender/blenlib/BLI_string.h +++ b/source/blender/blenlib/BLI_string.h @@ -40,6 +40,7 @@ extern "C" { char *BLI_strdupn(const char *str, const size_t len) #ifdef __GNUC__ +__attribute__((malloc)) __attribute__((warn_unused_result)) __attribute__((nonnull)) #endif @@ -47,6 +48,7 @@ __attribute__((nonnull)) char *BLI_strdup(const char *str) #ifdef __GNUC__ +__attribute__((malloc)) __attribute__((warn_unused_result)) __attribute__((nonnull)) #endif @@ -54,6 +56,7 @@ __attribute__((nonnull)) char *BLI_strdupcat(const char *__restrict str1, const char *__restrict str2) #ifdef __GNUC__ +__attribute__((malloc)) __attribute__((warn_unused_result)) __attribute__((nonnull)) #endif @@ -81,6 +84,7 @@ __attribute__((nonnull)) char *BLI_str_quoted_substrN(const char *__restrict str, const char *__restrict prefix) #ifdef __GNUC__ +__attribute__((malloc)) __attribute__((warn_unused_result)) __attribute__((nonnull)) #endif @@ -88,6 +92,7 @@ __attribute__((nonnull)) char *BLI_replacestrN(const char *__restrict str, const char *__restrict substr_old, const char *__restrict substr_new) #ifdef __GNUC__ +__attribute__((malloc)) __attribute__((warn_unused_result)) __attribute__((nonnull)) #endif @@ -108,6 +113,7 @@ __attribute__ ((format(printf, 3, 0))) char *BLI_sprintfN(const char *__restrict format, ...) #ifdef __GNUC__ +__attribute__((malloc)) __attribute__ ((format(printf, 1, 2))) __attribute__((warn_unused_result)) __attribute__((nonnull)) @@ -183,4 +189,4 @@ __attribute__((nonnull)) } #endif -#endif +#endif /* __BLI_STRING_H__ */ diff --git a/source/blender/editors/include/UI_interface.h b/source/blender/editors/include/UI_interface.h index 2daab072435..9a9cab9b46c 100644 --- a/source/blender/editors/include/UI_interface.h +++ b/source/blender/editors/include/UI_interface.h @@ -550,7 +550,11 @@ typedef struct uiStringInfo { /* Note: Expects pointers to uiStringInfo structs as parameters. * Will fill them with translated strings, when possible. * Strings in uiStringInfo must be MEM_freeN'ed by caller. */ -void uiButGetStrInfo(struct bContext *C, uiBut *but, ...); +void uiButGetStrInfo(struct bContext *C, uiBut *but, ...) +#ifdef __GNUC__ +__attribute__((sentinel)) +#endif +; /* Edit i18n stuff. */ /* Name of the main py op from i18n addon. */ |