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 @@ -208,7 +211,9 @@ #define __pure2 #define __unused #define __packed +#define __w_unused_result #define __aligned(x) +#define __alloc_size(...) #define __section(x) #define __weak #else @@ -363,8 +368,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) @@ -373,6 +380,12 @@ #define __returns_twice #endif +#if __has_attribute(alloc_size) || __GNUC_PREREQ__(4, 3) +#define __alloc_size(...) __attribute__((alloc_size(__VA_ARGS__))) +#else +#define __alloc_size(...) +#endif + /* XXX: should use `#if __STDC_VERSION__ < 199901'. */ #if !__GNUC_PREREQ__(2, 7) && !defined(__INTEL_COMPILER) #define __func__ NULL