summaryrefslogtreecommitdiff
path: root/include/string.h
diff options
context:
space:
mode:
authorjvoisin2023-09-21 15:50:32 +0200
committerjvoisin2023-09-21 15:50:32 +0200
commit8c2352b985b1bf69efb965ba15f5e300eb7e8e12 (patch)
tree9901e915156ca32c0b9f006f3139ba34958f68ef /include/string.h
parent46add4c4aecbbb8edb4b70ac5ed3a8c144f497ee (diff)
Properly enable diagnose_as_builtin attribute
Diffstat (limited to 'include/string.h')
-rw-r--r--include/string.h26
1 files changed, 22 insertions, 4 deletions
diff --git a/include/string.h b/include/string.h
index 010b7f2..2735b55 100644
--- a/include/string.h
+++ b/include/string.h
@@ -40,7 +40,9 @@ extern "C" {
40 40
41__access(write_only, 1, 3) 41__access(write_only, 1, 3)
42__access(read_only, 2, 3) 42__access(read_only, 2, 3)
43#if __has_builtin(__builtin_mempcpy)
43__diagnose_as_builtin(__builtin_memcpy, 1, 2, 3) 44__diagnose_as_builtin(__builtin_memcpy, 1, 2, 3)
45#endif
44_FORTIFY_FN(memcpy) void *memcpy(void * _FORTIFY_POS0 __od, 46_FORTIFY_FN(memcpy) void *memcpy(void * _FORTIFY_POS0 __od,
45 const void * _FORTIFY_POS0 __os, size_t __n) 47 const void * _FORTIFY_POS0 __os, size_t __n)
46__error_if((__bos(__od, 0) < __n), "'memcpy' called with `n` bigger than the size of `d`.") 48__error_if((__bos(__od, 0) < __n), "'memcpy' called with `n` bigger than the size of `d`.")
@@ -59,7 +61,9 @@ __error_if((__bos(__od, 0) < __n), "'memcpy' called with `n` bigger than the siz
59 61
60__access(write_only, 1, 3) 62__access(write_only, 1, 3)
61__access(read_only, 2, 3) 63__access(read_only, 2, 3)
64#if __has_builtin(__builtin_memmove)
62__diagnose_as_builtin(__builtin_memmove, 1, 2, 3) 65__diagnose_as_builtin(__builtin_memmove, 1, 2, 3)
66#endif
63_FORTIFY_FN(memmove) void *memmove(void * _FORTIFY_POS0 __d, 67_FORTIFY_FN(memmove) void *memmove(void * _FORTIFY_POS0 __d,
64 const void * _FORTIFY_POS0 __s, size_t __n) 68 const void * _FORTIFY_POS0 __s, size_t __n)
65{ 69{
@@ -72,7 +76,9 @@ _FORTIFY_FN(memmove) void *memmove(void * _FORTIFY_POS0 __d,
72} 76}
73 77
74__access(write_only, 1, 3) 78__access(write_only, 1, 3)
79#if __has_builtin(__builtin_memset)
75__diagnose_as_builtin(__builtin_memset, 1, 2, 3) 80__diagnose_as_builtin(__builtin_memset, 1, 2, 3)
81#endif
76_FORTIFY_FN(memset) void *memset(void * _FORTIFY_POS0 __d, int __c, size_t __n) 82_FORTIFY_FN(memset) void *memset(void * _FORTIFY_POS0 __d, int __c, size_t __n)
77__warning_if(__c != 0 && __n == 0, "'memset' will set `0` bytes; did you invert the arguments?") 83__warning_if(__c != 0 && __n == 0, "'memset' will set `0` bytes; did you invert the arguments?")
78{ 84{
@@ -84,7 +90,9 @@ __warning_if(__c != 0 && __n == 0, "'memset' will set `0` bytes; did you invert
84} 90}
85 91
86__access(read_only, 1, 3) 92__access(read_only, 1, 3)
93#if __has_builtin(__builtin_memchr)
87__diagnose_as_builtin(__builtin_memchr, 1, 2, 3) 94__diagnose_as_builtin(__builtin_memchr, 1, 2, 3)
95#endif
88_FORTIFY_FN(memchr) void *memchr(const void * _FORTIFY_POS0 __d, int __c, size_t __n) 96_FORTIFY_FN(memchr) void *memchr(const void * _FORTIFY_POS0 __d, int __c, size_t __n)
89{ 97{
90 size_t __b = __bos(__d, 0); 98 size_t __b = __bos(__d, 0);
@@ -95,7 +103,6 @@ _FORTIFY_FN(memchr) void *memchr(const void * _FORTIFY_POS0 __d, int __c, size_t
95} 103}
96 104
97__access(read_only, 1, 2) 105__access(read_only, 1, 2)
98__diagnose_as_builtin(__builtin_strchr, 1, 2, 3)
99_FORTIFY_FN(strchr) char *strchr(const char * _FORTIFY_POS0 __s, int __c) 106_FORTIFY_FN(strchr) char *strchr(const char * _FORTIFY_POS0 __s, int __c)
100{ 107{
101 size_t __b = __bos(__s, 0); 108 size_t __b = __bos(__s, 0);
@@ -107,7 +114,6 @@ _FORTIFY_FN(strchr) char *strchr(const char * _FORTIFY_POS0 __s, int __c)
107} 114}
108 115
109__access(read_only, 1, 2) 116__access(read_only, 1, 2)
110__diagnose_as_builtin(__builtin_strrchr, 1, 2, 3)
111_FORTIFY_FN(strrchr) char *strrchr(const char * _FORTIFY_POS0 __s, int __c) 117_FORTIFY_FN(strrchr) char *strrchr(const char * _FORTIFY_POS0 __s, int __c)
112{ 118{
113 size_t __b = __bos(__s, 0); 119 size_t __b = __bos(__s, 0);
@@ -124,7 +130,9 @@ _FORTIFY_FN(strrchr) char *strrchr(const char * _FORTIFY_POS0 __s, int __c)
124#undef stpcpy 130#undef stpcpy
125__access(write_only, 1) 131__access(write_only, 1)
126__access(read_only, 2) 132__access(read_only, 2)
133#if __has_builtin(__builtin_stpcpy)
127__diagnose_as_builtin(__builtin_stpcpy, 1, 2) 134__diagnose_as_builtin(__builtin_stpcpy, 1, 2)
135#endif
128_FORTIFY_FN(stpcpy) char *stpcpy(char * _FORTIFY_POS0 __d, const char *__s) 136_FORTIFY_FN(stpcpy) char *stpcpy(char * _FORTIFY_POS0 __d, const char *__s)
129{ 137{
130 size_t __n = strlen(__s) + 1; 138 size_t __n = strlen(__s) + 1;
@@ -141,7 +149,9 @@ _FORTIFY_FN(stpcpy) char *stpcpy(char * _FORTIFY_POS0 __d, const char *__s)
141#undef stpncpy 149#undef stpncpy
142__access(write_only, 1) 150__access(write_only, 1)
143__access(read_only, 2, 3) 151__access(read_only, 2, 3)
152#if __has_builtin(__builtin_stpncpy)
144__diagnose_as_builtin(__builtin_stpncpy, 1, 2, 3) 153__diagnose_as_builtin(__builtin_stpncpy, 1, 2, 3)
154#endif
145_FORTIFY_FN(stpncpy) char *stpncpy(char * _FORTIFY_POS0 __d, const char *__s, 155_FORTIFY_FN(stpncpy) char *stpncpy(char * _FORTIFY_POS0 __d, const char *__s,
146 size_t __n) 156 size_t __n)
147{ 157{
@@ -157,7 +167,9 @@ _FORTIFY_FN(stpncpy) char *stpncpy(char * _FORTIFY_POS0 __d, const char *__s,
157 167
158__access (read_write, 1) 168__access (read_write, 1)
159__access (read_only, 2) 169__access (read_only, 2)
170#if __has_builtin(__builtin_strcat)
160__diagnose_as_builtin(__builtin_strcat, 1, 2) 171__diagnose_as_builtin(__builtin_strcat, 1, 2)
172#endif
161_FORTIFY_FN(strcat) char *strcat(char * _FORTIFY_POS0 __d, const char *__s) 173_FORTIFY_FN(strcat) char *strcat(char * _FORTIFY_POS0 __d, const char *__s)
162{ 174{
163 size_t __b = __bos(__d, 0); 175 size_t __b = __bos(__d, 0);
@@ -169,7 +181,9 @@ _FORTIFY_FN(strcat) char *strcat(char * _FORTIFY_POS0 __d, const char *__s)
169 181
170__access (write_only, 1) 182__access (write_only, 1)
171__access (read_only, 2) 183__access (read_only, 2)
184#if __has_builtin(__builtin_strcpy)
172__diagnose_as_builtin(__builtin_strcpy, 1, 2) 185__diagnose_as_builtin(__builtin_strcpy, 1, 2)
186#endif
173_FORTIFY_FN(strcpy) char *strcpy(char * _FORTIFY_POS0 __d, const char *__s) 187_FORTIFY_FN(strcpy) char *strcpy(char * _FORTIFY_POS0 __d, const char *__s)
174{ 188{
175 size_t __n = strlen(__s) + 1; 189 size_t __n = strlen(__s) + 1;
@@ -185,7 +199,9 @@ _FORTIFY_FN(strcpy) char *strcpy(char * _FORTIFY_POS0 __d, const char *__s)
185 199
186__access (read_write, 1) 200__access (read_write, 1)
187__access (read_only, 2, 3) 201__access (read_only, 2, 3)
202#if __has_builtin(__builtin_strncat)
188__diagnose_as_builtin(__builtin_strncat, 1, 2, 3) 203__diagnose_as_builtin(__builtin_strncat, 1, 2, 3)
204#endif
189_FORTIFY_FN(strncat) char *strncat(char * _FORTIFY_POS0 __d, const char *__s, 205_FORTIFY_FN(strncat) char *strncat(char * _FORTIFY_POS0 __d, const char *__s,
190 size_t __n) 206 size_t __n)
191{ 207{
@@ -202,7 +218,9 @@ _FORTIFY_FN(strncat) char *strncat(char * _FORTIFY_POS0 __d, const char *__s,
202 218
203__access (write_only, 1) 219__access (write_only, 1)
204__access (read_only, 2, 3) 220__access (read_only, 2, 3)
221#if __has_builtin(__builtin_strncpy)
205__diagnose_as_builtin(__builtin_strncpy, 1, 2, 3) 222__diagnose_as_builtin(__builtin_strncpy, 1, 2, 3)
223#endif
206_FORTIFY_FN(strncpy) char *strncpy(char * _FORTIFY_POS0 __d, 224_FORTIFY_FN(strncpy) char *strncpy(char * _FORTIFY_POS0 __d,
207 const char *__s, size_t __n) 225 const char *__s, size_t __n)
208{ 226{
@@ -219,7 +237,9 @@ _FORTIFY_FN(strncpy) char *strncpy(char * _FORTIFY_POS0 __d,
219#undef mempcpy 237#undef mempcpy
220__access(write_only, 1) 238__access(write_only, 1)
221__access(read_only, 2, 3) 239__access(read_only, 2, 3)
240#if __has_builtin(__builtin_mempcpy)
222__diagnose_as_builtin(__builtin_mempcpy, 1, 2, 3) 241__diagnose_as_builtin(__builtin_mempcpy, 1, 2, 3)
242#endif
223_FORTIFY_FN(mempcpy) void *mempcpy(void * _FORTIFY_POS0 __d, 243_FORTIFY_FN(mempcpy) void *mempcpy(void * _FORTIFY_POS0 __d,
224 const void * _FORTIFY_POS0 __s, size_t __n) 244 const void * _FORTIFY_POS0 __s, size_t __n)
225{ 245{
@@ -237,7 +257,6 @@ _FORTIFY_FN(mempcpy) void *mempcpy(void * _FORTIFY_POS0 __d,
237#undef strlcpy 257#undef strlcpy
238__access (read_write, 1) 258__access (read_write, 1)
239__access (read_only, 2, 3) 259__access (read_only, 2, 3)
240__diagnose_as_builtin(__builtin_strlcat, 1, 2, 3)
241_FORTIFY_FN(strlcat) size_t strlcat(char * _FORTIFY_POS0 __d, 260_FORTIFY_FN(strlcat) size_t strlcat(char * _FORTIFY_POS0 __d,
242 const char *__s, size_t __n) 261 const char *__s, size_t __n)
243{ 262{
@@ -250,7 +269,6 @@ _FORTIFY_FN(strlcat) size_t strlcat(char * _FORTIFY_POS0 __d,
250 269
251__access (write_only, 1) 270__access (write_only, 1)
252__access (read_only, 2, 3) 271__access (read_only, 2, 3)
253__diagnose_as_builtin(__builtin_strlcpy, 1, 2, 3)
254_FORTIFY_FN(strlcpy) size_t strlcpy(char * _FORTIFY_POS0 __d, 272_FORTIFY_FN(strlcpy) size_t strlcpy(char * _FORTIFY_POS0 __d,
255 const char *__s, size_t __n) 273 const char *__s, size_t __n)
256{ 274{