Add alloc_size and malloc attributes to a few functions.
authorLasse Collin <lasse.collin@tukaani.org>
Tue, 18 Jan 2011 19:23:50 +0000 (21:23 +0200)
committerLasse Collin <lasse.collin@tukaani.org>
Tue, 18 Jan 2011 19:23:50 +0000 (21:23 +0200)
Thanks to Cristian Rodríguez for the original patch.

src/common/sysdefs.h
src/liblzma/common/common.h
src/xz/util.h

index 51f06cf..69370ba 100644 (file)
@@ -180,4 +180,10 @@ typedef unsigned char _Bool;
 #      define ARRAY_SIZE(array) (sizeof(array) / sizeof((array)[0]))
 #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
index 3a85168..b819432 100644 (file)
@@ -205,7 +205,7 @@ struct lzma_internal_s {
 
 /// Allocates memory
 extern void *lzma_alloc(size_t size, lzma_allocator *allocator)
-               lzma_attribute((malloc));
+               lzma_attribute((malloc)) lzma_attr_alloc_size(1);
 
 /// Frees memory
 extern void lzma_free(void *ptr, lzma_allocator *allocator);
index fea8cc6..4b2d3e2 100644 (file)
 
 
 /// \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
-extern char *xstrdup(const char *src);
+extern char *xstrdup(const char *src) lzma_attribute((malloc));
 
 
 /// \brief      Fancy version of strtoull()