fortify-headers

standalone fortify-source implementation
git clone git://git.2f30.org/fortify-headers
Log | Files | Refs | README | LICENSE

commit 5ce4b94b7ac1d529b42ac76609b686d1ba0dffcb
parent 07da6751b9d1a6498e81c9d3b97ec3b552fa0b38
Author: jvoisin <julien.voisin@dustri.org>
Date:   Mon, 11 Sep 2023 17:41:31 +0200

Add the warn_unused_result attribute to alloc-related functions

Diffstat:
Minclude/fortify-headers.h | 7+++++++
Minclude/stdlib.h | 4++++
2 files changed, 11 insertions(+), 0 deletions(-)

diff --git a/include/fortify-headers.h b/include/fortify-headers.h @@ -110,6 +110,13 @@ #define __error_if(cond, msg) #endif +#if __has_attribute (warn_unused_result) +#define __warn_unused_result __attribute__ ((warn_unused_result)) +#else +#define __warn_unused_result +#endif + + #endif /* __has_attribute */ /* diff --git a/include/stdlib.h b/include/stdlib.h @@ -42,6 +42,7 @@ extern "C" { __malloc(malloc (free, 1)) __alloc_size(1) +__warn_unused_result __diagnose_as_builtin(__builtin_malloc, 1) _FORTIFY_FN(malloc) void *malloc(size_t __s) { @@ -49,6 +50,7 @@ _FORTIFY_FN(malloc) void *malloc(size_t __s) } __alloc_size(2) +__warn_unused_result __diagnose_as_builtin(__builtin_realloc, 1, 2) _FORTIFY_FN(realloc) void *realloc(void *__p, size_t __s) { @@ -56,6 +58,7 @@ _FORTIFY_FN(realloc) void *realloc(void *__p, size_t __s) } __alloc_size(1, 2) +__warn_unused_result __diagnose_as_builtin(__builtin_calloc, 1, 2) _FORTIFY_FN(calloc) void *calloc(size_t __n, size_t __s) { @@ -65,6 +68,7 @@ _FORTIFY_FN(calloc) void *calloc(size_t __n, size_t __s) #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) #undef reallocarray __alloc_size (2, 3) +__warn_unused_result __diagnose_as_builtin(__builtin_reallocarray, 1, 2, 3) _FORTIFY_FN(reallocarray) void* reallocarray(void* __p, size_t __n, size_t __s) {