From 36a88e82ebd8cda894292c7071cb1256592221aa Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Sat, 30 Jul 2016 09:58:15 -0700 Subject: [PATCH] Restore attribute alloc_size for GCC. clang doesn't support attribute alloc_size, but GCC uses it to give diagnostics where clang can't, and we had a test for one such case. Bug: http://b/30513330 Change-Id: I4c14771258992d6bea684db7f91d60312642662f --- libc/include/malloc.h | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/libc/include/malloc.h b/libc/include/malloc.h index 07d7896b3..7452e535f 100644 --- a/libc/include/malloc.h +++ b/libc/include/malloc.h @@ -23,12 +23,18 @@ __BEGIN_DECLS -void* malloc(size_t byte_count) __mallocfunc __wur; -void* calloc(size_t item_count, size_t item_size) __mallocfunc __wur; -void* realloc(void* p, size_t byte_count) __wur; +#if defined(__clang__) +#define __BIONIC_ALLOC_SIZE(...) /* clang doesn't support attribute alloc_size. */ +#else +#define __BIONIC_ALLOC_SIZE(...) __attribute__((__alloc_size__(__VA_ARGS__))) +#endif + +void* malloc(size_t byte_count) __mallocfunc __BIONIC_ALLOC_SIZE(1) __wur; +void* calloc(size_t item_count, size_t item_size) __mallocfunc __BIONIC_ALLOC_SIZE(1,2) __wur; +void* realloc(void* p, size_t byte_count) __BIONIC_ALLOC_SIZE(2) __wur; void free(void* p); -void* memalign(size_t alignment, size_t byte_count) __mallocfunc __wur; +void* memalign(size_t alignment, size_t byte_count) __mallocfunc __BIONIC_ALLOC_SIZE(2) __wur; size_t malloc_usable_size(const void* p) __INTRODUCED_IN(17); #ifndef STRUCT_MALLINFO_DECLARED -- 2.11.0