From 671ca07d23b1ed8770fbebfe89d1682eb34b7dcb Mon Sep 17 00:00:00 2001 From: DL6ER Date: Mon, 11 Mar 2019 11:58:10 +0100 Subject: [PATCH] Add further attributes that give the compiler a hint how large the returned pointers might be. Signed-off-by: DL6ER --- memory.c | 4 ++-- routines.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/memory.c b/memory.c index 5612ef8d..503e84d1 100644 --- a/memory.c +++ b/memory.c @@ -166,7 +166,7 @@ char* __attribute__((malloc)) FTLstrdup(const char *src, const char * file, cons } #undef calloc -void* __attribute__((malloc)) FTLcalloc(size_t nmemb, size_t size, const char * file, const char * function, int line) +void* __attribute__((malloc)) __attribute__((alloc_size(1,2))) FTLcalloc(size_t nmemb, size_t size, const char * file, const char * function, int line) { // The FTLcalloc() function allocates memory for an array of nmemb elements // of size bytes each and returns a pointer to the allocated memory. The @@ -182,7 +182,7 @@ void* __attribute__((malloc)) FTLcalloc(size_t nmemb, size_t size, const char * } #undef realloc -void *FTLrealloc(void *ptr_in, size_t size, const char * file, const char * function, int line) +void __attribute__((alloc_size(2))) *FTLrealloc(void *ptr_in, size_t size, const char * file, const char * function, int line) { // The FTLrealloc() function changes the size of the memory block pointed to // by ptr to size bytes. The contents will be unchanged in the range from diff --git a/routines.h b/routines.h index e69ec674..89d5502c 100644 --- a/routines.h +++ b/routines.h @@ -94,8 +94,8 @@ void SQLite3LogCallback(void *pArg, int iErrCode, const char *zMsg); // memory.c void memory_check(int which); char *FTLstrdup(const char *src, const char *file, const char *function, int line) __attribute__((malloc)); -void *FTLcalloc(size_t nmemb, size_t size, const char *file, const char *function, int line) __attribute__((malloc)); -void *FTLrealloc(void *ptr_in, size_t size, const char *file, const char *function, int line); +void *FTLcalloc(size_t nmemb, size_t size, const char *file, const char *function, int line) __attribute__((malloc)) __attribute__((alloc_size(1,2))); +void *FTLrealloc(void *ptr_in, size_t size, const char *file, const char *function, int line) __attribute__((alloc_size(2))); void FTLfree(void *ptr, const char* file, const char *function, int line); void validate_access(const char * name, int pos, bool testmagic, int line, const char * function, const char * file);