summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorq662023-12-15 23:48:58 +0100
committerq662023-12-15 23:50:43 +0100
commita018052d410126f94c2602b208b099839d333b05 (patch)
tree6fb36635689a4568f384e1cc7c2ae9f4e617ad58
parent95441d2647a149ffa6db4a81c0a19e96e3b56ba5 (diff)
Rename some macros to be more namespace-friendly
-rw-r--r--include/fortify-headers.h24
-rw-r--r--include/poll.h4
-rw-r--r--include/stdio.h86
-rw-r--r--include/stdlib.h26
-rw-r--r--include/string.h126
-rw-r--r--include/strings.h12
-rw-r--r--include/sys/select.h6
-rw-r--r--include/sys/socket.h16
-rw-r--r--include/unistd.h46
-rw-r--r--include/wchar.h28
10 files changed, 187 insertions, 187 deletions
diff --git a/include/fortify-headers.h b/include/fortify-headers.h
index 70b7952..9831a33 100644
--- a/include/fortify-headers.h
+++ b/include/fortify-headers.h
@@ -71,38 +71,38 @@
71 * See: 71 * See:
72 * - https://gcc.gnu.org/onlinedocs/gcc/Object-Size-Checking.html 72 * - https://gcc.gnu.org/onlinedocs/gcc/Object-Size-Checking.html
73 */ 73 */
74#define __bos(ptr, type) __builtin_dynamic_object_size (ptr, type) 74#define __fh_bos(ptr, type) __builtin_dynamic_object_size (ptr, type)
75#else 75#else
76#define __bos(ptr, type) __builtin_object_size (ptr, type) 76#define __fh_bos(ptr, type) __builtin_object_size (ptr, type)
77#endif 77#endif
78 78
79#if defined __has_attribute 79#if defined __has_attribute
80#if __has_attribute (access) 80#if __has_attribute (access)
81#define __access(...) __attribute__ ((access (__VA_ARGS__))) 81#define __fh_access(...) __attribute__ ((access (__VA_ARGS__)))
82#else 82#else
83#define __access(...) 83#define __fh_access(...)
84#endif 84#endif
85 85
86#if __has_attribute (format) 86#if __has_attribute (format)
87#define __format(...) __attribute__ ((format (__VA_ARGS__))) 87#define __fh_format(...) __attribute__ ((format (__VA_ARGS__)))
88#else 88#else
89#define __format(...) 89#define __fh_format(...)
90#endif 90#endif
91 91
92#if __has_attribute (malloc) 92#if __has_attribute (malloc)
93#ifdef __clang__ 93#ifdef __clang__
94#define __malloc(...) __attribute__ ((malloc)) 94#define __fh_malloc(...) __attribute__ ((malloc))
95#else 95#else
96#define __malloc(...) __attribute__ ((malloc, __VA_ARGS__)) 96#define __fh_malloc(...) __attribute__ ((malloc, __VA_ARGS__))
97#endif /* __clang__ */ 97#endif /* __clang__ */
98#else 98#else
99#define __malloc(...) 99#define __fh_malloc(...)
100#endif 100#endif
101 101
102#if __has_attribute (alloc_size) && !defined(__alloc_size) 102#if __has_attribute (alloc_size) && !defined(__fh_alloc_size)
103#define __alloc_size(...) __attribute__ ((alloc_size (__VA_ARGS__))) 103#define __fh_alloc_size(...) __attribute__ ((alloc_size (__VA_ARGS__)))
104#else 104#else
105#define __alloc_size(...) 105#define __fh_alloc_size(...)
106#endif 106#endif
107 107
108#if __has_attribute (diagnose_as_builtin) 108#if __has_attribute (diagnose_as_builtin)
diff --git a/include/poll.h b/include/poll.h
index 29e5c40..def2c69 100644
--- a/include/poll.h
+++ b/include/poll.h
@@ -36,7 +36,7 @@ __diagnose_as_builtin(__builtin_poll, 1, 2, 3)
36#endif 36#endif
37_FORTIFY_FN(poll) int poll(struct pollfd * _FORTIFY_POS0 __f, nfds_t __n, int __s) 37_FORTIFY_FN(poll) int poll(struct pollfd * _FORTIFY_POS0 __f, nfds_t __n, int __s)
38{ 38{
39 __fh_size_t __b = __bos(__f, 0); 39 __fh_size_t __b = __fh_bos(__f, 0);
40 40
41 if (__n > __b / sizeof(struct pollfd)) 41 if (__n > __b / sizeof(struct pollfd))
42 __builtin_trap(); 42 __builtin_trap();
@@ -51,7 +51,7 @@ __diagnose_as_builtin(__builtin_ppoll, 1, 2, 3, 4)
51_FORTIFY_FN(ppoll) int ppoll(struct pollfd * _FORTIFY_POS0 __f, nfds_t __n, 51_FORTIFY_FN(ppoll) int ppoll(struct pollfd * _FORTIFY_POS0 __f, nfds_t __n,
52 const struct timespec *__s, const sigset_t *__m) 52 const struct timespec *__s, const sigset_t *__m)
53{ 53{
54 __fh_size_t __b = __bos(__f, 0); 54 __fh_size_t __b = __fh_bos(__f, 0);
55 55
56 if (__n > __b / sizeof(struct pollfd)) 56 if (__n > __b / sizeof(struct pollfd))
57 __builtin_trap(); 57 __builtin_trap();
diff --git a/include/stdio.h b/include/stdio.h
index 59ae4ff..c6817fa 100644
--- a/include/stdio.h
+++ b/include/stdio.h
@@ -44,7 +44,7 @@ extern "C" {
44#undef fmemopen 44#undef fmemopen
45#undef popen 45#undef popen
46 46
47__access(read_only, 2) 47__fh_access(read_only, 2)
48#if __has_builtin(__builtin_fdopen) 48#if __has_builtin(__builtin_fdopen)
49__diagnose_as_builtin(__builtin_fdopen, 1, 2) 49__diagnose_as_builtin(__builtin_fdopen, 1, 2)
50#endif 50#endif
@@ -53,7 +53,7 @@ _FORTIFY_FN(fdopen) FILE *fdopen(int __f, const char* _FORTIFY_POS0 __m)
53 return __orig_fdopen(__f, __m); 53 return __orig_fdopen(__f, __m);
54} 54}
55 55
56__malloc(malloc (fclose, 1)) 56__fh_malloc(malloc (fclose, 1))
57#if __has_builtin(__builtin_fmemopen) 57#if __has_builtin(__builtin_fmemopen)
58__diagnose_as_builtin(__builtin_fmemopen, 1, 2, 3) 58__diagnose_as_builtin(__builtin_fmemopen, 1, 2, 3)
59#endif 59#endif
@@ -62,9 +62,9 @@ _FORTIFY_FN(fmemopen) FILE *fmemopen(void* _FORTIFY_POS0 __b, size_t __s, const
62 return __orig_fmemopen(__b, __s, __m); 62 return __orig_fmemopen(__b, __s, __m);
63} 63}
64 64
65__access(read_only, 1) 65__fh_access(read_only, 1)
66__access(read_only, 2) 66__fh_access(read_only, 2)
67__malloc(malloc (pclose, 1)) 67__fh_malloc(malloc (pclose, 1))
68#if __has_builtin(__builtin_popen) 68#if __has_builtin(__builtin_popen)
69__diagnose_as_builtin(__builtin_popen, 1, 2) 69__diagnose_as_builtin(__builtin_popen, 1, 2)
70#endif 70#endif
@@ -75,22 +75,22 @@ _FORTIFY_FN(popen) FILE *popen(const char* _FORTIFY_POS0 __c, const char* _FORTI
75 75
76#endif /* _POSIX_SOURCE || _POSIX_C_SOURCE || _XOPEN_SOURCE || _GNU_SOURCE || _BSD_SOURCE */ 76#endif /* _POSIX_SOURCE || _POSIX_C_SOURCE || _XOPEN_SOURCE || _GNU_SOURCE || _BSD_SOURCE */
77 77
78__access(write_only, 1, 2) 78__fh_access(write_only, 1, 2)
79#if __has_builtin(__builtin_fgets) 79#if __has_builtin(__builtin_fgets)
80__diagnose_as_builtin(__builtin_fgets, 1, 2, 3) 80__diagnose_as_builtin(__builtin_fgets, 1, 2, 3)
81#endif 81#endif
82_FORTIFY_FN(fgets) char *fgets(char * _FORTIFY_POS0 __s, int __n, FILE *__f) 82_FORTIFY_FN(fgets) char *fgets(char * _FORTIFY_POS0 __s, int __n, FILE *__f)
83{ 83{
84 __fh_size_t __b = __bos(__s, 0); 84 __fh_size_t __b = __fh_bos(__s, 0);
85 85
86 if ((__fh_size_t)__n > __b) 86 if ((__fh_size_t)__n > __b)
87 __builtin_trap(); 87 __builtin_trap();
88 return __orig_fgets(__s, __n, __f); 88 return __orig_fgets(__s, __n, __f);
89} 89}
90 90
91__access(read_only, 1) 91__fh_access(read_only, 1)
92__access(read_only, 2) 92__fh_access(read_only, 2)
93__malloc(malloc (fclose, 1)) 93__fh_malloc(malloc (fclose, 1))
94#if __has_builtin(__builtin_fopen) 94#if __has_builtin(__builtin_fopen)
95__diagnose_as_builtin(__builtin_fopen, 1, 2) 95__diagnose_as_builtin(__builtin_fopen, 1, 2)
96#endif 96#endif
@@ -99,14 +99,14 @@ _FORTIFY_FN(fopen) FILE *fopen(const char* _FORTIFY_POS0 __p, const char* _FORTI
99 return __orig_fopen(__p, __m); 99 return __orig_fopen(__p, __m);
100} 100}
101 101
102__access(write_only, 1) 102__fh_access(write_only, 1)
103#if __has_builtin(__builtin_fread) 103#if __has_builtin(__builtin_fread)
104__diagnose_as_builtin(__builtin_fread, 1, 2, 3, 4) 104__diagnose_as_builtin(__builtin_fread, 1, 2, 3, 4)
105#endif 105#endif
106_FORTIFY_FN(fread) size_t fread(void * _FORTIFY_POS0 __d, size_t __n, 106_FORTIFY_FN(fread) size_t fread(void * _FORTIFY_POS0 __d, size_t __n,
107 size_t __m, FILE *__f) 107 size_t __m, FILE *__f)
108{ 108{
109 __fh_size_t __b = __bos(__d, 0); 109 __fh_size_t __b = __fh_bos(__d, 0);
110 110
111 if (__bmo(__n, __m)) 111 if (__bmo(__n, __m))
112 __builtin_trap(); 112 __builtin_trap();
@@ -115,14 +115,14 @@ _FORTIFY_FN(fread) size_t fread(void * _FORTIFY_POS0 __d, size_t __n,
115 return __orig_fread(__d, __n, __m, __f); 115 return __orig_fread(__d, __n, __m, __f);
116} 116}
117 117
118__access(read_only, 1) 118__fh_access(read_only, 1)
119#if __has_builtin(__builtin_fwrite) 119#if __has_builtin(__builtin_fwrite)
120__diagnose_as_builtin(__builtin_fwrite, 1, 2, 3, 4) 120__diagnose_as_builtin(__builtin_fwrite, 1, 2, 3, 4)
121#endif 121#endif
122_FORTIFY_FN(fwrite) size_t fwrite(const void * _FORTIFY_POS0 __d, size_t __n, 122_FORTIFY_FN(fwrite) size_t fwrite(const void * _FORTIFY_POS0 __d, size_t __n,
123 size_t __m, FILE *__f) 123 size_t __m, FILE *__f)
124{ 124{
125 __fh_size_t __b = __bos(__d, 0); 125 __fh_size_t __b = __fh_bos(__d, 0);
126 126
127 if (__bmo(__n, __m)) 127 if (__bmo(__n, __m))
128 __builtin_trap(); 128 __builtin_trap();
@@ -133,7 +133,7 @@ _FORTIFY_FN(fwrite) size_t fwrite(const void * _FORTIFY_POS0 __d, size_t __n,
133 133
134#ifndef __clang__ /* FIXME */ 134#ifndef __clang__ /* FIXME */
135#undef tmpfile 135#undef tmpfile
136__malloc(malloc (fclose, 1)) 136__fh_malloc(malloc (fclose, 1))
137#if __has_builtin(__builtin_tmpfile) 137#if __has_builtin(__builtin_tmpfile)
138__diagnose_as_builtin(__builtin_tmpfile) 138__diagnose_as_builtin(__builtin_tmpfile)
139#endif 139#endif
@@ -143,9 +143,9 @@ _FORTIFY_FN(tmpfile) FILE *tmpfile(void)
143} 143}
144#endif 144#endif
145 145
146__access(read_write, 1, 2) 146__fh_access(read_write, 1, 2)
147__access(read_only, 3) 147__fh_access(read_only, 3)
148__format(printf, 3, 0) 148__fh_format(printf, 3, 0)
149#if __has_builtin(__builtin_vsnprintf) 149#if __has_builtin(__builtin_vsnprintf)
150__diagnose_as_builtin(__builtin_vsnprintf, 1, 2, 3, 4) 150__diagnose_as_builtin(__builtin_vsnprintf, 1, 2, 3, 4)
151#endif 151#endif
@@ -153,9 +153,9 @@ _FORTIFY_FN(vsnprintf) int vsnprintf(char * _FORTIFY_POS0 __s, size_t __n,
153 const char *__f, __builtin_va_list __v) 153 const char *__f, __builtin_va_list __v)
154{ 154{
155#if __has_builtin(__builtin___vsnprintf_chk) && USE_NATIVE_CHK 155#if __has_builtin(__builtin___vsnprintf_chk) && USE_NATIVE_CHK
156 return __builtin___vsnprintf_chk(__s, __n, _FORTIFY_SOURCE, __bos(__s, 0), __f, __v); 156 return __builtin___vsnprintf_chk(__s, __n, _FORTIFY_SOURCE, __fh_bos(__s, 0), __f, __v);
157#else 157#else
158 __fh_size_t __b = __bos(__s, 0); 158 __fh_size_t __b = __fh_bos(__s, 0);
159 159
160 if (__n > __b) 160 if (__n > __b)
161 __builtin_trap(); 161 __builtin_trap();
@@ -163,9 +163,9 @@ _FORTIFY_FN(vsnprintf) int vsnprintf(char * _FORTIFY_POS0 __s, size_t __n,
163#endif 163#endif
164} 164}
165 165
166__format(printf, 2, 0) 166__fh_format(printf, 2, 0)
167__access(read_write, 1) 167__fh_access(read_write, 1)
168__access(read_only, 2) 168__fh_access(read_only, 2)
169#if __has_builtin(__builtin_vsprintf) 169#if __has_builtin(__builtin_vsprintf)
170__diagnose_as_builtin(__builtin_vsprintf, 1, 2, 3) 170__diagnose_as_builtin(__builtin_vsprintf, 1, 2, 3)
171#endif 171#endif
@@ -173,9 +173,9 @@ _FORTIFY_FN(vsprintf) int vsprintf(char * _FORTIFY_POS0 __s, const char *__f,
173 __builtin_va_list __v) 173 __builtin_va_list __v)
174{ 174{
175#if __has_builtin(__builtin___vsprintf_chk) && USE_NATIVE_CHK 175#if __has_builtin(__builtin___vsprintf_chk) && USE_NATIVE_CHK
176 return __builtin___vsprintf_chk(__s, _FORTIFY_SOURCE, __bos(__s, 0), __f, __v); 176 return __builtin___vsprintf_chk(__s, _FORTIFY_SOURCE, __fh_bos(__s, 0), __f, __v);
177#else 177#else
178 __fh_size_t __b = __bos(__s, 0); 178 __fh_size_t __b = __fh_bos(__s, 0);
179 int __r; 179 int __r;
180 180
181 if (__b != (__fh_size_t)-1) { 181 if (__b != (__fh_size_t)-1) {
@@ -193,8 +193,8 @@ _FORTIFY_FN(vsprintf) int vsprintf(char * _FORTIFY_POS0 __s, const char *__f,
193#undef vfprintf 193#undef vfprintf
194#undef vprintf 194#undef vprintf
195 195
196__access(read_only, 2) 196__fh_access(read_only, 2)
197__format(printf, 2, 0) 197__fh_format(printf, 2, 0)
198#if __has_builtin(__builtin_vfprintf) 198#if __has_builtin(__builtin_vfprintf)
199__diagnose_as_builtin(__builtin_vfprintf, 2, 3) 199__diagnose_as_builtin(__builtin_vfprintf, 2, 3)
200#endif 200#endif
@@ -207,8 +207,8 @@ _FORTIFY_FN(vfprintf) int vfprintf(FILE * __s, const char *__f, __builtin_va_lis
207#endif 207#endif
208} 208}
209 209
210__access(read_only, 1) 210__fh_access(read_only, 1)
211__format(printf, 1, 0) 211__fh_format(printf, 1, 0)
212#if __has_builtin(__builtin_vprintf) 212#if __has_builtin(__builtin_vprintf)
213__diagnose_as_builtin(__builtin_vprintf, 1, 2) 213__diagnose_as_builtin(__builtin_vprintf, 1, 2)
214#endif 214#endif
@@ -248,16 +248,16 @@ _FORTIFY_FN(vprintf) int vprintf(const char *__f, __builtin_va_list __v)
248#undef printf 248#undef printf
249#undef fprintf 249#undef fprintf
250 250
251__access(read_write, 1, 2) 251__fh_access(read_write, 1, 2)
252__access(read_only, 3) 252__fh_access(read_only, 3)
253__format(printf, 3, 4) 253__fh_format(printf, 3, 4)
254_FORTIFY_FN(snprintf) int snprintf(char *__s, size_t __n, 254_FORTIFY_FN(snprintf) int snprintf(char *__s, size_t __n,
255 const char *__f, ...) 255 const char *__f, ...)
256{ 256{
257#if __has_builtin(__builtin___snprintf_chk) && USE_NATIVE_CHK 257#if __has_builtin(__builtin___snprintf_chk) && USE_NATIVE_CHK
258 return __builtin___snprintf_chk(__s, __n, _FORTIFY_SOURCE, __bos(__s, 0), __f, __builtin_va_arg_pack()); 258 return __builtin___snprintf_chk(__s, __n, _FORTIFY_SOURCE, __fh_bos(__s, 0), __f, __builtin_va_arg_pack());
259#else 259#else
260 __fh_size_t __b = __bos(__s, 0); 260 __fh_size_t __b = __fh_bos(__s, 0);
261 261
262 if (__n > __b) 262 if (__n > __b)
263 __builtin_trap(); 263 __builtin_trap();
@@ -265,15 +265,15 @@ _FORTIFY_FN(snprintf) int snprintf(char *__s, size_t __n,
265#endif 265#endif
266} 266}
267 267
268__format(printf, 2, 3) 268__fh_format(printf, 2, 3)
269__access(read_write, 1) 269__fh_access(read_write, 1)
270__access(read_only, 2) 270__fh_access(read_only, 2)
271_FORTIFY_FN(sprintf) int sprintf(char *__s, const char *__f, ...) 271_FORTIFY_FN(sprintf) int sprintf(char *__s, const char *__f, ...)
272{ 272{
273#if __has_builtin(__builtin___sprintf_chk) && USE_NATIVE_CHK 273#if __has_builtin(__builtin___sprintf_chk) && USE_NATIVE_CHK
274 return __builtin___sprintf_chk(__s, _FORTIFY_SOURCE, __bos(__s, 0), __f, __builtin_va_arg_pack()); 274 return __builtin___sprintf_chk(__s, _FORTIFY_SOURCE, __fh_bos(__s, 0), __f, __builtin_va_arg_pack());
275#else 275#else
276 __fh_size_t __b = __bos(__s, 0); 276 __fh_size_t __b = __fh_bos(__s, 0);
277 int __r; 277 int __r;
278 278
279 if (__b != (__fh_size_t)-1) { 279 if (__b != (__fh_size_t)-1) {
@@ -287,8 +287,8 @@ _FORTIFY_FN(sprintf) int sprintf(char *__s, const char *__f, ...)
287#endif 287#endif
288} 288}
289 289
290__format(printf, 1, 2) 290__fh_format(printf, 1, 2)
291__access(read_only, 1) 291__fh_access(read_only, 1)
292_FORTIFY_FN(printf) int printf(const char *__f, ...) 292_FORTIFY_FN(printf) int printf(const char *__f, ...)
293{ 293{
294#if __has_builtin(__builtin___printf_chk) && USE_NATIVE_CHK 294#if __has_builtin(__builtin___printf_chk) && USE_NATIVE_CHK
@@ -298,8 +298,8 @@ _FORTIFY_FN(printf) int printf(const char *__f, ...)
298#endif 298#endif
299} 299}
300 300
301__access(read_only, 2) 301__fh_access(read_only, 2)
302__format(printf, 2, 0) 302__fh_format(printf, 2, 0)
303#if __has_builtin(__builtin_fprintf) 303#if __has_builtin(__builtin_fprintf)
304__diagnose_as_builtin(__builtin_fprintf, 2, 3) 304__diagnose_as_builtin(__builtin_fprintf, 2, 3)
305#endif 305#endif
diff --git a/include/stdlib.h b/include/stdlib.h
index 986b1df..1c10906 100644
--- a/include/stdlib.h
+++ b/include/stdlib.h
@@ -37,7 +37,7 @@ __diagnose_as_builtin(__builtin_mbstowcs, 1, 2, 3)
37_FORTIFY_FN(mbstowcs) size_t mbstowcs(wchar_t * _FORTIFY_POS0 __ws, 37_FORTIFY_FN(mbstowcs) size_t mbstowcs(wchar_t * _FORTIFY_POS0 __ws,
38 const char *__s, size_t __wn) 38 const char *__s, size_t __wn)
39{ 39{
40 __fh_size_t __b = __bos(__ws, 0); 40 __fh_size_t __b = __fh_bos(__ws, 0);
41 41
42 if (__ws && __wn > __b / sizeof(wchar_t)) 42 if (__ws && __wn > __b / sizeof(wchar_t))
43 __builtin_trap(); 43 __builtin_trap();
@@ -45,14 +45,14 @@ _FORTIFY_FN(mbstowcs) size_t mbstowcs(wchar_t * _FORTIFY_POS0 __ws,
45} 45}
46 46
47#undef wcstombs 47#undef wcstombs
48__access(write_only, 1, 3) 48__fh_access(write_only, 1, 3)
49#if __has_builtin(__builtin_wcstombs) 49#if __has_builtin(__builtin_wcstombs)
50__diagnose_as_builtin(__builtin_wcstombs, 1, 2, 3) 50__diagnose_as_builtin(__builtin_wcstombs, 1, 2, 3)
51#endif 51#endif
52_FORTIFY_FN(wcstombs) size_t wcstombs(char * _FORTIFY_POS0 __s, 52_FORTIFY_FN(wcstombs) size_t wcstombs(char * _FORTIFY_POS0 __s,
53 const wchar_t *__ws, size_t __n) 53 const wchar_t *__ws, size_t __n)
54{ 54{
55 __fh_size_t __b = __bos(__s, 0); 55 __fh_size_t __b = __fh_bos(__s, 0);
56 56
57 if (__s && __n > __b) 57 if (__s && __n > __b)
58 __builtin_trap(); 58 __builtin_trap();
@@ -68,7 +68,7 @@ __diagnose_as_builtin(__builtin_wctomb, 1, 2)
68#endif 68#endif
69_FORTIFY_FN(wctomb) int wctomb(char * _FORTIFY_POS0 __s, wchar_t __w) 69_FORTIFY_FN(wctomb) int wctomb(char * _FORTIFY_POS0 __s, wchar_t __w)
70{ 70{
71 __fh_size_t __b = __bos(__s, 0); 71 __fh_size_t __b = __fh_bos(__s, 0);
72 72
73 if (__s && 16 > __b && MB_CUR_MAX > __b) 73 if (__s && 16 > __b && MB_CUR_MAX > __b)
74 __builtin_trap(); 74 __builtin_trap();
@@ -81,11 +81,11 @@ _FORTIFY_FN(wctomb) int wctomb(char * _FORTIFY_POS0 __s, wchar_t __w)
81#if __has_builtin(__builtin_qsort) 81#if __has_builtin(__builtin_qsort)
82__diagnose_as_builtin(__builtin_qsort, 1, 2, 3, 4) 82__diagnose_as_builtin(__builtin_qsort, 1, 2, 3, 4)
83#endif 83#endif
84__access(read_write, 1) 84__fh_access(read_write, 1)
85_FORTIFY_FN(qsort) void qsort(void * _FORTIFY_POS0 base, size_t nmemb, size_t size, 85_FORTIFY_FN(qsort) void qsort(void * _FORTIFY_POS0 base, size_t nmemb, size_t size,
86 int (*compar)(const void *, const void *)) 86 int (*compar)(const void *, const void *))
87{ 87{
88 __fh_size_t __b = __bos(base, 0); 88 __fh_size_t __b = __fh_bos(base, 0);
89 89
90 if (__bmo(nmemb, size)) 90 if (__bmo(nmemb, size))
91 __builtin_trap(); 91 __builtin_trap();
@@ -101,8 +101,8 @@ _FORTIFY_FN(qsort) void qsort(void * _FORTIFY_POS0 base, size_t nmemb, size_t si
101#undef realloc 101#undef realloc
102#undef calloc 102#undef calloc
103 103
104__malloc(malloc (free, 1)) 104__fh_malloc(malloc (free, 1))
105__alloc_size(1) 105__fh_alloc_size(1)
106__warn_unused_result 106__warn_unused_result
107#if __has_builtin(__builtin_malloc) 107#if __has_builtin(__builtin_malloc)
108__diagnose_as_builtin(__builtin_malloc, 1) 108__diagnose_as_builtin(__builtin_malloc, 1)
@@ -112,7 +112,7 @@ _FORTIFY_FN(malloc) void *malloc(size_t __s)
112 return __orig_malloc(__s); 112 return __orig_malloc(__s);
113} 113}
114 114
115__alloc_size(2) 115__fh_alloc_size(2)
116__warn_unused_result 116__warn_unused_result
117#if __has_builtin(__builtin_realloc) 117#if __has_builtin(__builtin_realloc)
118__diagnose_as_builtin(__builtin_realloc, 1, 2) 118__diagnose_as_builtin(__builtin_realloc, 1, 2)
@@ -122,7 +122,7 @@ _FORTIFY_FN(realloc) void *realloc(void *__p, size_t __s)
122 return __orig_realloc(__p, __s); 122 return __orig_realloc(__p, __s);
123} 123}
124 124
125__alloc_size(1, 2) 125__fh_alloc_size(1, 2)
126__warn_unused_result 126__warn_unused_result
127#if __has_builtin(__builtin_calloc) 127#if __has_builtin(__builtin_calloc)
128__diagnose_as_builtin(__builtin_calloc, 1, 2) 128__diagnose_as_builtin(__builtin_calloc, 1, 2)
@@ -134,7 +134,7 @@ _FORTIFY_FN(calloc) void *calloc(size_t __n, size_t __s)
134 134
135#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) 135#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
136#undef reallocarray 136#undef reallocarray
137__alloc_size (2, 3) 137__fh_alloc_size (2, 3)
138__warn_unused_result 138__warn_unused_result
139#if __has_builtin(__builtin_reallocarray) 139#if __has_builtin(__builtin_reallocarray)
140__diagnose_as_builtin(__builtin_reallocarray, 1, 2, 3) 140__diagnose_as_builtin(__builtin_reallocarray, 1, 2, 3)
@@ -154,7 +154,7 @@ __diagnose_as_builtin(__builtin_realpath, 1, 2)
154_FORTIFY_FN(realpath) char *realpath(const char *__p, char *__r) 154_FORTIFY_FN(realpath) char *realpath(const char *__p, char *__r)
155{ 155{
156 // PATH_MAX is defined as 4096 156 // PATH_MAX is defined as 4096
157 if (__r && 4096 > __bos(__r, 2)) { 157 if (__r && 4096 > __fh_bos(__r, 2)) {
158 char __buf[4096], *__ret; 158 char __buf[4096], *__ret;
159 __fh_size_t __l; 159 __fh_size_t __l;
160 160
@@ -162,7 +162,7 @@ _FORTIFY_FN(realpath) char *realpath(const char *__p, char *__r)
162 if (!__ret) 162 if (!__ret)
163 return NULL; 163 return NULL;
164 __l = __builtin_strlen(__ret) + 1; 164 __l = __builtin_strlen(__ret) + 1;
165 if (__l > __bos(__r, 0)) 165 if (__l > __fh_bos(__r, 0))
166 __builtin_trap(); 166 __builtin_trap();
167 __builtin_memcpy(__r, __ret, __l); 167 __builtin_memcpy(__r, __ret, __l);
168 return __r; 168 return __r;
diff --git a/include/string.h b/include/string.h
index a6965b2..eb6cc90 100644
--- a/include/string.h
+++ b/include/string.h
@@ -39,20 +39,20 @@ extern "C" {
39#undef strncat 39#undef strncat
40#undef strncpy 40#undef strncpy
41 41
42__access(write_only, 1, 3) 42__fh_access(write_only, 1, 3)
43__access(read_only, 2, 3) 43__fh_access(read_only, 2, 3)
44#if __has_builtin(__builtin_mempcpy) 44#if __has_builtin(__builtin_mempcpy)
45__diagnose_as_builtin(__builtin_memcpy, 1, 2, 3) 45__diagnose_as_builtin(__builtin_memcpy, 1, 2, 3)
46#endif 46#endif
47_FORTIFY_FN(memcpy) void *memcpy(void * _FORTIFY_POS0 __od, 47_FORTIFY_FN(memcpy) void *memcpy(void * _FORTIFY_POS0 __od,
48 const void * _FORTIFY_POS0 __os, size_t __n) 48 const void * _FORTIFY_POS0 __os, size_t __n)
49__error_if((__bos(__od, 0) < __n), "'memcpy' called with `n` bigger than the size of `d`.") 49__error_if((__fh_bos(__od, 0) < __n), "'memcpy' called with `n` bigger than the size of `d`.")
50{ 50{
51#if __has_builtin(__builtin___memcpy_chk) && USE_NATIVE_CHK 51#if __has_builtin(__builtin___memcpy_chk) && USE_NATIVE_CHK
52 return __builtin___memcpy_chk(__od, __os, __n, __bos(__od, 0)); 52 return __builtin___memcpy_chk(__od, __os, __n, __fh_bos(__od, 0));
53#else 53#else
54 __fh_size_t __bd = __bos(__od, 0); 54 __fh_size_t __bd = __fh_bos(__od, 0);
55 __fh_size_t __bs = __bos(__os, 0); 55 __fh_size_t __bs = __fh_bos(__os, 0);
56 char *__d = (char *)__od; 56 char *__d = (char *)__od;
57 const char *__s = (const char *)__os; 57 const char *__s = (const char *)__os;
58 58
@@ -64,8 +64,8 @@ __error_if((__bos(__od, 0) < __n), "'memcpy' called with `n` bigger than the siz
64#endif 64#endif
65} 65}
66 66
67__access(write_only, 1, 3) 67__fh_access(write_only, 1, 3)
68__access(read_only, 2, 3) 68__fh_access(read_only, 2, 3)
69#if __has_builtin(__builtin_memmove) 69#if __has_builtin(__builtin_memmove)
70__diagnose_as_builtin(__builtin_memmove, 1, 2, 3) 70__diagnose_as_builtin(__builtin_memmove, 1, 2, 3)
71#endif 71#endif
@@ -73,10 +73,10 @@ _FORTIFY_FN(memmove) void *memmove(void * _FORTIFY_POS0 __d,
73 const void * _FORTIFY_POS0 __s, size_t __n) 73 const void * _FORTIFY_POS0 __s, size_t __n)
74{ 74{
75#if __has_builtin(__builtin___memmove_chk) && USE_NATIVE_CHK 75#if __has_builtin(__builtin___memmove_chk) && USE_NATIVE_CHK
76 return __builtin___memmove_chk(__d, __s, __n, __bos(__d, 0)); 76 return __builtin___memmove_chk(__d, __s, __n, __fh_bos(__d, 0));
77#else 77#else
78 __fh_size_t __bd = __bos(__d, 0); 78 __fh_size_t __bd = __fh_bos(__d, 0);
79 __fh_size_t __bs = __bos(__s, 0); 79 __fh_size_t __bs = __fh_bos(__s, 0);
80 80
81 if (__n > __bd || __n > __bs) 81 if (__n > __bd || __n > __bs)
82 __builtin_trap(); 82 __builtin_trap();
@@ -84,7 +84,7 @@ _FORTIFY_FN(memmove) void *memmove(void * _FORTIFY_POS0 __d,
84#endif 84#endif
85} 85}
86 86
87__access(write_only, 1, 3) 87__fh_access(write_only, 1, 3)
88#if __has_builtin(__builtin_memset) 88#if __has_builtin(__builtin_memset)
89__diagnose_as_builtin(__builtin_memset, 1, 2, 3) 89__diagnose_as_builtin(__builtin_memset, 1, 2, 3)
90#endif 90#endif
@@ -92,9 +92,9 @@ _FORTIFY_FN(memset) void *memset(void * _FORTIFY_POS0 __d, int __c, size_t __n)
92__warning_if(__c != 0 && __n == 0, "'memset' will set `0` bytes; did you invert the arguments?") 92__warning_if(__c != 0 && __n == 0, "'memset' will set `0` bytes; did you invert the arguments?")
93{ 93{
94#if __has_builtin(__builtin___memset_chk) && USE_NATIVE_CHK 94#if __has_builtin(__builtin___memset_chk) && USE_NATIVE_CHK
95 return __builtin___memset_chk(__d, __c, __n, __bos(__d, 0)); 95 return __builtin___memset_chk(__d, __c, __n, __fh_bos(__d, 0));
96#else 96#else
97 __fh_size_t __b = __bos(__d, 0); 97 __fh_size_t __b = __fh_bos(__d, 0);
98 98
99 if (__n > __b) 99 if (__n > __b)
100 __builtin_trap(); 100 __builtin_trap();
@@ -102,16 +102,16 @@ __warning_if(__c != 0 && __n == 0, "'memset' will set `0` bytes; did you invert
102#endif 102#endif
103} 103}
104 104
105__access(read_only, 1, 3) 105__fh_access(read_only, 1, 3)
106#if __has_builtin(__builtin_memchr) 106#if __has_builtin(__builtin_memchr)
107__diagnose_as_builtin(__builtin_memchr, 1, 2, 3) 107__diagnose_as_builtin(__builtin_memchr, 1, 2, 3)
108#endif 108#endif
109_FORTIFY_FN(memchr) void *memchr(const void * _FORTIFY_POS0 __d, int __c, size_t __n) 109_FORTIFY_FN(memchr) void *memchr(const void * _FORTIFY_POS0 __d, int __c, size_t __n)
110{ 110{
111#if __has_builtin(__builtin___memchr_chk) && USE_NATIVE_CHK 111#if __has_builtin(__builtin___memchr_chk) && USE_NATIVE_CHK
112 return __builtin___memchr_chk(__d, __c, __n, __bos(__d, 0)); 112 return __builtin___memchr_chk(__d, __c, __n, __fh_bos(__d, 0));
113#else 113#else
114 __fh_size_t __b = __bos(__d, 0); 114 __fh_size_t __b = __fh_bos(__d, 0);
115 115
116 if (__n > __b) 116 if (__n > __b)
117 __builtin_trap(); 117 __builtin_trap();
@@ -119,13 +119,13 @@ _FORTIFY_FN(memchr) void *memchr(const void * _FORTIFY_POS0 __d, int __c, size_t
119#endif 119#endif
120} 120}
121 121
122__access(read_only, 1, 2) 122__fh_access(read_only, 1, 2)
123_FORTIFY_FN(strchr) char *strchr(const char * _FORTIFY_POS0 __s, int __c) 123_FORTIFY_FN(strchr) char *strchr(const char * _FORTIFY_POS0 __s, int __c)
124{ 124{
125#if __has_builtin(__builtin___strchr_chk) && USE_NATIVE_CHK 125#if __has_builtin(__builtin___strchr_chk) && USE_NATIVE_CHK
126 return __builtin___strchr_chk(__s, __c, __bos(__s, 0)); 126 return __builtin___strchr_chk(__s, __c, __fh_bos(__s, 0));
127#else 127#else
128 __fh_size_t __b = __bos(__s, 0); 128 __fh_size_t __b = __fh_bos(__s, 0);
129 129
130 char* __r = __builtin_strchr(__s, __c); 130 char* __r = __builtin_strchr(__s, __c);
131 if (__r - __s > __b) 131 if (__r - __s > __b)
@@ -134,13 +134,13 @@ _FORTIFY_FN(strchr) char *strchr(const char * _FORTIFY_POS0 __s, int __c)
134#endif 134#endif
135} 135}
136 136
137__access(read_only, 1, 2) 137__fh_access(read_only, 1, 2)
138_FORTIFY_FN(strrchr) char *strrchr(const char * _FORTIFY_POS0 __s, int __c) 138_FORTIFY_FN(strrchr) char *strrchr(const char * _FORTIFY_POS0 __s, int __c)
139{ 139{
140#if __has_builtin(__builtin___strrchr_chk) && USE_NATIVE_CHK 140#if __has_builtin(__builtin___strrchr_chk) && USE_NATIVE_CHK
141 return __builtin___strrchr_chk(__s, __c, __bos(__s, 0)); 141 return __builtin___strrchr_chk(__s, __c, __fh_bos(__s, 0));
142#else 142#else
143 __fh_size_t __b = __bos(__s, 0); 143 __fh_size_t __b = __fh_bos(__s, 0);
144 144
145 char* __r = __builtin_strrchr(__s, __c); 145 char* __r = __builtin_strrchr(__s, __c);
146 if (__r - __s > __b) 146 if (__r - __s > __b)
@@ -153,22 +153,22 @@ _FORTIFY_FN(strrchr) char *strrchr(const char * _FORTIFY_POS0 __s, int __c)
153 || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \ 153 || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \
154 || defined(_BSD_SOURCE) 154 || defined(_BSD_SOURCE)
155#undef stpcpy 155#undef stpcpy
156__access(write_only, 1) 156__fh_access(write_only, 1)
157__access(read_only, 2) 157__fh_access(read_only, 2)
158#if __has_builtin(__builtin_stpcpy) 158#if __has_builtin(__builtin_stpcpy)
159__diagnose_as_builtin(__builtin_stpcpy, 1, 2) 159__diagnose_as_builtin(__builtin_stpcpy, 1, 2)
160#endif 160#endif
161_FORTIFY_FN(stpcpy) char *stpcpy(char * _FORTIFY_POS0 __d, const char *__s) 161_FORTIFY_FN(stpcpy) char *stpcpy(char * _FORTIFY_POS0 __d, const char *__s)
162{ 162{
163#if __has_builtin(__builtin___stpcpy_chk) && USE_NATIVE_CHK 163#if __has_builtin(__builtin___stpcpy_chk) && USE_NATIVE_CHK
164 return __builtin___stpcpy_chk(__d, __s, __bos(__d, 0)); 164 return __builtin___stpcpy_chk(__d, __s, __fh_bos(__d, 0));
165#else 165#else
166 __fh_size_t __n = strlen(__s) + 1; 166 __fh_size_t __n = strlen(__s) + 1;
167 167
168 if (__fh_overlap(__d, __s, __n)) 168 if (__fh_overlap(__d, __s, __n))
169 __builtin_trap(); 169 __builtin_trap();
170 170
171 __fh_size_t __b = __bos(__d, 0); 171 __fh_size_t __b = __fh_bos(__d, 0);
172 if (__n > __b) 172 if (__n > __b)
173 __builtin_trap(); 173 __builtin_trap();
174 return __orig_stpcpy(__d, __s); 174 return __orig_stpcpy(__d, __s);
@@ -176,8 +176,8 @@ _FORTIFY_FN(stpcpy) char *stpcpy(char * _FORTIFY_POS0 __d, const char *__s)
176} 176}
177 177
178#undef stpncpy 178#undef stpncpy
179__access(write_only, 1) 179__fh_access(write_only, 1)
180__access(read_only, 2, 3) 180__fh_access(read_only, 2, 3)
181#if __has_builtin(__builtin_stpncpy) 181#if __has_builtin(__builtin_stpncpy)
182__diagnose_as_builtin(__builtin_stpncpy, 1, 2, 3) 182__diagnose_as_builtin(__builtin_stpncpy, 1, 2, 3)
183#endif 183#endif
@@ -185,12 +185,12 @@ _FORTIFY_FN(stpncpy) char *stpncpy(char * _FORTIFY_POS0 __d, const char *__s,
185 size_t __n) 185 size_t __n)
186{ 186{
187#if __has_builtin(__builtin___stpncpy_chk) && USE_NATIVE_CHK 187#if __has_builtin(__builtin___stpncpy_chk) && USE_NATIVE_CHK
188 return __builtin___stpncpy_chk(__d, __s, __n, __bos(__d, 0)); 188 return __builtin___stpncpy_chk(__d, __s, __n, __fh_bos(__d, 0));
189#else 189#else
190 if (__fh_overlap(__d, __s, __n)) 190 if (__fh_overlap(__d, __s, __n))
191 __builtin_trap(); 191 __builtin_trap();
192 192
193 __fh_size_t __b = __bos(__d, 0); 193 __fh_size_t __b = __fh_bos(__d, 0);
194 if (__n > __b && strlen(__s) + 1 > __b) 194 if (__n > __b && strlen(__s) + 1 > __b)
195 __builtin_trap(); 195 __builtin_trap();
196 return __orig_stpncpy(__d, __s, __n); 196 return __orig_stpncpy(__d, __s, __n);
@@ -198,17 +198,17 @@ _FORTIFY_FN(stpncpy) char *stpncpy(char * _FORTIFY_POS0 __d, const char *__s,
198} 198}
199#endif 199#endif
200 200
201__access (read_write, 1) 201__fh_access (read_write, 1)
202__access (read_only, 2) 202__fh_access (read_only, 2)
203#if __has_builtin(__builtin_strcat) 203#if __has_builtin(__builtin_strcat)
204__diagnose_as_builtin(__builtin_strcat, 1, 2) 204__diagnose_as_builtin(__builtin_strcat, 1, 2)
205#endif 205#endif
206_FORTIFY_FN(strcat) char *strcat(char * _FORTIFY_POS0 __d, const char *__s) 206_FORTIFY_FN(strcat) char *strcat(char * _FORTIFY_POS0 __d, const char *__s)
207{ 207{
208#if __has_builtin(__builtin___strcat_chk) && USE_NATIVE_CHK 208#if __has_builtin(__builtin___strcat_chk) && USE_NATIVE_CHK
209 return __builtin___strcat_chk(__d, __s, __bos(__d, 0)); 209 return __builtin___strcat_chk(__d, __s, __fh_bos(__d, 0));
210#else 210#else
211 __fh_size_t __b = __bos(__d, 0); 211 __fh_size_t __b = __fh_bos(__d, 0);
212 212
213 if (strlen(__s) + strlen(__d) + 1 > __b) 213 if (strlen(__s) + strlen(__d) + 1 > __b)
214 __builtin_trap(); 214 __builtin_trap();
@@ -216,46 +216,46 @@ _FORTIFY_FN(strcat) char *strcat(char * _FORTIFY_POS0 __d, const char *__s)
216#endif 216#endif
217} 217}
218 218
219__access (write_only, 1) 219__fh_access (write_only, 1)
220__access (read_only, 2) 220__fh_access (read_only, 2)
221#if __has_builtin(__builtin_strcpy) 221#if __has_builtin(__builtin_strcpy)
222__diagnose_as_builtin(__builtin_strcpy, 1, 2) 222__diagnose_as_builtin(__builtin_strcpy, 1, 2)
223#endif 223#endif
224_FORTIFY_FN(strcpy) char *strcpy(char * _FORTIFY_POS0 __d, const char *__s) 224_FORTIFY_FN(strcpy) char *strcpy(char * _FORTIFY_POS0 __d, const char *__s)
225{ 225{
226#if __has_builtin(__builtin___strcpy_chk) && USE_NATIVE_CHK 226#if __has_builtin(__builtin___strcpy_chk) && USE_NATIVE_CHK
227 return __builtin___strcpy_chk(__d, __s, __bos(__d, 0)); 227 return __builtin___strcpy_chk(__d, __s, __fh_bos(__d, 0));
228#else 228#else
229 __fh_size_t __n = strlen(__s) + 1; 229 __fh_size_t __n = strlen(__s) + 1;
230 230
231 if (__fh_overlap(__d, __s, __n)) 231 if (__fh_overlap(__d, __s, __n))
232 __builtin_trap(); 232 __builtin_trap();
233 233
234 __fh_size_t __b = __bos(__d, 0); 234 __fh_size_t __b = __fh_bos(__d, 0);
235 if (__n > __b) 235 if (__n > __b)
236 __builtin_trap(); 236 __builtin_trap();
237 return __orig_strcpy(__d, __s); 237 return __orig_strcpy(__d, __s);
238#endif 238#endif
239} 239}
240 240
241__access (read_only, 1) 241__fh_access (read_only, 1)
242#if __has_builtin(__builtin_strlen) 242#if __has_builtin(__builtin_strlen)
243__diagnose_as_builtin(__builtin_strlen, 1) 243__diagnose_as_builtin(__builtin_strlen, 1)
244#endif 244#endif
245_FORTIFY_FN(strlen) size_t strlen(const char * _FORTIFY_POS0 __s) 245_FORTIFY_FN(strlen) size_t strlen(const char * _FORTIFY_POS0 __s)
246{ 246{
247#if __has_builtin(__builtin___strlen_chk) && USE_NATIVE_CHK 247#if __has_builtin(__builtin___strlen_chk) && USE_NATIVE_CHK
248 return __builtin___strlen_chk(__s, __bos(__s, 0)); 248 return __builtin___strlen_chk(__s, __fh_bos(__s, 0));
249#else 249#else
250 __fh_size_t ret = __orig_strlen(__s); 250 __fh_size_t ret = __orig_strlen(__s);
251 if (ret > __bos(__s, 0) - 1) 251 if (ret > __fh_bos(__s, 0) - 1)
252 __builtin_trap(); 252 __builtin_trap();
253 return ret; 253 return ret;
254#endif 254#endif
255} 255}
256 256
257__access (read_write, 1) 257__fh_access (read_write, 1)
258__access (read_only, 2, 3) 258__fh_access (read_only, 2, 3)
259#if __has_builtin(__builtin_strncat) 259#if __has_builtin(__builtin_strncat)
260__diagnose_as_builtin(__builtin_strncat, 1, 2, 3) 260__diagnose_as_builtin(__builtin_strncat, 1, 2, 3)
261#endif 261#endif
@@ -263,9 +263,9 @@ _FORTIFY_FN(strncat) char *strncat(char * _FORTIFY_POS0 __d, const char *__s,
263 size_t __n) 263 size_t __n)
264{ 264{
265#if __has_builtin(__builtin___strncat_chk) && USE_NATIVE_CHK 265#if __has_builtin(__builtin___strncat_chk) && USE_NATIVE_CHK
266 return __builtin___strncat_chk(__d, __s, __n, __bos(__d, 0)); 266 return __builtin___strncat_chk(__d, __s, __n, __fh_bos(__d, 0));
267#else 267#else
268 __fh_size_t __b = __bos(__d, 0); 268 __fh_size_t __b = __fh_bos(__d, 0);
269 269
270 if (__n > __b) { 270 if (__n > __b) {
271 __fh_size_t __sl = strnlen(__s, __n); 271 __fh_size_t __sl = strnlen(__s, __n);
@@ -277,8 +277,8 @@ _FORTIFY_FN(strncat) char *strncat(char * _FORTIFY_POS0 __d, const char *__s,
277#endif 277#endif
278} 278}
279 279
280__access (write_only, 1) 280__fh_access (write_only, 1)
281__access (read_only, 2, 3) 281__fh_access (read_only, 2, 3)
282#if __has_builtin(__builtin_strncpy) 282#if __has_builtin(__builtin_strncpy)
283__diagnose_as_builtin(__builtin_strncpy, 1, 2, 3) 283__diagnose_as_builtin(__builtin_strncpy, 1, 2, 3)
284#endif 284#endif
@@ -286,12 +286,12 @@ _FORTIFY_FN(strncpy) char *strncpy(char * _FORTIFY_POS0 __d,
286 const char *__s, size_t __n) 286 const char *__s, size_t __n)
287{ 287{
288#if __has_builtin(__builtin___strncpy_chk) && USE_NATIVE_CHK 288#if __has_builtin(__builtin___strncpy_chk) && USE_NATIVE_CHK
289 return __builtin___strncpy_chk(__d, __s, __n, __bos(__d, 0)); 289 return __builtin___strncpy_chk(__d, __s, __n, __fh_bos(__d, 0));
290#else 290#else
291 if (__fh_overlap(__d, __s, __n)) 291 if (__fh_overlap(__d, __s, __n))
292 __builtin_trap(); 292 __builtin_trap();
293 293
294 __fh_size_t __b = __bos(__d, 0); 294 __fh_size_t __b = __fh_bos(__d, 0);
295 if (__n > __b) 295 if (__n > __b)
296 __builtin_trap(); 296 __builtin_trap();
297 return __orig_strncpy(__d, __s, __n); 297 return __orig_strncpy(__d, __s, __n);
@@ -300,8 +300,8 @@ _FORTIFY_FN(strncpy) char *strncpy(char * _FORTIFY_POS0 __d,
300 300
301#ifdef _GNU_SOURCE 301#ifdef _GNU_SOURCE
302#undef mempcpy 302#undef mempcpy
303__access(write_only, 1) 303__fh_access(write_only, 1)
304__access(read_only, 2, 3) 304__fh_access(read_only, 2, 3)
305#if __has_builtin(__builtin_mempcpy) 305#if __has_builtin(__builtin_mempcpy)
306__diagnose_as_builtin(__builtin_mempcpy, 1, 2, 3) 306__diagnose_as_builtin(__builtin_mempcpy, 1, 2, 3)
307#endif 307#endif
@@ -309,10 +309,10 @@ _FORTIFY_FN(mempcpy) void *mempcpy(void * _FORTIFY_POS0 __d,
309 const void * _FORTIFY_POS0 __s, size_t __n) 309 const void * _FORTIFY_POS0 __s, size_t __n)
310{ 310{
311#if __has_builtin(__builtin___mempcpy_chk) && USE_NATIVE_CHK 311#if __has_builtin(__builtin___mempcpy_chk) && USE_NATIVE_CHK
312 return __builtin___mempcpy_chk(__d, __s, __n, __bos(__d, 0)); 312 return __builtin___mempcpy_chk(__d, __s, __n, __fh_bos(__d, 0));
313#else 313#else
314 __fh_size_t __bd = __bos(__d, 0); 314 __fh_size_t __bd = __fh_bos(__d, 0);
315 __fh_size_t __bs = __bos(__s, 0); 315 __fh_size_t __bs = __fh_bos(__s, 0);
316 316
317 if (__n > __bd || __n > __bs) 317 if (__n > __bd || __n > __bs)
318 __builtin_trap(); 318 __builtin_trap();
@@ -324,8 +324,8 @@ _FORTIFY_FN(mempcpy) void *mempcpy(void * _FORTIFY_POS0 __d,
324#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) 324#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
325#undef strlcat 325#undef strlcat
326#undef strlcpy 326#undef strlcpy
327__access (read_write, 1) 327__fh_access (read_write, 1)
328__access (read_only, 2, 3) 328__fh_access (read_only, 2, 3)
329#if __has_builtin(__builtin_strlcat) 329#if __has_builtin(__builtin_strlcat)
330__diagnose_as_builtin(__builtin_strlcat, 1, 2, 3) 330__diagnose_as_builtin(__builtin_strlcat, 1, 2, 3)
331#endif 331#endif
@@ -333,9 +333,9 @@ _FORTIFY_FN(strlcat) size_t strlcat(char * _FORTIFY_POS0 __d,
333 const char *__s, size_t __n) 333 const char *__s, size_t __n)
334{ 334{
335#if __has_builtin(__builtin___strlcat_chk) && USE_NATIVE_CHK 335#if __has_builtin(__builtin___strlcat_chk) && USE_NATIVE_CHK
336 return __builtin___strlcat_chk(__d, __s, __n, __bos(__d, 0)); 336 return __builtin___strlcat_chk(__d, __s, __n, __fh_bos(__d, 0));
337#else 337#else
338 __fh_size_t __b = __bos(__d, 0); 338 __fh_size_t __b = __fh_bos(__d, 0);
339 339
340 if (__n > __b) 340 if (__n > __b)
341 __builtin_trap(); 341 __builtin_trap();
@@ -343,8 +343,8 @@ _FORTIFY_FN(strlcat) size_t strlcat(char * _FORTIFY_POS0 __d,
343#endif 343#endif
344} 344}
345 345
346__access (write_only, 1) 346__fh_access (write_only, 1)
347__access (read_only, 2, 3) 347__fh_access (read_only, 2, 3)
348#if __has_builtin(__builtin_strlcpy) 348#if __has_builtin(__builtin_strlcpy)
349__diagnose_as_builtin(__builtin_strlcpy, 1, 2, 3) 349__diagnose_as_builtin(__builtin_strlcpy, 1, 2, 3)
350#endif 350#endif
@@ -352,9 +352,9 @@ _FORTIFY_FN(strlcpy) size_t strlcpy(char * _FORTIFY_POS0 __d,
352 const char *__s, size_t __n) 352 const char *__s, size_t __n)
353{ 353{
354#if __has_builtin(__builtin___strlcpy_chk) && USE_NATIVE_CHK 354#if __has_builtin(__builtin___strlcpy_chk) && USE_NATIVE_CHK
355 return __builtin___strlcpy_chk(__d, __s, __n, __bos(__d, 0)); 355 return __builtin___strlcpy_chk(__d, __s, __n, __fh_bos(__d, 0));
356#else 356#else
357 __fh_size_t __b = __bos(__d, 0); 357 __fh_size_t __b = __fh_bos(__d, 0);
358 358
359 if (__n > __b) 359 if (__n > __b)
360 __builtin_trap(); 360 __builtin_trap();
diff --git a/include/strings.h b/include/strings.h
index 6886ddc..511acca 100644
--- a/include/strings.h
+++ b/include/strings.h
@@ -31,8 +31,8 @@ extern "C" {
31 || (defined(_XOPEN_SOURCE) && _XOPEN_SOURCE+0 < 700) 31 || (defined(_XOPEN_SOURCE) && _XOPEN_SOURCE+0 < 700)
32#undef bcopy 32#undef bcopy
33#undef bzero 33#undef bzero
34__access(write_only, 2, 3) 34__fh_access(write_only, 2, 3)
35__access(read_only, 1, 3) 35__fh_access(read_only, 1, 3)
36#if __has_builtin(__builtin_bcopy) && !defined(__clang__) 36#if __has_builtin(__builtin_bcopy) && !defined(__clang__)
37// parameter 1 of function '__orig_bcopy' has type 'const void *', but parameter 1 of function '__builtin_bcopy' has type 'void *' 37// parameter 1 of function '__orig_bcopy' has type 'const void *', but parameter 1 of function '__builtin_bcopy' has type 'void *'
38__diagnose_as_builtin(__builtin_bcopy, 1, 2, 3) 38__diagnose_as_builtin(__builtin_bcopy, 1, 2, 3)
@@ -40,21 +40,21 @@ __diagnose_as_builtin(__builtin_bcopy, 1, 2, 3)
40_FORTIFY_FN(bcopy) void bcopy(const void * _FORTIFY_POS0 __s, 40_FORTIFY_FN(bcopy) void bcopy(const void * _FORTIFY_POS0 __s,
41 void * _FORTIFY_POS0 __d, size_t __n) 41 void * _FORTIFY_POS0 __d, size_t __n)
42{ 42{
43 __fh_size_t __bd = __bos(__d, 0); 43 __fh_size_t __bd = __fh_bos(__d, 0);
44 __fh_size_t __bs = __bos(__s, 0); 44 __fh_size_t __bs = __fh_bos(__s, 0);
45 45
46 if (__n > __bd || __n > __bs) 46 if (__n > __bd || __n > __bs)
47 __builtin_trap(); 47 __builtin_trap();
48 return __orig_bcopy(__s, __d, __n); 48 return __orig_bcopy(__s, __d, __n);
49} 49}
50 50
51__access(write_only, 1, 2) 51__fh_access(write_only, 1, 2)
52#if __has_builtin(__builtin_bzero) 52#if __has_builtin(__builtin_bzero)
53__diagnose_as_builtin(__builtin_bzero, 1, 2) 53__diagnose_as_builtin(__builtin_bzero, 1, 2)
54#endif 54#endif
55_FORTIFY_FN(bzero) void bzero(void * _FORTIFY_POS0 __s, size_t __n) 55_FORTIFY_FN(bzero) void bzero(void * _FORTIFY_POS0 __s, size_t __n)
56{ 56{
57 __fh_size_t __b = __bos(__s, 0); 57 __fh_size_t __b = __fh_bos(__s, 0);
58 58
59 if (__n > __b) 59 if (__n > __b)
60 __builtin_trap(); 60 __builtin_trap();
diff --git a/include/sys/select.h b/include/sys/select.h
index 9e17b19..c8fbb31 100644
--- a/include/sys/select.h
+++ b/include/sys/select.h
@@ -34,7 +34,7 @@ extern "C" {
34 34
35_STI void __fortify_FD_CLR(int __f, fd_set * _FORTIFY_POS0 __s) 35_STI void __fortify_FD_CLR(int __f, fd_set * _FORTIFY_POS0 __s)
36{ 36{
37 __fh_size_t __b = __bos(__s, 0); 37 __fh_size_t __b = __fh_bos(__s, 0);
38 38
39 if (__f < 0 || __f >= FD_SETSIZE || __b < sizeof(fd_set)) 39 if (__f < 0 || __f >= FD_SETSIZE || __b < sizeof(fd_set))
40 __builtin_trap(); 40 __builtin_trap();
@@ -43,7 +43,7 @@ _STI void __fortify_FD_CLR(int __f, fd_set * _FORTIFY_POS0 __s)
43 43
44_STI void __fortify_FD_SET(int __f, fd_set * _FORTIFY_POS0 __s) 44_STI void __fortify_FD_SET(int __f, fd_set * _FORTIFY_POS0 __s)
45{ 45{
46 __fh_size_t __b = __bos(__s, 0); 46 __fh_size_t __b = __fh_bos(__s, 0);
47 47
48 if (__f < 0 || __f >= FD_SETSIZE || __b < sizeof(fd_set)) 48 if (__f < 0 || __f >= FD_SETSIZE || __b < sizeof(fd_set))
49 __builtin_trap(); 49 __builtin_trap();
@@ -52,7 +52,7 @@ _STI void __fortify_FD_SET(int __f, fd_set * _FORTIFY_POS0 __s)
52 52
53_STI int __fortify_FD_ISSET(int __f, fd_set * _FORTIFY_POS0 __s) 53_STI int __fortify_FD_ISSET(int __f, fd_set * _FORTIFY_POS0 __s)
54{ 54{
55 __fh_size_t __b = __bos(__s, 0); 55 __fh_size_t __b = __fh_bos(__s, 0);
56 56
57 if (__f < 0 || __f >= FD_SETSIZE || __b < sizeof(fd_set)) 57 if (__f < 0 || __f >= FD_SETSIZE || __b < sizeof(fd_set))
58 __builtin_trap(); 58 __builtin_trap();
diff --git a/include/sys/socket.h b/include/sys/socket.h
index b7a8cf8..18648f9 100644
--- a/include/sys/socket.h
+++ b/include/sys/socket.h
@@ -34,46 +34,46 @@ extern "C" {
34#undef send 34#undef send
35#undef sendto 35#undef sendto
36 36
37__access(write_only, 2, 3) 37__fh_access(write_only, 2, 3)
38_FORTIFY_FN(recv) ssize_t recv(int __f, void * _FORTIFY_POS0 __s, size_t __n, 38_FORTIFY_FN(recv) ssize_t recv(int __f, void * _FORTIFY_POS0 __s, size_t __n,
39 int __fl) 39 int __fl)
40{ 40{
41 __fh_size_t __b = __bos(__s, 0); 41 __fh_size_t __b = __fh_bos(__s, 0);
42 42
43 if (__n > __b) 43 if (__n > __b)
44 __builtin_trap(); 44 __builtin_trap();
45 return __orig_recv(__f, __s, __n, __fl); 45 return __orig_recv(__f, __s, __n, __fl);
46} 46}
47 47
48__access(write_only, 2, 3) 48__fh_access(write_only, 2, 3)
49_FORTIFY_FN(recvfrom) ssize_t recvfrom(int __f, void * _FORTIFY_POS0 __s, 49_FORTIFY_FN(recvfrom) ssize_t recvfrom(int __f, void * _FORTIFY_POS0 __s,
50 size_t __n, int __fl, 50 size_t __n, int __fl,
51 struct sockaddr *__a, socklen_t *__l) 51 struct sockaddr *__a, socklen_t *__l)
52{ 52{
53 __fh_size_t __b = __bos(__s, 0); 53 __fh_size_t __b = __fh_bos(__s, 0);
54 54
55 if (__n > __b) 55 if (__n > __b)
56 __builtin_trap(); 56 __builtin_trap();
57 return __orig_recvfrom(__f, __s, __n, __fl, __a, __l); 57 return __orig_recvfrom(__f, __s, __n, __fl, __a, __l);
58} 58}
59 59
60__access(read_only, 2, 3) 60__fh_access(read_only, 2, 3)
61_FORTIFY_FN(send) ssize_t send(int __f, const void * _FORTIFY_POS0 __s, 61_FORTIFY_FN(send) ssize_t send(int __f, const void * _FORTIFY_POS0 __s,
62 size_t __n, int __fl) 62 size_t __n, int __fl)
63{ 63{
64 __fh_size_t __b = __bos(__s, 0); 64 __fh_size_t __b = __fh_bos(__s, 0);
65 65
66 if (__n > __b) 66 if (__n > __b)
67 __builtin_trap(); 67 __builtin_trap();
68 return __orig_send(__f, __s, __n, __fl); 68 return __orig_send(__f, __s, __n, __fl);
69} 69}
70 70
71__access(read_only, 2, 3) 71__fh_access(read_only, 2, 3)
72_FORTIFY_FN(sendto) ssize_t sendto(int __f, const void * _FORTIFY_POS0 __s, 72_FORTIFY_FN(sendto) ssize_t sendto(int __f, const void * _FORTIFY_POS0 __s,
73 size_t __n, int __fl, 73 size_t __n, int __fl,
74 const struct sockaddr *__a, socklen_t __l) 74 const struct sockaddr *__a, socklen_t __l)
75{ 75{
76 __fh_size_t __b = __bos(__s, 0); 76 __fh_size_t __b = __fh_bos(__s, 0);
77 77
78 if (__n > __b) 78 if (__n > __b)
79 __builtin_trap(); 79 __builtin_trap();
diff --git a/include/unistd.h b/include/unistd.h
index 5074d33..69095d5 100644
--- a/include/unistd.h
+++ b/include/unistd.h
@@ -41,13 +41,13 @@ extern "C" {
41#undef ttyname_r 41#undef ttyname_r
42#undef write 42#undef write
43 43
44__access(write_only, 2, 3) 44__fh_access(write_only, 2, 3)
45#if __has_builtin(__builtin_confstr) 45#if __has_builtin(__builtin_confstr)
46__diagnose_as_builtin(__builtin_confstr, 1, 2, 3) 46__diagnose_as_builtin(__builtin_confstr, 1, 2, 3)
47#endif 47#endif
48_FORTIFY_FN(confstr) size_t confstr(int __n, char * _FORTIFY_POS0 __s, size_t __l) 48_FORTIFY_FN(confstr) size_t confstr(int __n, char * _FORTIFY_POS0 __s, size_t __l)
49{ 49{
50 __fh_size_t __b = __bos(__s, 0); 50 __fh_size_t __b = __fh_bos(__s, 0);
51 __fh_size_t __r = __orig_confstr(__n, __s, __b > __l ? __l : __b); 51 __fh_size_t __r = __orig_confstr(__n, __s, __b > __l ? __l : __b);
52 52
53 if (__l > __b && __r > __b) 53 if (__l > __b && __r > __b)
@@ -55,13 +55,13 @@ _FORTIFY_FN(confstr) size_t confstr(int __n, char * _FORTIFY_POS0 __s, size_t __
55 return __r; 55 return __r;
56} 56}
57 57
58__access(write_only, 1, 2) 58__fh_access(write_only, 1, 2)
59#if __has_builtin(__builtin_getcwd) 59#if __has_builtin(__builtin_getcwd)
60__diagnose_as_builtin(__builtin_getcwd, 1, 2) 60__diagnose_as_builtin(__builtin_getcwd, 1, 2)
61#endif 61#endif
62_FORTIFY_FN(getcwd) char *getcwd(char * _FORTIFY_POS0 __s, size_t __l) 62_FORTIFY_FN(getcwd) char *getcwd(char * _FORTIFY_POS0 __s, size_t __l)
63{ 63{
64 __fh_size_t __b = __bos(__s, 0); 64 __fh_size_t __b = __fh_bos(__s, 0);
65 65
66 if (__l > __b) 66 if (__l > __b)
67 __builtin_trap(); 67 __builtin_trap();
@@ -70,13 +70,13 @@ _FORTIFY_FN(getcwd) char *getcwd(char * _FORTIFY_POS0 __s, size_t __l)
70 70
71#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) 71#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
72#undef getdomainname 72#undef getdomainname
73__access(write_only, 1, 2) 73__fh_access(write_only, 1, 2)
74#if __has_builtin(__builtin_getdomainname) 74#if __has_builtin(__builtin_getdomainname)
75__diagnose_as_builtin(__builtin_getdomainname, 1, 2) 75__diagnose_as_builtin(__builtin_getdomainname, 1, 2)
76#endif 76#endif
77_FORTIFY_FN(getdomainname) int getdomainname(char * _FORTIFY_POS0 __s, size_t __l) 77_FORTIFY_FN(getdomainname) int getdomainname(char * _FORTIFY_POS0 __s, size_t __l)
78{ 78{
79 __fh_size_t __b = __bos(__s, 0); 79 __fh_size_t __b = __fh_bos(__s, 0);
80 80
81 if (__l > __b) 81 if (__l > __b)
82 __builtin_trap(); 82 __builtin_trap();
@@ -89,33 +89,33 @@ __diagnose_as_builtin(__builtin_getgroups, 1, 2)
89#endif 89#endif
90_FORTIFY_FN(getgroups) int getgroups(int __l, gid_t * _FORTIFY_POS0 __s) 90_FORTIFY_FN(getgroups) int getgroups(int __l, gid_t * _FORTIFY_POS0 __s)
91{ 91{
92 __fh_size_t __b = __bos(__s, 0); 92 __fh_size_t __b = __fh_bos(__s, 0);
93 93
94 if (__l > 0 && (unsigned)__l > __b / sizeof(gid_t)) 94 if (__l > 0 && (unsigned)__l > __b / sizeof(gid_t))
95 __builtin_trap(); 95 __builtin_trap();
96 return __orig_getgroups(__l, __s); 96 return __orig_getgroups(__l, __s);
97} 97}
98 98
99__access(write_only, 1, 2) 99__fh_access(write_only, 1, 2)
100#if __has_builtin(__builtin_gethostname) 100#if __has_builtin(__builtin_gethostname)
101__diagnose_as_builtin(__builtin_gethostname, 1, 2) 101__diagnose_as_builtin(__builtin_gethostname, 1, 2)
102#endif 102#endif
103_FORTIFY_FN(gethostname) int gethostname(char * _FORTIFY_POS0 __s, size_t __l) 103_FORTIFY_FN(gethostname) int gethostname(char * _FORTIFY_POS0 __s, size_t __l)
104{ 104{
105 __fh_size_t __b = __bos(__s, 0); 105 __fh_size_t __b = __fh_bos(__s, 0);
106 106
107 if (__l > __b) 107 if (__l > __b)
108 __builtin_trap(); 108 __builtin_trap();
109 return __orig_gethostname(__s, __l); 109 return __orig_gethostname(__s, __l);
110} 110}
111 111
112__access(write_only, 1, 2) 112__fh_access(write_only, 1, 2)
113#if __has_builtin(__builtin_getlogin_r) 113#if __has_builtin(__builtin_getlogin_r)
114__diagnose_as_builtin(__builtin_getlogin_r, 1, 2) 114__diagnose_as_builtin(__builtin_getlogin_r, 1, 2)
115#endif 115#endif
116_FORTIFY_FN(getlogin_r) int getlogin_r(char * _FORTIFY_POS0 __s, size_t __l) 116_FORTIFY_FN(getlogin_r) int getlogin_r(char * _FORTIFY_POS0 __s, size_t __l)
117{ 117{
118 __fh_size_t __b = __bos(__s, 0); 118 __fh_size_t __b = __fh_bos(__s, 0);
119 119
120 if (__l > __b) 120 if (__l > __b)
121 __builtin_trap(); 121 __builtin_trap();
@@ -128,76 +128,76 @@ __diagnose_as_builtin(__builtin_pread, 1, 2, 3, 4)
128_FORTIFY_FN(pread) ssize_t pread(int __f, void * _FORTIFY_POS0 __s, 128_FORTIFY_FN(pread) ssize_t pread(int __f, void * _FORTIFY_POS0 __s,
129 size_t __n, off_t __o) 129 size_t __n, off_t __o)
130{ 130{
131 __fh_size_t __b = __bos(__s, 0); 131 __fh_size_t __b = __fh_bos(__s, 0);
132 132
133 if (__n > __b) 133 if (__n > __b)
134 __builtin_trap(); 134 __builtin_trap();
135 return __orig_pread(__f, __s, __n, __o); 135 return __orig_pread(__f, __s, __n, __o);
136} 136}
137 137
138__access(write_only, 2, 3) 138__fh_access(write_only, 2, 3)
139#if __has_builtin(__builtin_read) 139#if __has_builtin(__builtin_read)
140__diagnose_as_builtin(__builtin_read, 1, 2, 3) 140__diagnose_as_builtin(__builtin_read, 1, 2, 3)
141#endif 141#endif
142_FORTIFY_FN(read) ssize_t read(int __f, void * _FORTIFY_POS0 __s, size_t __n) 142_FORTIFY_FN(read) ssize_t read(int __f, void * _FORTIFY_POS0 __s, size_t __n)
143{ 143{
144 __fh_size_t __b = __bos(__s, 0); 144 __fh_size_t __b = __fh_bos(__s, 0);
145 145
146 if (__n > __b) 146 if (__n > __b)
147 __builtin_trap(); 147 __builtin_trap();
148 return __orig_read(__f, __s, __n); 148 return __orig_read(__f, __s, __n);
149} 149}
150 150
151__access(write_only, 2, 3) 151__fh_access(write_only, 2, 3)
152#if __has_builtin(__builtin_readlink) 152#if __has_builtin(__builtin_readlink)
153__diagnose_as_builtin(__builtin_readlink, 1, 2, 3) 153__diagnose_as_builtin(__builtin_readlink, 1, 2, 3)
154#endif 154#endif
155_FORTIFY_FN(readlink) ssize_t readlink(const char *__p, 155_FORTIFY_FN(readlink) ssize_t readlink(const char *__p,
156 char * _FORTIFY_POS0 __s, size_t __n) 156 char * _FORTIFY_POS0 __s, size_t __n)
157{ 157{
158 __fh_size_t __b = __bos(__s, 0); 158 __fh_size_t __b = __fh_bos(__s, 0);
159 159
160 if (__n > __b) 160 if (__n > __b)
161 __builtin_trap(); 161 __builtin_trap();
162 return __orig_readlink(__p, __s, __n); 162 return __orig_readlink(__p, __s, __n);
163} 163}
164 164
165__access(write_only, 3, 4) 165__fh_access(write_only, 3, 4)
166#if __has_builtin(__builtin_readlinkat) 166#if __has_builtin(__builtin_readlinkat)
167__diagnose_as_builtin(__builtin_readlinkat, 1, 2, 3, 4) 167__diagnose_as_builtin(__builtin_readlinkat, 1, 2, 3, 4)
168#endif 168#endif
169_FORTIFY_FN(readlinkat) ssize_t readlinkat(int __f, const char *__p, 169_FORTIFY_FN(readlinkat) ssize_t readlinkat(int __f, const char *__p,
170 char * _FORTIFY_POS0 __s, size_t __n) 170 char * _FORTIFY_POS0 __s, size_t __n)
171{ 171{
172 __fh_size_t __b = __bos(__s, 0); 172 __fh_size_t __b = __fh_bos(__s, 0);
173 173
174 if (__n > __b) 174 if (__n > __b)
175 __builtin_trap(); 175 __builtin_trap();
176 return __orig_readlinkat(__f, __p, __s, __n); 176 return __orig_readlinkat(__f, __p, __s, __n);
177} 177}
178 178
179__access(write_only, 2, 3) 179__fh_access(write_only, 2, 3)
180#if __has_builtin(__builtin_ttyname_r) 180#if __has_builtin(__builtin_ttyname_r)
181__diagnose_as_builtin(__builtin_ttyname_r, 1, 2, 3) 181__diagnose_as_builtin(__builtin_ttyname_r, 1, 2, 3)
182#endif 182#endif
183_FORTIFY_FN(ttyname_r) int ttyname_r(int __f, char * _FORTIFY_POS0 __s, 183_FORTIFY_FN(ttyname_r) int ttyname_r(int __f, char * _FORTIFY_POS0 __s,
184 size_t __n) 184 size_t __n)
185{ 185{
186 __fh_size_t __b = __bos(__s, 0); 186 __fh_size_t __b = __fh_bos(__s, 0);
187 187
188 if (__n > __b) 188 if (__n > __b)
189 __builtin_trap(); 189 __builtin_trap();
190 return __orig_ttyname_r(__f, __s, __n); 190 return __orig_ttyname_r(__f, __s, __n);
191} 191}
192 192
193__access(read_only, 2, 3) 193__fh_access(read_only, 2, 3)
194#if __has_builtin(__builtin_write) 194#if __has_builtin(__builtin_write)
195__diagnose_as_builtin(__builtin_write, 1, 2, 3) 195__diagnose_as_builtin(__builtin_write, 1, 2, 3)
196#endif 196#endif
197_FORTIFY_FN(write) ssize_t write(int __f, const void * _FORTIFY_POS0 __s, 197_FORTIFY_FN(write) ssize_t write(int __f, const void * _FORTIFY_POS0 __s,
198 size_t __n) 198 size_t __n)
199{ 199{
200 __fh_size_t __b = __bos(__s, 0); 200 __fh_size_t __b = __fh_bos(__s, 0);
201 201
202 if (__n > __b) 202 if (__n > __b)
203 __builtin_trap(); 203 __builtin_trap();
@@ -210,7 +210,7 @@ __diagnose_as_builtin(__builtin_pwrite, 1, 2, 3, 4)
210_FORTIFY_FN(pwrite) ssize_t pwrite(int __f, const void * _FORTIFY_POS0 __s, 210_FORTIFY_FN(pwrite) ssize_t pwrite(int __f, const void * _FORTIFY_POS0 __s,
211 size_t __n, off_t __o) 211 size_t __n, off_t __o)
212{ 212{
213 __fh_size_t __b = __bos(__s, 0); 213 __fh_size_t __b = __fh_bos(__s, 0);
214 214
215 if (__n > __b) 215 if (__n > __b)
216 __builtin_trap(); 216 __builtin_trap();
diff --git a/include/wchar.h b/include/wchar.h
index e7e3db6..792fad6 100644
--- a/include/wchar.h
+++ b/include/wchar.h
@@ -47,7 +47,7 @@ __diagnose_as_builtin(__builtin_fgetws, 1, 2, 3)
47_FORTIFY_FN(fgetws) wchar_t *fgetws(wchar_t * _FORTIFY_POS0 __s, 47_FORTIFY_FN(fgetws) wchar_t *fgetws(wchar_t * _FORTIFY_POS0 __s,
48 int __n, FILE *__f) 48 int __n, FILE *__f)
49{ 49{
50 __fh_size_t __b = __bos(__s, 0); 50 __fh_size_t __b = __fh_bos(__s, 0);
51 51
52 if ((__fh_size_t)__n > __b / sizeof(wchar_t)) 52 if ((__fh_size_t)__n > __b / sizeof(wchar_t))
53 __builtin_trap(); 53 __builtin_trap();
@@ -64,7 +64,7 @@ _FORTIFY_FN(mbsnrtowcs) size_t mbsnrtowcs(wchar_t * _FORTIFY_POS0 __d,
64 const char **__s, size_t __n, 64 const char **__s, size_t __n,
65 size_t __wn, mbstate_t *__st) 65 size_t __wn, mbstate_t *__st)
66{ 66{
67 __fh_size_t __b = __bos(__d, 0); 67 __fh_size_t __b = __fh_bos(__d, 0);
68 __fh_size_t __r; 68 __fh_size_t __r;
69 69
70 if (__wn > __n / sizeof(wchar_t)) { 70 if (__wn > __n / sizeof(wchar_t)) {
@@ -88,7 +88,7 @@ _FORTIFY_FN(mbsrtowcs) size_t mbsrtowcs(wchar_t * _FORTIFY_POS0 __d,
88 const char **__s, size_t __wn, 88 const char **__s, size_t __wn,
89 mbstate_t *__st) 89 mbstate_t *__st)
90{ 90{
91 __fh_size_t __b = __bos(__d, 0); 91 __fh_size_t __b = __fh_bos(__d, 0);
92 __fh_size_t __r; 92 __fh_size_t __r;
93 93
94 __b /= sizeof(wchar_t); 94 __b /= sizeof(wchar_t);
@@ -106,14 +106,14 @@ __diagnose_as_builtin(__builtin_wcrtomb, 1, 2, 3)
106_FORTIFY_FN(wcrtomb) size_t wcrtomb(char * __s, wchar_t __w, mbstate_t *__st) 106_FORTIFY_FN(wcrtomb) size_t wcrtomb(char * __s, wchar_t __w, mbstate_t *__st)
107{ 107{
108 // In glibc, MB_LEN_MAX is typically 16 (6 in glibc versions earlier than 2.2) 108 // In glibc, MB_LEN_MAX is typically 16 (6 in glibc versions earlier than 2.2)
109 if (__s && 16 > __bos(__s, 2)) { 109 if (__s && 16 > __fh_bos(__s, 2)) {
110 char __buf[16]; 110 char __buf[16];
111 __fh_size_t __r; 111 __fh_size_t __r;
112 112
113 __r = __orig_wcrtomb(__buf, __w, __st); 113 __r = __orig_wcrtomb(__buf, __w, __st);
114 if (__r == (__fh_size_t)-1) 114 if (__r == (__fh_size_t)-1)
115 return __r; 115 return __r;
116 if (__r > __bos(__s, 0)) 116 if (__r > __fh_bos(__s, 0))
117 __builtin_trap(); 117 __builtin_trap();
118 __builtin_memcpy(__s, __buf, __r); 118 __builtin_memcpy(__s, __buf, __r);
119 return __r; 119 return __r;
@@ -128,7 +128,7 @@ __diagnose_as_builtin(__builtin_wcscat, 1, 2)
128_FORTIFY_FN(wcscat) wchar_t *wcscat(wchar_t * _FORTIFY_POS0 __d, 128_FORTIFY_FN(wcscat) wchar_t *wcscat(wchar_t * _FORTIFY_POS0 __d,
129 const wchar_t *__s) 129 const wchar_t *__s)
130{ 130{
131 __fh_size_t __b = __bos(__d, 0); 131 __fh_size_t __b = __fh_bos(__d, 0);
132 132
133 if (wcslen(__s) + wcslen(__d) + 1 > __b / sizeof(wchar_t)) 133 if (wcslen(__s) + wcslen(__d) + 1 > __b / sizeof(wchar_t))
134 __builtin_trap(); 134 __builtin_trap();
@@ -141,7 +141,7 @@ __diagnose_as_builtin(__builtin_wcscpy, 1, 2)
141_FORTIFY_FN(wcscpy) wchar_t *wcscpy(wchar_t * _FORTIFY_POS0 __d, 141_FORTIFY_FN(wcscpy) wchar_t *wcscpy(wchar_t * _FORTIFY_POS0 __d,
142 const wchar_t *__s) 142 const wchar_t *__s)
143{ 143{
144 __fh_size_t __b = __bos(__d, 0); 144 __fh_size_t __b = __fh_bos(__d, 0);
145 145
146 if (wcslen(__s) + 1 > __b / sizeof(wchar_t)) 146 if (wcslen(__s) + 1 > __b / sizeof(wchar_t))
147 __builtin_trap(); 147 __builtin_trap();
@@ -154,7 +154,7 @@ __diagnose_as_builtin(__builtin_wcsncat, 1, 2, 3)
154_FORTIFY_FN(wcsncat) wchar_t *wcsncat(wchar_t * _FORTIFY_POS0 __d, 154_FORTIFY_FN(wcsncat) wchar_t *wcsncat(wchar_t * _FORTIFY_POS0 __d,
155 const wchar_t *__s, size_t __n) 155 const wchar_t *__s, size_t __n)
156{ 156{
157 __fh_size_t __b = __bos(__d, 0); 157 __fh_size_t __b = __fh_bos(__d, 0);
158 __fh_size_t __sl, __dl; 158 __fh_size_t __sl, __dl;
159 159
160 if (__n > __b / sizeof(wchar_t)) { 160 if (__n > __b / sizeof(wchar_t)) {
@@ -174,7 +174,7 @@ __diagnose_as_builtin(__builtin_wcsncpy, 1, 2, 3)
174_FORTIFY_FN(wcsncpy) wchar_t *wcsncpy(wchar_t * _FORTIFY_POS0 __d, 174_FORTIFY_FN(wcsncpy) wchar_t *wcsncpy(wchar_t * _FORTIFY_POS0 __d,
175 const wchar_t *__s, size_t __n) 175 const wchar_t *__s, size_t __n)
176{ 176{
177 __fh_size_t __b = __bos(__d, 0); 177 __fh_size_t __b = __fh_bos(__d, 0);
178 178
179 if (__n > __b / sizeof(wchar_t)) 179 if (__n > __b / sizeof(wchar_t))
180 __builtin_trap(); 180 __builtin_trap();
@@ -191,7 +191,7 @@ _FORTIFY_FN(wcsnrtombs) size_t wcsnrtombs(char * _FORTIFY_POS0 __d,
191 const wchar_t **__s, size_t __wn, 191 const wchar_t **__s, size_t __wn,
192 size_t __n, mbstate_t *__st) 192 size_t __n, mbstate_t *__st)
193{ 193{
194 __fh_size_t __b = __bos(__d, 0); 194 __fh_size_t __b = __fh_bos(__d, 0);
195 __fh_size_t __r; 195 __fh_size_t __r;
196 196
197 if (__wn > __n / sizeof(wchar_t)) { 197 if (__wn > __n / sizeof(wchar_t)) {
@@ -215,7 +215,7 @@ _FORTIFY_FN(wcsrtombs) size_t wcsrtombs(char * _FORTIFY_POS0 __d,
215 const wchar_t **__s, size_t __n, 215 const wchar_t **__s, size_t __n,
216 mbstate_t *__st) 216 mbstate_t *__st)
217{ 217{
218 __fh_size_t __b = __bos(__d, 0); 218 __fh_size_t __b = __fh_bos(__d, 0);
219 __fh_size_t __r; 219 __fh_size_t __r;
220 220
221 __r = __orig_wcsrtombs(__d, __s, __n > __b ? __b : __n, __st); 221 __r = __orig_wcsrtombs(__d, __s, __n > __b ? __b : __n, __st);
@@ -230,7 +230,7 @@ __diagnose_as_builtin(__builtin_wmemcpy, 1, 2, 3)
230_FORTIFY_FN(wmemcpy) wchar_t *wmemcpy(wchar_t * _FORTIFY_POS0 __d, 230_FORTIFY_FN(wmemcpy) wchar_t *wmemcpy(wchar_t * _FORTIFY_POS0 __d,
231 const wchar_t *__s, size_t __n) 231 const wchar_t *__s, size_t __n)
232{ 232{
233 __fh_size_t __b = __bos(__d, 0); 233 __fh_size_t __b = __fh_bos(__d, 0);
234 234
235 if (__n > __b / sizeof(wchar_t)) 235 if (__n > __b / sizeof(wchar_t))
236 __builtin_trap(); 236 __builtin_trap();
@@ -243,7 +243,7 @@ __diagnose_as_builtin(__builtin_wmemmove, 1, 2, 3)
243_FORTIFY_FN(wmemmove) wchar_t *wmemmove(wchar_t * _FORTIFY_POS0 __d, 243_FORTIFY_FN(wmemmove) wchar_t *wmemmove(wchar_t * _FORTIFY_POS0 __d,
244 const wchar_t *__s, size_t __n) 244 const wchar_t *__s, size_t __n)
245{ 245{
246 __fh_size_t __b = __bos(__d, 0); 246 __fh_size_t __b = __fh_bos(__d, 0);
247 247
248 if (__n > __b / sizeof(wchar_t)) 248 if (__n > __b / sizeof(wchar_t))
249 __builtin_trap(); 249 __builtin_trap();
@@ -256,7 +256,7 @@ __diagnose_as_builtin(__builtin_wmemset, 1, 2, 3)
256_FORTIFY_FN(wmemset) wchar_t *wmemset(wchar_t * _FORTIFY_POS0 __s, 256_FORTIFY_FN(wmemset) wchar_t *wmemset(wchar_t * _FORTIFY_POS0 __s,
257 wchar_t __c, size_t __n) 257 wchar_t __c, size_t __n)
258{ 258{
259 __fh_size_t __b = __bos(__s, 0); 259 __fh_size_t __b = __fh_bos(__s, 0);
260 260
261 if (__n > __b / sizeof(wchar_t)) 261 if (__n > __b / sizeof(wchar_t))
262 __builtin_trap(); 262 __builtin_trap();