From 7c36569cc56a5d82bfe2d501ced76ff3a0a3af7b Mon Sep 17 00:00:00 2001 From: Marcus Fritzsch Date: Mon, 19 Jun 2017 13:51:44 +0200 Subject: util: add printf format check attributes Signed-off-by: Marcus Fritzsch --- src/util.h | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'src/util.h') diff --git a/src/util.h b/src/util.h index 600c638..2fe6e84 100644 --- a/src/util.h +++ b/src/util.h @@ -5,14 +5,21 @@ extern "C" { #endif -void lognotice(char const *fmt, ...); -void logerror(char const *fmt, ...); -void fatal(char const *fmt, ...); +#ifdef __GNUC__ +#define ATTR_FORMAT(stringindex, firsttocheck) __attribute__((format(printf, stringindex, firsttocheck))) +#else +#define ATTR_FORMAT(stringindex, firsttocheck) +#endif + +void lognotice(char const *fmt, ...) ATTR_FORMAT(1,2); +void logerror(char const *fmt, ...) ATTR_FORMAT(1,2); +void fatal(char const *fmt, ...) ATTR_FORMAT(1,2); #ifdef DEBUG_OUTPUT -void logdebug(char const *fmt, ...); +void logdebug(char const *fmt, ...) ATTR_FORMAT(1,2); #else -inline void logdebug(char const *fmt, ...) {} +static inline void logdebug(char const * fmt, ...) ATTR_FORMAT(1,2); +static inline void logdebug(char const * fmt, ...) {} #endif #ifdef __cplusplus -- cgit 1.2.3-korg