summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorjvoisin2023-07-18 23:07:05 +0200
committerjvoisin2023-07-18 23:07:05 +0200
commit9aa4490263ead62dc545cf0e8b83e0ef77eb7a6e (patch)
treedde291ce98e99e76bc9e085c35311f2942cac0c8 /include
parent8b6129312db7b2405f883c4080b835c69a855627 (diff)
Make use of the alloc_size attribute
Diffstat (limited to 'include')
-rw-r--r--include/fortify-headers.h7
-rw-r--r--include/stdlib.h23
2 files changed, 30 insertions, 0 deletions
diff --git a/include/fortify-headers.h b/include/fortify-headers.h
index 2f81fc0..dde19a2 100644
--- a/include/fortify-headers.h
+++ b/include/fortify-headers.h
@@ -78,6 +78,13 @@
78#define __malloc(...) 78#define __malloc(...)
79#endif 79#endif
80 80
81#if __has_attribute (alloc_size)
82#define __alloc_size(...) __attribute__ ((alloc_size (__VA_ARGS__)))
83#else
84#define __alloc_size(...)
85#endif
86
87
81#endif /* __has_attribute */ 88#endif /* __has_attribute */
82 89
83 90
diff --git a/include/stdlib.h b/include/stdlib.h
index b661862..6914f02 100644
--- a/include/stdlib.h
+++ b/include/stdlib.h
@@ -37,13 +37,36 @@ extern "C" {
37#endif 37#endif
38 38
39#undef malloc 39#undef malloc
40#undef realloc
40 41
41__malloc(malloc (free, 1)) 42__malloc(malloc (free, 1))
43__alloc_size(1)
42_FORTIFY_FN(malloc) void *malloc(size_t __s) 44_FORTIFY_FN(malloc) void *malloc(size_t __s)
43{ 45{
44 return __orig_malloc(__s); 46 return __orig_malloc(__s);
45} 47}
46 48
49__alloc_size(2)
50_FORTIFY_FN(realloc) void *realloc(void *__p, size_t __s)
51{
52 return __orig_realloc(__p, __s);
53}
54
55__alloc_size(1, 2)
56_FORTIFY_FN(calloc) void *calloc(size_t __n, size_t __s)
57{
58 return __orig_calloc(__n, __s);
59}
60
61#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
62#undef reallocarray
63__alloc_size (2, 3)
64_FORTIFY_FN(reallocarray) void* reallocarray(void* __p, size_t __n, size_t __s)
65{
66 return __orig_reallocarray(__p, __n, __s);
67}
68#endif
69
47/* FIXME clang */ 70/* FIXME clang */
48#if (defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE)) && !defined(__clang__) 71#if (defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE)) && !defined(__clang__)
49#undef realpath 72#undef realpath