Skip to content

Commit

Permalink
Mark the variadic *printf functions with __attribute__((format)).
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
svkampen committed May 16, 2020
1 parent d3b9846 commit ba025a5
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions printf.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ void _putchar(char character);
* \return The number of characters that are written into the array, not counting the terminating null character
*/
#define printf printf_
#ifdef __GNUC__
__attribute__ ((format (__printf__, 1, 2)))
#endif
int printf_(const char* format, ...);


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


Expand All @@ -84,6 +90,9 @@ int sprintf_(char* buffer, const char* format, ...);
*/
#define snprintf snprintf_
#define vsnprintf vsnprintf_
#ifdef __GNUC__
__attribute__ ((format (__printf__, 3, 4)))
#endif
int snprintf_(char* buffer, size_t count, const char* format, ...);
int vsnprintf_(char* buffer, size_t count, const char* format, va_list va);

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


Expand Down

0 comments on commit ba025a5

Please sign in to comment.