commit 611069d07c14bf7ace7a75fa2bc9147db8ac097d
parent e9b6cb7e2eb7029902ae92ef43fb905e5072785b
Author: jvoisin <julien.voisin@dustri.org>
Date: Fri, 14 Nov 2025 16:25:52 +0100
Add __diagnose_if annotations
Diffstat:
3 files changed, 8 insertions(+), 0 deletions(-)
diff --git a/include/fortify-headers.h b/include/fortify-headers.h
@@ -73,6 +73,12 @@
#define __format(...)
#endif
+#if __has_attribute (__diagnose_if)
+#define __warning_if(cond, msg) __attribute__ ((__diagnose_if (cond, msg, "warning")))
+#else
+#define __warning_if(cond, msg)
+#endif
+
#endif
#endif
diff --git a/include/stdlib.h b/include/stdlib.h
@@ -39,6 +39,7 @@ extern "C" {
/* FIXME clang */
#if (defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE)) && !defined(__clang__)
#undef realpath
+__warning_if(__p == NULL, "'realpath' called with path set to `NULL`; did you invert the arguments?")
_FORTIFY_FN(realpath) char *realpath(const char *__p, char *__r)
{
#ifndef PATH_MAX
diff --git a/include/string.h b/include/string.h
@@ -71,6 +71,7 @@ _FORTIFY_FN(memmove) void *memmove(void * _FORTIFY_POS0 __d,
}
__access(write_only, 1, 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);