From 985ec9d6ec56f15a72ec974ff2fd1f7bab68cd91 Mon Sep 17 00:00:00 2001 From: "Daniel P. Berrange" Date: Fri, 10 Feb 2012 14:30:56 +0000 Subject: [PATCH] Add printf format annotations to all '...' functions To allow the compile to detect incorrect printf formats, any var-args function should have a format annotation * common/macros.h: Helper to define ATTR_PRINTF for code which can't depend on glib * common/canvas_base.c, common/lz.h, common/macros.h: Annotate some var-args methods --- common/Makefile.am | 1 + common/canvas_base.c | 8 ++++---- common/log.h | 5 +++-- common/lz.h | 6 +++--- common/macros.h | 4 ++-- common/quic.h | 6 +++--- 6 files changed, 16 insertions(+), 14 deletions(-) diff --git a/common/Makefile.am b/common/Makefile.am index 7955b30..f1880e8 100644 --- a/common/Makefile.am +++ b/common/Makefile.am @@ -16,6 +16,7 @@ libspice_common_la_SOURCES = \ lz.h \ lz_common.h \ lz_config.h \ + macros.h \ marshaller.c \ marshaller.h \ mem.c \ diff --git a/common/canvas_base.c b/common/canvas_base.c index 257cbc3..7504c0b 100644 --- a/common/canvas_base.c +++ b/common/canvas_base.c @@ -1741,7 +1741,7 @@ static pixman_image_t *canvas_scale_surface(pixman_image_t *src, const SpiceRect return surface; } -ATTR_PRINTF(2, 3) static void quic_usr_error(QuicUsrContext *usr, const char *fmt, ...) +SPICE_ATTR_PRINTF(2, 3) static void quic_usr_error(QuicUsrContext *usr, const char *fmt, ...) { QuicData *usr_data = (QuicData *)usr; va_list ap; @@ -1753,7 +1753,7 @@ ATTR_PRINTF(2, 3) static void quic_usr_error(QuicUsrContext *usr, const char *fm longjmp(usr_data->jmp_env, 1); } -ATTR_PRINTF(2, 3) static void quic_usr_warn(QuicUsrContext *usr, const char *fmt, ...) +SPICE_ATTR_PRINTF(2, 3) static void quic_usr_warn(QuicUsrContext *usr, const char *fmt, ...) { QuicData *usr_data = (QuicData *)usr; va_list ap; @@ -1773,7 +1773,7 @@ static void quic_usr_free(QuicUsrContext *usr, void *ptr) free(ptr); } -ATTR_PRINTF(2, 3) static void lz_usr_warn(LzUsrContext *usr, const char *fmt, ...) +SPICE_ATTR_PRINTF(2, 3) static void lz_usr_warn(LzUsrContext *usr, const char *fmt, ...) { LzData *usr_data = (LzData *)usr; va_list ap; @@ -1783,7 +1783,7 @@ ATTR_PRINTF(2, 3) static void lz_usr_warn(LzUsrContext *usr, const char *fmt, .. va_end(ap); } -ATTR_PRINTF(2, 3) static void lz_usr_error(LzUsrContext *usr, const char *fmt, ...) +SPICE_ATTR_PRINTF(2, 3) static void lz_usr_error(LzUsrContext *usr, const char *fmt, ...) { LzData *usr_data = (LzData *)usr; va_list ap; diff --git a/common/log.h b/common/log.h index 949879e..37c491f 100644 --- a/common/log.h +++ b/common/log.h @@ -20,6 +20,7 @@ #include #include +#include "macros.h" SPICE_BEGIN_DECLS @@ -45,14 +46,14 @@ void spice_logv(const char *log_domain, const char *strloc, const char *function, const char *format, - va_list args); + va_list args) SPICE_ATTR_PRINTF(5, 0); void spice_log(const char *log_domain, SpiceLogLevel log_level, const char *strloc, const char *function, const char *format, - ...); + ...) SPICE_ATTR_PRINTF(5, 6); #ifndef spice_return_if_fail #define spice_return_if_fail(x) SPICE_STMT_START { \ diff --git a/common/lz.h b/common/lz.h index 2393749..21ba1fa 100644 --- a/common/lz.h +++ b/common/lz.h @@ -19,9 +19,9 @@ typedef void *LzContext; typedef struct LzUsrContext LzUsrContext; struct LzUsrContext { - ATTR_PRINTF(2, 3) void (*error)(LzUsrContext *usr, const char *fmt, ...); - ATTR_PRINTF(2, 3) void (*warn)(LzUsrContext *usr, const char *fmt, ...); - ATTR_PRINTF(2, 3) void (*info)(LzUsrContext *usr, const char *fmt, ...); + SPICE_ATTR_PRINTF(2, 3) void (*error)(LzUsrContext *usr, const char *fmt, ...); + SPICE_ATTR_PRINTF(2, 3) void (*warn)(LzUsrContext *usr, const char *fmt, ...); + SPICE_ATTR_PRINTF(2, 3) void (*info)(LzUsrContext *usr, const char *fmt, ...); void *(*malloc)(LzUsrContext *usr, int size); void (*free)(LzUsrContext *usr, void *ptr); int (*more_space)(LzUsrContext *usr, uint8_t **io_ptr); // get the next chunk of the diff --git a/common/macros.h b/common/macros.h index 44a37e4..ba9713b 100644 --- a/common/macros.h +++ b/common/macros.h @@ -20,10 +20,10 @@ #define __MACROS_H #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5) -#define ATTR_PRINTF(a,b) \ +#define SPICE_ATTR_PRINTF(a,b) \ __attribute__((format(printf,a,b))) #else -#define ATTR_PRINTF(a,b) +#define SPICE_ATTR_PRINTF(a,b) #endif /* __GNUC__ */ diff --git a/common/quic.h b/common/quic.h index b533f39..ee5fb17 100644 --- a/common/quic.h +++ b/common/quic.h @@ -41,9 +41,9 @@ typedef void *QuicContext; typedef struct QuicUsrContext QuicUsrContext; struct QuicUsrContext { - ATTR_PRINTF(2, 3) void (*error)(QuicUsrContext *usr, const char *fmt, ...); - ATTR_PRINTF(2, 3) void (*warn)(QuicUsrContext *usr, const char *fmt, ...); - ATTR_PRINTF(2, 3) void (*info)(QuicUsrContext *usr, const char *fmt, ...); + SPICE_ATTR_PRINTF(2, 3) void (*error)(QuicUsrContext *usr, const char *fmt, ...); + SPICE_ATTR_PRINTF(2, 3) void (*warn)(QuicUsrContext *usr, const char *fmt, ...); + SPICE_ATTR_PRINTF(2, 3) void (*info)(QuicUsrContext *usr, const char *fmt, ...); void *(*malloc)(QuicUsrContext *usr, int size); void (*free)(QuicUsrContext *usr, void *ptr); int (*more_space)(QuicUsrContext *usr, uint32_t **io_ptr, int rows_completed);