diff options
| author | jvoisin | 2025-11-14 15:06:23 +0100 |
|---|---|---|
| committer | jvoisin | 2025-11-14 16:56:09 +0100 |
| commit | e9b6cb7e2eb7029902ae92ef43fb905e5072785b (patch) | |
| tree | 81a2faba510f23858c8fba80c2345227be4e8e3b /include | |
| parent | bf242b15e1f7873bdb940c2441b5e57747bc2f81 (diff) | |
Add `format` annotations
Diffstat (limited to 'include')
| -rw-r--r-- | include/fortify-headers.h | 9 | ||||
| -rw-r--r-- | include/stdio.h | 4 |
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); |
