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)

/suse/meissner/0001-attribute-alloc_size-for-newer-gccs.patch

  • a/avahi-common/gccmacro.h

    old new  
    2828 
    2929AVAHI_C_DECL_BEGIN 
    3030 
     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 
    3140#if defined(__GNUC__) && (__GNUC__ >= 4) 
    3241#define AVAHI_GCC_SENTINEL __attribute__ ((sentinel)) 
    3342#else 
  • a/avahi-common/malloc.h

    old new  
    3535AVAHI_C_DECL_BEGIN 
    3636 
    3737/** Allocate some memory, just like the libc malloc() */ 
    38 void *avahi_malloc(size_t size)
     38void *avahi_malloc(size_t size) AVAHI_GCC_ALLOC_SIZE(1)
    3939 
    4040/** Similar to avahi_malloc() but set the memory to zero */ 
    41 void *avahi_malloc0(size_t size)
     41void *avahi_malloc0(size_t size) AVAHI_GCC_ALLOC_SIZE(1)
    4242 
    4343/** Free some memory */ 
    4444void avahi_free(void *p); 
    4545 
    4646/** Similar to libc's realloc() */ 
    47 void *avahi_realloc(void *p, size_t size)
     47void *avahi_realloc(void *p, size_t size) AVAHI_GCC_ALLOC_SIZE(2)
    4848 
    4949/** Internal helper for avahi_new() */ 
    50 static inline void* avahi_new_internal(unsigned n, size_t k) { 
     50static inline void* AVAHI_GCC_ALLOC_SIZE2(1,2) avahi_new_internal(unsigned n, size_t k) { 
    5151    assert(n < INT_MAX/k); 
    5252    return avahi_malloc(n*k); 
    5353} 
     
    5656#define avahi_new(type, n) ((type*) avahi_new_internal((n), sizeof(type))) 
    5757 
    5858/** Internal helper for avahi_new0() */ 
    59 static inline void* avahi_new0_internal(unsigned n, size_t k) { 
     59static inline void* AVAHI_GCC_ALLOC_SIZE2(1,2) avahi_new0_internal(unsigned n, size_t k) { 
    6060    assert(n < INT_MAX/k); 
    6161    return avahi_malloc0(n*k); 
    6262} 
     
    7171char *avahi_strndup(const char *s, size_t l); 
    7272 
    7373/** Duplicate the given memory block into a new one allocated with avahi_malloc() */ 
    74 void *avahi_memdup(const void *s, size_t l)
     74void *avahi_memdup(const void *s, size_t l) AVAHI_GCC_ALLOC_SIZE(2)
    7575 
    7676/** Wraps allocator functions */ 
    7777typedef 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 */ 
    8282} AvahiAllocator; 
    8383 
    8484/** Change the allocator. May be NULL to return to default (libc)