diff options
| author | jvoisin | 2023-09-21 15:50:32 +0200 |
|---|---|---|
| committer | jvoisin | 2023-09-21 15:50:32 +0200 |
| commit | 8c2352b985b1bf69efb965ba15f5e300eb7e8e12 (patch) | |
| tree | 9901e915156ca32c0b9f006f3139ba34958f68ef /include/string.h | |
| parent | 46add4c4aecbbb8edb4b70ac5ed3a8c144f497ee (diff) | |
Properly enable diagnose_as_builtin attribute
Diffstat (limited to 'include/string.h')
| -rw-r--r-- | include/string.h | 26 |
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 | { |
