From: "Daniel P. Berrange" <berra...@redhat.com> 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/canvas_base.c | 8 ++++---- common/lz.h | 7 ++++--- common/macros.h | 30 ++++++++++++++++++++++++++++++ common/quic.h | 7 ++++--- 4 files changed, 42 insertions(+), 10 deletions(-) create mode 100644 common/macros.h diff --git a/common/canvas_base.c b/common/canvas_base.c index 54de7c6..46a0cdd 100644 --- a/common/canvas_base.c +++ b/common/canvas_base.c @@ -1764,7 +1764,7 @@ static pixman_image_t *canvas_scale_surface(pixman_image_t *src, const SpiceRect return surface; } -static void quic_usr_error(QuicUsrContext *usr, const char *fmt, ...) +ATTR_PRINTF(2, 3) static void quic_usr_error(QuicUsrContext *usr, const char *fmt, ...) { QuicData *usr_data = (QuicData *)usr; va_list ap; @@ -1776,7 +1776,7 @@ static void quic_usr_error(QuicUsrContext *usr, const char *fmt, ...) longjmp(usr_data->jmp_env, 1); } -static void quic_usr_warn(QuicUsrContext *usr, const char *fmt, ...) +ATTR_PRINTF(2, 3) static void quic_usr_warn(QuicUsrContext *usr, const char *fmt, ...) { QuicData *usr_data = (QuicData *)usr; va_list ap; @@ -1796,7 +1796,7 @@ static void quic_usr_free(QuicUsrContext *usr, void *ptr) free(ptr); } -static void lz_usr_warn(LzUsrContext *usr, const char *fmt, ...) +ATTR_PRINTF(2, 3) static void lz_usr_warn(LzUsrContext *usr, const char *fmt, ...) { LzData *usr_data = (LzData *)usr; va_list ap; @@ -1806,7 +1806,7 @@ static void lz_usr_warn(LzUsrContext *usr, const char *fmt, ...) va_end(ap); } -static void lz_usr_error(LzUsrContext *usr, const char *fmt, ...) +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/lz.h b/common/lz.h index 993609f..a51ccc0 100644 --- a/common/lz.h +++ b/common/lz.h @@ -9,14 +9,15 @@ #include "lz_common.h" #include "lz_config.h" #include "draw.h" +#include "macros.h" typedef void *LzContext; typedef struct LzUsrContext LzUsrContext; struct LzUsrContext { - void (*error)(LzUsrContext *usr, const char *fmt, ...); - void (*warn)(LzUsrContext *usr, const char *fmt, ...); - void (*info)(LzUsrContext *usr, const char *fmt, ...); + 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, ...); 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 new file mode 100644 index 0000000..44a37e4 --- /dev/null +++ b/common/macros.h @@ -0,0 +1,30 @@ +/* -*- Mode: C; c-basic-offset: 4; indent-tabs-mode: nil -*- */ +/* + Copyright (C) 2009 Red Hat, Inc. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef __MACROS_H +#define __MACROS_H + +#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5) +#define ATTR_PRINTF(a,b) \ + __attribute__((format(printf,a,b))) +#else +#define ATTR_PRINTF(a,b) +#endif /* __GNUC__ */ + + +#endif /* __MACROS_H */ diff --git a/common/quic.h b/common/quic.h index f4ef854..74068f3 100644 --- a/common/quic.h +++ b/common/quic.h @@ -20,6 +20,7 @@ #define __QUIC_H #include "quic_config.h" +#include "macros.h" typedef enum { QUIC_IMAGE_TYPE_INVALID, @@ -37,9 +38,9 @@ typedef void *QuicContext; typedef struct QuicUsrContext QuicUsrContext; struct QuicUsrContext { - void (*error)(QuicUsrContext *usr, const char *fmt, ...); - void (*warn)(QuicUsrContext *usr, const char *fmt, ...); - void (*info)(QuicUsrContext *usr, const char *fmt, ...); + 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, ...); void *(*malloc)(QuicUsrContext *usr, int size); void (*free)(QuicUsrContext *usr, void *ptr); int (*more_space)(QuicUsrContext *usr, uint32_t **io_ptr, int rows_completed); -- 1.7.7.6 _______________________________________________ Spice-devel mailing list Spice-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/spice-devel