summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorjvoisin2025-11-14 15:06:23 +0100
committerjvoisin2025-11-14 16:56:09 +0100
commite9b6cb7e2eb7029902ae92ef43fb905e5072785b (patch)
tree81a2faba510f23858c8fba80c2345227be4e8e3b /include
parentbf242b15e1f7873bdb940c2441b5e57747bc2f81 (diff)
Add `format` annotations
Diffstat (limited to 'include')
-rw-r--r--include/fortify-headers.h9
-rw-r--r--include/stdio.h4
2 files changed, 11 insertions, 2 deletions
diff --git a/include/fortify-headers.h b/include/fortify-headers.h
index a9b7498..67c4792 100644
--- a/include/fortify-headers.h
+++ b/include/fortify-headers.h
@@ -59,15 +59,20 @@
59#define __bos(ptr, type) __builtin_object_size (ptr, type) 59#define __bos(ptr, type) __builtin_object_size (ptr, type)
60#endif 60#endif
61 61
62/* This needs to be two different conditions: https://gcc.gnu.org/onlinedocs/cpp/_005f_005fhas_005fattribute.html */
63#if defined __has_attribute 62#if defined __has_attribute
63
64#if __has_attribute (access) 64#if __has_attribute (access)
65#define __access(...) __attribute__ ((access (__VA_ARGS__))) 65#define __access(...) __attribute__ ((access (__VA_ARGS__)))
66#else 66#else
67#define __access(...) 67#define __access(...)
68#endif 68#endif
69
70#if __has_attribute (format)
71#define __format(...) __attribute__ ((format (__VA_ARGS__)))
69#else 72#else
70#define __access(...) 73#define __format(...)
74#endif
75
71#endif 76#endif
72 77
73#endif 78#endif
diff --git a/include/stdio.h b/include/stdio.h
index 67738ed..aebe861 100644
--- a/include/stdio.h
+++ b/include/stdio.h
@@ -76,6 +76,7 @@ _FORTIFY_FN(fwrite) size_t fwrite(const void * _FORTIFY_POS0 __d, size_t __n,
76 return __orig_fwrite(__d, __n, __m, __f); 76 return __orig_fwrite(__d, __n, __m, __f);
77} 77}
78 78
79__format(printf, 3, 0)
79__access(write_only, 1, 2) 80__access(write_only, 1, 2)
80__access(read_only, 3) 81__access(read_only, 3)
81_FORTIFY_FN(vsnprintf) int vsnprintf(char * _FORTIFY_POS0 __s, size_t __n, 82_FORTIFY_FN(vsnprintf) int vsnprintf(char * _FORTIFY_POS0 __s, size_t __n,
@@ -88,6 +89,7 @@ _FORTIFY_FN(vsnprintf) int vsnprintf(char * _FORTIFY_POS0 __s, size_t __n,
88 return __orig_vsnprintf(__s, __n, __f, __v); 89 return __orig_vsnprintf(__s, __n, __f, __v);
89} 90}
90 91
92__format(printf, 2, 0)
91__access(write_only, 1) 93__access(write_only, 1)
92__access(read_only, 2) 94__access(read_only, 2)
93_FORTIFY_FN(vsprintf) int vsprintf(char * _FORTIFY_POS0 __s, const char *__f, 95_FORTIFY_FN(vsprintf) int vsprintf(char * _FORTIFY_POS0 __s, const char *__f,
@@ -121,6 +123,7 @@ _FORTIFY_FN(vsprintf) int vsprintf(char * _FORTIFY_POS0 __s, const char *__f,
121 * 3) not implementing these under clang, which is what we do for now 123 * 3) not implementing these under clang, which is what we do for now
122 */ 124 */
123 125
126__format(printf, 3, 4)
124_FORTIFY_FN(snprintf) int snprintf(char *__s, size_t __n, 127_FORTIFY_FN(snprintf) int snprintf(char *__s, size_t __n,
125 const char *__f, ...) 128 const char *__f, ...)
126{ 129{
@@ -131,6 +134,7 @@ _FORTIFY_FN(snprintf) int snprintf(char *__s, size_t __n,
131 return __orig_snprintf(__s, __n, __f, __builtin_va_arg_pack()); 134 return __orig_snprintf(__s, __n, __f, __builtin_va_arg_pack());
132} 135}
133 136
137__format(printf, 2, 3)
134_FORTIFY_FN(sprintf) int sprintf(char *__s, const char *__f, ...) 138_FORTIFY_FN(sprintf) int sprintf(char *__s, const char *__f, ...)
135{ 139{
136 size_t __b = __bos(__s, 0); 140 size_t __b = __bos(__s, 0);