summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjvoisin2023-07-09 18:50:30 +0200
committerjvoisin2023-07-09 18:50:30 +0200
commitb333df29dcfabcd4ad0cf630fdb648eaa38ec1c7 (patch)
tree3b7168b33afb3cd68ee50bcdc86e5e5e21136d28
parent190e386fe8666a1250e8aedce73bf8e32ab8c0fd (diff)
Add some `format` annotations
-rw-r--r--include/fortify-headers.h6
-rw-r--r--include/stdio.h2
-rw-r--r--tests/test_vsprintf.c2
3 files changed, 9 insertions, 1 deletions
diff --git a/include/fortify-headers.h b/include/fortify-headers.h
index 08b8dd3..24af881 100644
--- a/include/fortify-headers.h
+++ b/include/fortify-headers.h
@@ -60,6 +60,12 @@
60#define __access(...) 60#define __access(...)
61#endif 61#endif
62 62
63#if defined __has_attribute && __has_attribute (format)
64#define __format(...) __attribute__ ((format (__VA_ARGS__)))
65#else
66#define __format(...)
67#endif
68
63 69
64/* TODO(jvoisin) Figure a nice way to make use of __builtin_mul_overflow while ignoring the result. */ 70/* TODO(jvoisin) Figure a nice way to make use of __builtin_mul_overflow while ignoring the result. */
65/* TODO(jvoisin) Make use of C23's stdckdint header: https://gustedt.gitlabpages.inria.fr/c23-library/#stdckdint */ 71/* TODO(jvoisin) Make use of C23's stdckdint header: https://gustedt.gitlabpages.inria.fr/c23-library/#stdckdint */
diff --git a/include/stdio.h b/include/stdio.h
index d5206f5..5d589f0 100644
--- a/include/stdio.h
+++ b/include/stdio.h
@@ -116,6 +116,7 @@ _FORTIFY_FN(vsprintf) int vsprintf(char * _FORTIFY_POS0 __s, const char *__f,
116 */ 116 */
117 117
118__access(read_write, 1, 2) 118__access(read_write, 1, 2)
119__format(printf, 3, 4)
119_FORTIFY_FN(snprintf) int snprintf(char *__s, size_t __n, 120_FORTIFY_FN(snprintf) int snprintf(char *__s, size_t __n,
120 const char *__f, ...) 121 const char *__f, ...)
121{ 122{
@@ -126,6 +127,7 @@ _FORTIFY_FN(snprintf) int snprintf(char *__s, size_t __n,
126 return __orig_snprintf(__s, __n, __f, __builtin_va_arg_pack()); 127 return __orig_snprintf(__s, __n, __f, __builtin_va_arg_pack());
127} 128}
128 129
130__format(printf, 2, 3)
129_FORTIFY_FN(sprintf) int sprintf(char *__s, const char *__f, ...) 131_FORTIFY_FN(sprintf) int sprintf(char *__s, const char *__f, ...)
130{ 132{
131 size_t __b = __bos(__s, 0); 133 size_t __b = __bos(__s, 0);
diff --git a/tests/test_vsprintf.c b/tests/test_vsprintf.c
index 740816f..4e27201 100644
--- a/tests/test_vsprintf.c
+++ b/tests/test_vsprintf.c
@@ -12,7 +12,7 @@ int msg_valid(const char * format, ... ) {
12 va_end (args); 12 va_end (args);
13} 13}
14 14
15int msg(int n, const char * format, ... ) { 15int msg(const char * format, ... ) {
16 va_list args; 16 va_list args;
17 va_start (args, format); 17 va_start (args, format);
18 CHK_FAIL_START 18 CHK_FAIL_START