fortify-headers

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

commit e8b8e4f51481121a5ce042812e7e62e7b27e6116
parent 254471b1c96c2ab34a043350519aea37a0862b9b
Author: jvoisin <julien.voisin@dustri.org>
Date:   Mon, 21 Aug 2023 17:22:28 +0200

Make use of __diagnose_if

Diffstat:
Minclude/fortify-headers.h | 8++++++++
Minclude/string.h | 1+
2 files changed, 9 insertions(+), 0 deletions(-)

diff --git a/include/fortify-headers.h b/include/fortify-headers.h @@ -99,6 +99,14 @@ #define __diagnose_as_builtin(...) #endif +#if __has_attribute (__diagnose_if) +#define __warning_if(cond, msg) __attribute__ ((__diagnose_if (cond, msg, "warning"))) +#define __error_if(cond, msg) __attribute__ ((__diagnose_if (cond, msg, "error"))) +#else +#define __warning_if(cond, msg) +#define __error_if(cond, msg) +#endif + #endif /* __has_attribute */ /* diff --git a/include/string.h b/include/string.h @@ -75,6 +75,7 @@ _FORTIFY_FN(memmove) void *memmove(void * _FORTIFY_POS0 __d, __access(write_only, 1, 3) __diagnose_as_builtin(__builtin_memset, 1, 2, 3) +__warning_if(__c != 0 && __n == 0, "'memset' will set `0` bytes; did you invert the arguments?") _FORTIFY_FN(memset) void *memset(void * _FORTIFY_POS0 __d, int __c, size_t __n) { size_t __b = __bos(__d, 0);