Add GCC format checking attributes to log functions

GCC can check format and parameter correctness in printf()-like functions
for us so let's add necessary attributes to our log functions to emit a
warning where their way of being called is likely in need to be inspected
for correctness.

Signed-off-by: Maciej S. Szmigiero <mail@maciej.szmigiero.name>
This commit is contained in:
Maciej S. Szmigiero 2016-08-25 00:12:55 +02:00 committed by Frank Morgner
parent 1c40426421
commit 2e75198181
1 changed files with 14 additions and 1 deletions

View File

@ -52,11 +52,24 @@ enum {
#define sc_log _sc_log
#endif
void sc_do_log(struct sc_context *ctx, int level, const char *file, int line, const char *func,
#if defined(__GNUC__)
/* GCC can check format and param correctness for us */
void sc_do_log(struct sc_context *ctx, int level, const char *file, int line,
const char *func, const char *format, ...)
__attribute__ ((format (printf, 6, 7)));
void sc_do_log_noframe(sc_context_t *ctx, int level, const char *format,
va_list args) __attribute__ ((format (printf, 3, 0)));
void _sc_debug(struct sc_context *ctx, int level, const char *format, ...)
__attribute__ ((format (printf, 3, 4)));
void _sc_log(struct sc_context *ctx, const char *format, ...)
__attribute__ ((format (printf, 2, 3)));
#else
void sc_do_log(struct sc_context *ctx, int level, const char *file, int line, const char *func,
const char *format, ...);
void sc_do_log_noframe(sc_context_t *ctx, int level, const char *format, va_list args);
void _sc_debug(struct sc_context *ctx, int level, const char *format, ...);
void _sc_log(struct sc_context *ctx, const char *format, ...);
#endif
/**
* @brief Log binary data to a sc context
*