diff options
author | Stef Walter <stefw@gnome.org> | 2012-05-13 14:03:17 +0200 |
---|---|---|
committer | Stef Walter <stefw@gnome.org> | 2012-05-13 14:03:17 +0200 |
commit | 7bd4114182fcc86cd2515708fdf4d76622e0237d (patch) | |
tree | 5efb237c364a4a2259a747ae0edfcad6b5e45e40 /common | |
parent | 14b0be4353e5c4464cb9f61e419a2f8caf8757d0 (diff) |
Use gcc extensions to check varargs during compile
* Add macros GNUC_PRINTF and GNUC_NULL_TERMINATED to check
correct printf and NULL terminated style varargs
Diffstat (limited to 'common')
-rw-r--r-- | common/compat.h | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/common/compat.h b/common/compat.h index b2774f1..6326430 100644 --- a/common/compat.h +++ b/common/compat.h @@ -37,6 +37,18 @@ #include "config.h" +#if !defined(__cplusplus) && (__GNUC__ > 2) +#define GNUC_PRINTF(x, y) __attribute__((__format__(__printf__, x, y))) +#else +#define GNUC_PRINTF(x, y) +#endif + +#if __GNUC__ >= 4 +#define GNUC_NULL_TERMINATED __attribute__((__sentinel__)) +#else +#define GNUC_NULL_TERMINATED +#endif + #ifndef HAVE_GETPROGNAME const char * getprogname (void); #endif @@ -49,17 +61,17 @@ const char * getprogname (void); #include <stdarg.h> void err_set_file (void *fp); void err_set_exit (void (*ef)(int)); -void err (int eval, const char *fmt, ...); +void err (int eval, const char *fmt, ...) GNUC_PRINTF (2, 3); void verr (int eval, const char *fmt, va_list ap); -void errc (int eval, int code, const char *fmt, ...); +void errc (int eval, int code, const char *fmt, ...) GNUC_PRINTF (3, 4); void verrc (int eval, int code, const char *fmt, va_list ap); -void errx (int eval, const char *fmt, ...); +void errx (int eval, const char *fmt, ...) GNUC_PRINTF (2, 3); void verrx (int eval, const char *fmt, va_list ap); -void warn (const char *fmt, ...); +void warn (const char *fmt, ...) GNUC_PRINTF (1, 2); void vwarn (const char *fmt, va_list ap); -void warnc (int code, const char *fmt, ...); +void warnc (int code, const char *fmt, ...) GNUC_PRINTF (2, 3); void vwarnc (int code, const char *fmt, va_list ap); -void warnx (const char *fmt, ...); +void warnx (const char *fmt, ...) GNUC_PRINTF (1, 2); void vwarnx (const char *fmt, va_list ap); #endif /* !HAVE_ERR_H */ |