Skip to content

Commit ba025a5

Browse files
committed
Mark the variadic *printf functions with __attribute__((format)).
Using __attribute__((format)) means that compilers supporting the attribute (GCC, clang, icc, perhaps others) will automatically issue warnings when printf arguments are incorrectly typed (i.e. inconsistent with the type specified in the format string).
1 parent d3b9846 commit ba025a5

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

printf.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ void _putchar(char character);
5858
* \return The number of characters that are written into the array, not counting the terminating null character
5959
*/
6060
#define printf printf_
61+
#ifdef __GNUC__
62+
__attribute__ ((format (__printf__, 1, 2)))
63+
#endif
6164
int printf_(const char* format, ...);
6265

6366

@@ -69,6 +72,9 @@ int printf_(const char* format, ...);
6972
* \return The number of characters that are WRITTEN into the buffer, not counting the terminating null character
7073
*/
7174
#define sprintf sprintf_
75+
#ifdef __GNUC__
76+
__attribute__ ((format (__printf__, 2, 3)))
77+
#endif
7278
int sprintf_(char* buffer, const char* format, ...);
7379

7480

@@ -84,6 +90,9 @@ int sprintf_(char* buffer, const char* format, ...);
8490
*/
8591
#define snprintf snprintf_
8692
#define vsnprintf vsnprintf_
93+
#ifdef __GNUC__
94+
__attribute__ ((format (__printf__, 3, 4)))
95+
#endif
8796
int snprintf_(char* buffer, size_t count, const char* format, ...);
8897
int vsnprintf_(char* buffer, size_t count, const char* format, va_list va);
8998

@@ -106,6 +115,9 @@ int vprintf_(const char* format, va_list va);
106115
* \param format A string that specifies the format of the output
107116
* \return The number of characters that are sent to the output function, not counting the terminating null character
108117
*/
118+
#ifdef __GNUC__
119+
__attribute__ ((format (__printf__, 3, 4)))
120+
#endif
109121
int fctprintf(void (*out)(char character, void* arg), void* arg, const char* format, ...);
110122

111123

0 commit comments

Comments
 (0)