From: Davidlohr Bueso <dave@xxxxxxx> Date: Mon, 31 Jan 2011 15:42:07 -0300 When using an older version of GCC (3.0), the alloc_size attribute, used in xalloc.h does not exist, producing multiple warnings: warning: `__alloc_size__' attribute directive ignored This patch silences these messages. Signed-off-by: Davidlohr Bueso <dave@xxxxxxx> --- include/c.h | 7 +++++++ include/xalloc.h | 9 ++++++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/include/c.h b/include/c.h index b37c442..52a47c4 100644 --- a/include/c.h +++ b/include/c.h @@ -22,6 +22,13 @@ #endif /* !__GNUC__ */ +#if ((__GNUC__ * 100 + __GNUC__MINOR__) > 300) /* gcc version > 3.0 */ +# define ALLOCSZ_ATTR(x,...) __attribute__ ((alloc_size(x, ##__VA_ARGS__))) +#else +# define ALLOCSZ_ATTR(x,...) +#endif + + /* Force a compilation error if condition is true, but also produce a * result (of value 0 and type size_t), so the expression can be used * e.g. in a structure initializer (or where-ever else comma expressions diff --git a/include/xalloc.h b/include/xalloc.h index fc2f886..f7a5b9e 100644 --- a/include/xalloc.h +++ b/include/xalloc.h @@ -13,11 +13,14 @@ #include <stdlib.h> #include <err.h> +#include "c.h" + #ifndef XALLOC_EXIT_CODE # define XALLOC_EXIT_CODE EXIT_FAILURE #endif -static inline __attribute__((alloc_size(1))) + +static inline ALLOCSZ_ATTR(1) void *xmalloc(const size_t size) { void *ret = malloc(size); @@ -27,7 +30,7 @@ void *xmalloc(const size_t size) return ret; } -static inline __attribute__((alloc_size(2))) +static inline ALLOCSZ_ATTR(2) void *xrealloc(void *ptr, const size_t size) { void *ret = realloc(ptr, size); @@ -37,7 +40,7 @@ void *xrealloc(void *ptr, const size_t size) return ret; } -static inline __attribute__((alloc_size(1,2))) +static inline ALLOCSZ_ATTR(1,2) void *xcalloc(const size_t nelems, const size_t size) { void *ret = calloc(nelems, size); -- 1.7.1 -- To unsubscribe from this list: send the line "unsubscribe util-linux" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html