Ticket #238: 0001-attribute-alloc_size-for-newer-gccs.patch
| File 0001-attribute-alloc_size-for-newer-gccs.patch, 3.5 kB (added by MarcusMeissner, 4 months ago) |
|---|
-
a/avahi-common/gccmacro.h
old new 28 28 29 29 AVAHI_C_DECL_BEGIN 30 30 31 #if defined(__GNUC__) && (__GNUC__ >= 4) && (__GNUC_MINOR__ >= 3) 32 #define AVAHI_GCC_ALLOC_SIZE(x) __attribute__ ((__alloc_size__(x))) 33 #define AVAHI_GCC_ALLOC_SIZE2(x,y) __attribute__ ((__alloc_size__(x,y))) 34 #else 35 /** Macro for usage of GCC's alloc_size attribute */ 36 #define AVAHI_GCC_ALLOC_SIZE(x) 37 #define AVAHI_GCC_ALLOC_SIZE2(x,y) 38 #endif 39 31 40 #if defined(__GNUC__) && (__GNUC__ >= 4) 32 41 #define AVAHI_GCC_SENTINEL __attribute__ ((sentinel)) 33 42 #else -
a/avahi-common/malloc.h
old new 35 35 AVAHI_C_DECL_BEGIN 36 36 37 37 /** Allocate some memory, just like the libc malloc() */ 38 void *avahi_malloc(size_t size) ;38 void *avahi_malloc(size_t size) AVAHI_GCC_ALLOC_SIZE(1); 39 39 40 40 /** Similar to avahi_malloc() but set the memory to zero */ 41 void *avahi_malloc0(size_t size) ;41 void *avahi_malloc0(size_t size) AVAHI_GCC_ALLOC_SIZE(1); 42 42 43 43 /** Free some memory */ 44 44 void avahi_free(void *p); 45 45 46 46 /** Similar to libc's realloc() */ 47 void *avahi_realloc(void *p, size_t size) ;47 void *avahi_realloc(void *p, size_t size) AVAHI_GCC_ALLOC_SIZE(2); 48 48 49 49 /** Internal helper for avahi_new() */ 50 static inline void* avahi_new_internal(unsigned n, size_t k) {50 static inline void* AVAHI_GCC_ALLOC_SIZE2(1,2) avahi_new_internal(unsigned n, size_t k) { 51 51 assert(n < INT_MAX/k); 52 52 return avahi_malloc(n*k); 53 53 } … … 56 56 #define avahi_new(type, n) ((type*) avahi_new_internal((n), sizeof(type))) 57 57 58 58 /** Internal helper for avahi_new0() */ 59 static inline void* avahi_new0_internal(unsigned n, size_t k) {59 static inline void* AVAHI_GCC_ALLOC_SIZE2(1,2) avahi_new0_internal(unsigned n, size_t k) { 60 60 assert(n < INT_MAX/k); 61 61 return avahi_malloc0(n*k); 62 62 } … … 71 71 char *avahi_strndup(const char *s, size_t l); 72 72 73 73 /** Duplicate the given memory block into a new one allocated with avahi_malloc() */ 74 void *avahi_memdup(const void *s, size_t l) ;74 void *avahi_memdup(const void *s, size_t l) AVAHI_GCC_ALLOC_SIZE(2); 75 75 76 76 /** Wraps allocator functions */ 77 77 typedef struct AvahiAllocator { 78 void* (*malloc)(size_t size) ;79 void (*free)(void *p); 80 void* (*realloc)(void *p, size_t size) ;81 void* (*calloc)(size_t nmemb, size_t size) ; /**< May be NULL */78 void* (*malloc)(size_t size) AVAHI_GCC_ALLOC_SIZE(1); 79 void (*free)(void *p); 80 void* (*realloc)(void *p, size_t size) AVAHI_GCC_ALLOC_SIZE(2); 81 void* (*calloc)(size_t nmemb, size_t size) AVAHI_GCC_ALLOC_SIZE2(1,2); /**< May be NULL */ 82 82 } AvahiAllocator; 83 83 84 84 /** Change the allocator. May be NULL to return to default (libc)
