Message ID | 20210305124003.13582-2-julien@xen.org (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | xenstore: Check format printf | expand |
On 05.03.21 13:40, Julien Grall wrote: > From: Julien Grall <jgrall@amazon.com> > > At the moment PRINTF_ATTRIBUTE() is defined in two places: > - tdb.h: Defined as a NOP > - talloc.h: Defined as a NOP for GCC older than 3.0 otherwise will > add the attribute to check the printf format > > Xen requires to build with minimum GCC 4.1 and we want to check the > printf format for all the printf-like functions. > > Only implement PRINTF_ATTRIBUTE() once in utils.h and drop the > conditional check for GCC < 3.0. > > Signed-off-by: Julien Grall <jgrall@amazon.com> Reviewed-by: Juergen Gross <jgross@suse.com> Juergen
Julien Grall writes ("[PATCH for-4.15 1/2] tools/xenstore: Consolidate PRINTF_ATTRIBUTE() in utils.h"): > From: Julien Grall <jgrall@amazon.com> > > At the moment PRINTF_ATTRIBUTE() is defined in two places: > - tdb.h: Defined as a NOP > - talloc.h: Defined as a NOP for GCC older than 3.0 otherwise will > add the attribute to check the printf format > > Xen requires to build with minimum GCC 4.1 and we want to check the > printf format for all the printf-like functions. > > Only implement PRINTF_ATTRIBUTE() once in utils.h and drop the > conditional check for GCC < 3.0. Release-Acked-by: Ian Jackson <iwj@xenproject.org>
diff --git a/tools/xenstore/talloc.h b/tools/xenstore/talloc.h index 71a36e7be06b..a0f4bff25788 100644 --- a/tools/xenstore/talloc.h +++ b/tools/xenstore/talloc.h @@ -26,6 +26,8 @@ #include <sys/types.h> +#include "utils.h" + /* this is only needed for compatibility with the old talloc */ typedef void TALLOC_CTX; @@ -84,19 +86,6 @@ typedef void TALLOC_CTX; #define talloc_destroy(ctx) talloc_free(ctx) #endif -#ifndef PRINTF_ATTRIBUTE -#if (__GNUC__ >= 3) -/** Use gcc attribute to check printf fns. a1 is the 1-based index of - * the parameter containing the format, and a2 the index of the first - * argument. Note that some gcc 2.x versions don't handle this - * properly **/ -#define PRINTF_ATTRIBUTE(a1, a2) __attribute__ ((format (__printf__, a1, a2))) -#else -#define PRINTF_ATTRIBUTE(a1, a2) -#endif -#endif - - /* The following definitions come from talloc.c */ void *_talloc(const void *context, size_t size); void talloc_set_destructor(const void *ptr, int (*destructor)(void *)); diff --git a/tools/xenstore/tdb.h b/tools/xenstore/tdb.h index 557cf727b869..ce3c7339f884 100644 --- a/tools/xenstore/tdb.h +++ b/tools/xenstore/tdb.h @@ -1,6 +1,8 @@ #ifndef __TDB_H__ #define __TDB_H__ +#include "utils.h" + /* Unix SMB/CIFS implementation. @@ -84,10 +86,6 @@ struct tdb_traverse_lock { uint32_t hash; }; -#ifndef PRINTF_ATTRIBUTE -#define PRINTF_ATTRIBUTE(a,b) -#endif - /* this is the context structure that is returned from a db open */ typedef struct tdb_context { char *name; /* the name of the database */ diff --git a/tools/xenstore/utils.h b/tools/xenstore/utils.h index df1cb9a3bac6..3dfb96b556dd 100644 --- a/tools/xenstore/utils.h +++ b/tools/xenstore/utils.h @@ -27,6 +27,8 @@ static inline bool strends(const char *a, const char *b) */ const char *dump_state_align(FILE *fp); +#define PRINTF_ATTRIBUTE(a1, a2) __attribute__((format (printf, a1, a2))) + void barf(const char *fmt, ...) __attribute__((noreturn)); void barf_perror(const char *fmt, ...) __attribute__((noreturn));