summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorjvoisin2023-09-11 17:41:31 +0200
committerjvoisin2023-09-11 17:41:31 +0200
commit5ce4b94b7ac1d529b42ac76609b686d1ba0dffcb (patch)
tree6aaff589e9e302b28a9e517a5f2247676454967d /include
parent07da6751b9d1a6498e81c9d3b97ec3b552fa0b38 (diff)
Add the warn_unused_result attribute to alloc-related functions
Diffstat (limited to 'include')
-rw-r--r--include/fortify-headers.h7
-rw-r--r--include/stdlib.h4
2 files changed, 11 insertions, 0 deletions
diff --git a/include/fortify-headers.h b/include/fortify-headers.h
index dbace47..74c814b 100644
--- a/include/fortify-headers.h
+++ b/include/fortify-headers.h
@@ -110,6 +110,13 @@
110#define __error_if(cond, msg) 110#define __error_if(cond, msg)
111#endif 111#endif
112 112
113#if __has_attribute (warn_unused_result)
114#define __warn_unused_result __attribute__ ((warn_unused_result))
115#else
116#define __warn_unused_result
117#endif
118
119
113#endif /* __has_attribute */ 120#endif /* __has_attribute */
114 121
115/* 122/*
diff --git a/include/stdlib.h b/include/stdlib.h
index 4efdb82..2671280 100644
--- a/include/stdlib.h
+++ b/include/stdlib.h
@@ -42,6 +42,7 @@ extern "C" {
42 42
43__malloc(malloc (free, 1)) 43__malloc(malloc (free, 1))
44__alloc_size(1) 44__alloc_size(1)
45__warn_unused_result
45__diagnose_as_builtin(__builtin_malloc, 1) 46__diagnose_as_builtin(__builtin_malloc, 1)
46_FORTIFY_FN(malloc) void *malloc(size_t __s) 47_FORTIFY_FN(malloc) void *malloc(size_t __s)
47{ 48{
@@ -49,6 +50,7 @@ _FORTIFY_FN(malloc) void *malloc(size_t __s)
49} 50}
50 51
51__alloc_size(2) 52__alloc_size(2)
53__warn_unused_result
52__diagnose_as_builtin(__builtin_realloc, 1, 2) 54__diagnose_as_builtin(__builtin_realloc, 1, 2)
53_FORTIFY_FN(realloc) void *realloc(void *__p, size_t __s) 55_FORTIFY_FN(realloc) void *realloc(void *__p, size_t __s)
54{ 56{
@@ -56,6 +58,7 @@ _FORTIFY_FN(realloc) void *realloc(void *__p, size_t __s)
56} 58}
57 59
58__alloc_size(1, 2) 60__alloc_size(1, 2)
61__warn_unused_result
59__diagnose_as_builtin(__builtin_calloc, 1, 2) 62__diagnose_as_builtin(__builtin_calloc, 1, 2)
60_FORTIFY_FN(calloc) void *calloc(size_t __n, size_t __s) 63_FORTIFY_FN(calloc) void *calloc(size_t __n, size_t __s)
61{ 64{
@@ -65,6 +68,7 @@ _FORTIFY_FN(calloc) void *calloc(size_t __n, size_t __s)
65#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) 68#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
66#undef reallocarray 69#undef reallocarray
67__alloc_size (2, 3) 70__alloc_size (2, 3)
71__warn_unused_result
68__diagnose_as_builtin(__builtin_reallocarray, 1, 2, 3) 72__diagnose_as_builtin(__builtin_reallocarray, 1, 2, 3)
69_FORTIFY_FN(reallocarray) void* reallocarray(void* __p, size_t __n, size_t __s) 73_FORTIFY_FN(reallocarray) void* reallocarray(void* __p, size_t __n, size_t __s)
70{ 74{