From 34a9886a177f9e22930cec7eccda88df4a9f4838 Mon Sep 17 00:00:00 2001 From: David Gibson Date: Tue, 28 Feb 2017 10:09:45 +1100 Subject: Add printf format attributes When compiling with gcc, we already include the attribute on check_msg() to give compiler warnings about mismatches between printf() like format strings and the corresponding arguments. This patch adds similar attributes for lexical_error() and die(). Suggested-by: Nicolas Iooss Signed-off-by: David Gibson --- util.h | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'util.h') diff --git a/util.h b/util.h index 35b2bda..bc3d223 100644 --- a/util.h +++ b/util.h @@ -27,7 +27,13 @@ #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) -static inline void __attribute__((noreturn)) die(const char *str, ...) +#ifdef __GNUC__ +static inline void +__attribute__((noreturn)) __attribute__((format (printf, 1, 2))) +die(const char *str, ...) +#else +static inline void die(const char *str, ...) +#endif { va_list ap; @@ -59,7 +65,13 @@ static inline void *xrealloc(void *p, size_t len) } extern char *xstrdup(const char *s); + +#ifdef __GNUC__ +extern int __attribute__((format (printf, 2, 3))) +xasprintf(char **strp, const char *fmt, ...); +#else extern int xasprintf(char **strp, const char *fmt, ...); +#endif extern char *join_path(const char *path, const char *name); /** -- cgit v1.1