Add alloc_size and malloc attributes to a few functions.

Thanks to Cristian Rodríguez for the original patch.
This commit is contained in:
Lasse Collin 2011-01-18 21:23:50 +02:00
parent 316cbe2446
commit f71c4e16e9
3 changed files with 10 additions and 3 deletions

View File

@ -180,4 +180,10 @@ typedef unsigned char _Bool;
# define ARRAY_SIZE(array) (sizeof(array) / sizeof((array)[0])) # define ARRAY_SIZE(array) (sizeof(array) / sizeof((array)[0]))
#endif #endif
#if (__GNUC__ == 4 && __GNUC_MINOR__ >= 3) || __GNUC__ > 4
# define lzma_attr_alloc_size(x) __attribute__((__alloc_size__(x)))
#else
# define lzma_attr_alloc_size(x)
#endif
#endif #endif

View File

@ -205,7 +205,7 @@ struct lzma_internal_s {
/// Allocates memory /// Allocates memory
extern void *lzma_alloc(size_t size, lzma_allocator *allocator) extern void *lzma_alloc(size_t size, lzma_allocator *allocator)
lzma_attribute((malloc)); lzma_attribute((malloc)) lzma_attr_alloc_size(1);
/// Frees memory /// Frees memory
extern void lzma_free(void *ptr, lzma_allocator *allocator); extern void lzma_free(void *ptr, lzma_allocator *allocator);

View File

@ -19,11 +19,12 @@
/// \brief Safe realloc() that never returns NULL /// \brief Safe realloc() that never returns NULL
extern void *xrealloc(void *ptr, size_t size); extern void *xrealloc(void *ptr, size_t size)
lzma_attribute((malloc)) lzma_attr_alloc_size(2);
/// \brief Safe strdup() that never returns NULL /// \brief Safe strdup() that never returns NULL
extern char *xstrdup(const char *src); extern char *xstrdup(const char *src) lzma_attribute((malloc));
/// \brief Fancy version of strtoull() /// \brief Fancy version of strtoull()