Index: include/stdlib.h =================================================================== --- include/stdlib.h +++ include/stdlib.h @@ -87,21 +87,21 @@ long atol(const char *); void *bsearch(const void *, const void *, size_t, size_t, int (*)(const void *, const void *)); -void *calloc(size_t, size_t) __malloc_like; +void *calloc(size_t, size_t) __malloc_like __w_unused_result __alloc_size(1, 2); div_t div(int, int) __pure2; _Noreturn void exit(int); void free(void *); char *getenv(const char *); long labs(long) __pure2; ldiv_t ldiv(long, long) __pure2; -void *malloc(size_t) __malloc_like; +void *malloc(size_t) __malloc_like __w_unused_result __alloc_size(1); int mblen(const char *, size_t); size_t mbstowcs(wchar_t * __restrict , const char * __restrict, size_t); int mbtowc(wchar_t * __restrict, const char * __restrict, size_t); void qsort(void *, size_t, size_t, int (*)(const void *, const void *)); int rand(void); -void *realloc(void *, size_t); +void *realloc(void *, size_t) __w_unused_result __alloc_size(2); void srand(unsigned); double strtod(const char * __restrict, char ** __restrict); float strtof(const char * __restrict, char ** __restrict); @@ -170,7 +170,7 @@ int rand_r(unsigned *); /* (TSF) */ #endif #if __POSIX_VISIBLE >= 200112 -int posix_memalign(void **, size_t, size_t); /* (ADV) */ +int posix_memalign(void **, size_t, size_t) __nonnull(1); /* (ADV) */ int setenv(const char *, const char *, int); int unsetenv(const char *); #endif Index: sys/sys/cdefs.h =================================================================== --- sys/sys/cdefs.h +++ sys/sys/cdefs.h @@ -40,6 +40,9 @@ * Testing against Clang-specific extensions. */ +#ifndef __has_attribute +#define __has_attribute(x) 0 +#endif #ifndef __has_extension #define __has_extension __has_feature #endif @@ -209,6 +212,7 @@ #define __unused #define __packed #define __aligned(x) +#define __alloc_size(...) #define __section(x) #define __weak #else @@ -233,6 +237,11 @@ #define __aligned(x) __attribute__((__aligned__(x))) #define __section(x) __attribute__((__section__(x))) #endif +#if __has_attribute(alloc_size) || __GNUC_PREREQ__(4, 3) +#define __alloc_size(...) __attribute__((alloc_size(__VA_ARGS__))) +#else +#define __alloc_size(...) +#endif #if defined(__INTEL_COMPILER) #define __dead2 __attribute__((__noreturn__)) #define __pure2 __attribute__((__const__)) @@ -242,7 +251,7 @@ #define __aligned(x) __attribute__((__aligned__(x))) #define __section(x) __attribute__((__section__(x))) #endif -#endif +#endif /* lint */ #if !__GNUC_PREREQ__(2, 95) #define __alignof(x) __offsetof(struct { char __a; x __b; }, __b) @@ -363,8 +372,10 @@ #if __GNUC_PREREQ__(3, 4) #define __fastcall __attribute__((__fastcall__)) +#define __w_unused_result __attribute__((__warn_unused_result__)) #else #define __fastcall +#define __w_unused_result #endif #if __GNUC_PREREQ__(4, 1)