summaryrefslogtreecommitdiff
path: root/include/stdio.h
diff options
context:
space:
mode:
authorjvoisin2023-09-22 18:27:54 +0200
committerjvoisin2023-09-22 18:30:35 +0200
commit75b95fa25df74fcd0498bf59e3524f20f594755d (patch)
tree729ba69a2358566f126a8b20f9f30d7a5f7f249c /include/stdio.h
parent8c2352b985b1bf69efb965ba15f5e300eb7e8e12 (diff)
Add more __diagnose_as_builtin annotations
Diffstat (limited to 'include/stdio.h')
-rw-r--r--include/stdio.h26
1 files changed, 26 insertions, 0 deletions
diff --git a/include/stdio.h b/include/stdio.h
index 000a72d..582be4f 100644
--- a/include/stdio.h
+++ b/include/stdio.h
@@ -40,12 +40,18 @@ extern "C" {
40#undef vsprintf 40#undef vsprintf
41 41
42__access(read_only, 2) 42__access(read_only, 2)
43#if __has_builtin(__builtin_fdopen)
44__diagnose_as_builtin(__builtin_fdopen, 1, 2)
45#endif
43_FORTIFY_FN(fdopen) FILE *fdopen(int __f, const char* _FORTIFY_POS0 __m) 46_FORTIFY_FN(fdopen) FILE *fdopen(int __f, const char* _FORTIFY_POS0 __m)
44{ 47{
45 return __orig_fdopen(__f, __m); 48 return __orig_fdopen(__f, __m);
46} 49}
47 50
48__access(write_only, 1, 2) 51__access(write_only, 1, 2)
52#if __has_builtin(__builtin_fgets)
53__diagnose_as_builtin(__builtin_fgets, 1, 2, 3)
54#endif
49_FORTIFY_FN(fgets) char *fgets(char * _FORTIFY_POS0 __s, int __n, FILE *__f) 55_FORTIFY_FN(fgets) char *fgets(char * _FORTIFY_POS0 __s, int __n, FILE *__f)
50{ 56{
51 size_t __b = __bos(__s, 0); 57 size_t __b = __bos(__s, 0);
@@ -56,6 +62,9 @@ _FORTIFY_FN(fgets) char *fgets(char * _FORTIFY_POS0 __s, int __n, FILE *__f)
56} 62}
57 63
58__malloc(malloc (fclose, 1)) 64__malloc(malloc (fclose, 1))
65#if __has_builtin(__builtin_fmemopen)
66__diagnose_as_builtin(__builtin_fmemopen, 1, 2, 3)
67#endif
59_FORTIFY_FN(fmemopen) FILE *fmemopen(void* _FORTIFY_POS0 __b, size_t __s, const char* _FORTIFY_POS0 __m) 68_FORTIFY_FN(fmemopen) FILE *fmemopen(void* _FORTIFY_POS0 __b, size_t __s, const char* _FORTIFY_POS0 __m)
60{ 69{
61 return __orig_fmemopen(__b, __s, __m); 70 return __orig_fmemopen(__b, __s, __m);
@@ -64,12 +73,18 @@ _FORTIFY_FN(fmemopen) FILE *fmemopen(void* _FORTIFY_POS0 __b, size_t __s, const
64__access(read_only, 1) 73__access(read_only, 1)
65__access(read_only, 2) 74__access(read_only, 2)
66__malloc(malloc (fclose, 1)) 75__malloc(malloc (fclose, 1))
76#if __has_builtin(__builtin_fopen)
77__diagnose_as_builtin(__builtin_fopen, 1, 2)
78#endif
67_FORTIFY_FN(fopen) FILE *fopen(const char* _FORTIFY_POS0 __p, const char* _FORTIFY_POS0 __m) 79_FORTIFY_FN(fopen) FILE *fopen(const char* _FORTIFY_POS0 __p, const char* _FORTIFY_POS0 __m)
68{ 80{
69 return __orig_fopen(__p, __m); 81 return __orig_fopen(__p, __m);
70} 82}
71 83
72__access(write_only, 1) 84__access(write_only, 1)
85#if __has_builtin(__builtin_fread)
86__diagnose_as_builtin(__builtin_fread, 1, 2, 3, 4)
87#endif
73_FORTIFY_FN(fread) size_t fread(void * _FORTIFY_POS0 __d, size_t __n, 88_FORTIFY_FN(fread) size_t fread(void * _FORTIFY_POS0 __d, size_t __n,
74 size_t __m, FILE *__f) 89 size_t __m, FILE *__f)
75{ 90{
@@ -83,6 +98,9 @@ _FORTIFY_FN(fread) size_t fread(void * _FORTIFY_POS0 __d, size_t __n,
83} 98}
84 99
85__access(read_only, 1) 100__access(read_only, 1)
101#if __has_builtin(__builtin_fwrite)
102__diagnose_as_builtin(__builtin_fwrite, 1, 2, 3, 4)
103#endif
86_FORTIFY_FN(fwrite) size_t fwrite(const void * _FORTIFY_POS0 __d, size_t __n, 104_FORTIFY_FN(fwrite) size_t fwrite(const void * _FORTIFY_POS0 __d, size_t __n,
87 size_t __m, FILE *__f) 105 size_t __m, FILE *__f)
88{ 106{
@@ -98,6 +116,9 @@ _FORTIFY_FN(fwrite) size_t fwrite(const void * _FORTIFY_POS0 __d, size_t __n,
98__access(read_only, 1) 116__access(read_only, 1)
99__access(read_only, 2) 117__access(read_only, 2)
100__malloc(malloc (pclose, 1)) 118__malloc(malloc (pclose, 1))
119#if __has_builtin(__builtin_popen)
120__diagnose_as_builtin(__builtin_popen, 1, 2)
121#endif
101_FORTIFY_FN(popen) FILE *popen(const char* _FORTIFY_POS0 __c, const char* _FORTIFY_POS0 __t) 122_FORTIFY_FN(popen) FILE *popen(const char* _FORTIFY_POS0 __c, const char* _FORTIFY_POS0 __t)
102{ 123{
103 return __orig_popen(__c, __t); 124 return __orig_popen(__c, __t);
@@ -106,6 +127,9 @@ _FORTIFY_FN(popen) FILE *popen(const char* _FORTIFY_POS0 __c, const char* _FORTI
106#ifndef __clang__ /* FIXME */ 127#ifndef __clang__ /* FIXME */
107#undef tmpfile 128#undef tmpfile
108__malloc(malloc (fclose, 1)) 129__malloc(malloc (fclose, 1))
130#if __has_builtin(__builtin_tmpfile)
131__diagnose_as_builtin(__builtin_tmpfile)
132#endif
109_FORTIFY_FN(tmpfile) FILE *tmpfile(void) 133_FORTIFY_FN(tmpfile) FILE *tmpfile(void)
110{ 134{
111 return __orig_tmpfile(); 135 return __orig_tmpfile();
@@ -162,6 +186,8 @@ _FORTIFY_FN(vsprintf) int vsprintf(char * _FORTIFY_POS0 __s, const char *__f,
162 * have the __chk variants, we'd need to implement a body with intermediate 186 * have the __chk variants, we'd need to implement a body with intermediate
163 * variables within the macro, which means more non-portable mess 187 * variables within the macro, which means more non-portable mess
164 * 3) not implementing these under clang, which is what we do for now 188 * 3) not implementing these under clang, which is what we do for now
189 *
190 * TODO: add __diagnose_as_builtin
165 */ 191 */
166 192
167#undef snprintf 193#undef snprintf