From e0d30b2283948ac942573a84e6b904a90fdd05b2 Mon Sep 17 00:00:00 2001 From: David Herrmann Date: Sun, 30 Sep 2012 15:41:08 +0200 Subject: [PATCH] log/llog: add gcc format checks Add gcc attributes so the printf formats are correctly checked. This causes a lot of warnings which will be fixed in the following commits. Signed-off-by: David Herrmann --- src/log.h | 6 +++++- src/shl_llog.h | 23 ++++++++++++----------- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/src/log.h b/src/log.h index 52b07f6..d972942 100644 --- a/src/log.h +++ b/src/log.h @@ -176,6 +176,7 @@ void log_clean_filter(); * some log-message at application start. This is a handy-helper to do this. */ +__attribute__((format(printf, 7, 0))) void log_submit(const char *file, int line, const char *func, @@ -185,6 +186,7 @@ void log_submit(const char *file, const char *format, va_list args); +__attribute__((format(printf, 7, 8))) void log_format(const char *file, int line, const char *func, @@ -194,6 +196,7 @@ void log_format(const char *file, const char *format, ...); +__attribute__((format(printf, 6, 0))) void log_llog(const char *file, int line, const char *func, @@ -205,7 +208,8 @@ void log_llog(const char *file, int log_set_file(const char *file); void log_print_init(const char *appname); -static inline void log_dummyf(unsigned int sev, const char *format, ...) +static inline __attribute__((format(printf, 2, 3))) +void log_dummyf(unsigned int sev, const char *format, ...) { } diff --git a/src/shl_llog.h b/src/shl_llog.h index 0325957..29443af 100644 --- a/src/shl_llog.h +++ b/src/shl_llog.h @@ -71,15 +71,15 @@ typedef void (*llog_submit_t) (const char *file, const char *format, va_list args); -__attribute__((__unused__)) -static void llog_format(llog_submit_t llog, - const char *file, - int line, - const char *func, - const char *subs, - unsigned int sev, - const char *format, - ...) +static inline __attribute__((format(printf, 7, 8))) +void llog_format(llog_submit_t llog, + const char *file, + int line, + const char *func, + const char *subs, + unsigned int sev, + const char *format, + ...) { va_list list; @@ -101,8 +101,9 @@ static const char *LLOG_SUBSYSTEM __attribute__((__unused__)); #define llog_dprintf(obj, sev, format, ...) \ llog_format((obj), LLOG_DEFAULT, (sev), (format), ##__VA_ARGS__) -static inline void llog_dummyf(llog_submit_t llog, unsigned int sev, - const char *format, ...) +static inline __attribute__((format(printf, 3, 4))) +void llog_dummyf(llog_submit_t llog, unsigned int sev, + const char *format, ...) { }