From e7680876c48d0f5470b72f3f51fa13f72122b19e Mon Sep 17 00:00:00 2001 From: Josh Triplett Date: Fri, 9 Mar 2007 16:32:16 -0800 Subject: [PATCH] Use GCC format and sentinel attributes on appropriate functions Expose the FORMAT_ATTR portability macro in lib.h, and use it on the various printf-like functions in sparse. Add a new SENTINEL_ATTR portability macro for the GCC sentinel attribute, and use it on match_idents in parse.c. match_oplist in expression.c should use SENTINEL_ATTR, but GCC does not accept an integer 0 as a sentinel, only a pointer 0 like NULL. Signed-off-by: Josh Triplett --- compile-i386.c | 2 +- example.c | 8 ++++---- lib.h | 5 +++-- parse.c | 2 +- show-parse.c | 4 ++-- 5 files changed, 11 insertions(+), 10 deletions(-) diff --git a/compile-i386.c b/compile-i386.c index d61652e6..74f56a1f 100644 --- a/compile-i386.c +++ b/compile-i386.c @@ -173,7 +173,7 @@ static struct function *current_func = NULL; static struct textbuf *unit_post_text = NULL; static const char *current_section; -static void emit_comment(const char * fmt, ...); +static void emit_comment(const char * fmt, ...) FORMAT_ATTR(1); static void emit_move(struct storage *src, struct storage *dest, struct symbol *ctype, const char *comment); static int type_is_signed(struct symbol *sym); diff --git a/example.c b/example.c index cfb44089..9d68d127 100644 --- a/example.c +++ b/example.c @@ -236,7 +236,7 @@ static struct storage_hash *find_or_create_hash(pseudo_t pseudo, struct storage_ } /* Eventually we should just build it up in memory */ -static void output_line(struct bb_state *state, const char *fmt, ...) +static void FORMAT_ATTR(2) output_line(struct bb_state *state, const char *fmt, ...) { va_list args; @@ -245,7 +245,7 @@ static void output_line(struct bb_state *state, const char *fmt, ...) va_end(args); } -static void output_label(struct bb_state *state, const char *fmt, ...) +static void FORMAT_ATTR(2) output_label(struct bb_state *state, const char *fmt, ...) { static char buffer[512]; va_list args; @@ -257,7 +257,7 @@ static void output_label(struct bb_state *state, const char *fmt, ...) output_line(state, "%s:\n", buffer); } -static void output_insn(struct bb_state *state, const char *fmt, ...) +static void FORMAT_ATTR(2) output_insn(struct bb_state *state, const char *fmt, ...) { static char buffer[512]; va_list args; @@ -272,7 +272,7 @@ static void output_insn(struct bb_state *state, const char *fmt, ...) #define output_insn(state, fmt, arg...) \ output_insn(state, fmt "\t\t# %s" , ## arg , __FUNCTION__) -static void output_comment(struct bb_state *state, const char *fmt, ...) +static void FORMAT_ATTR(2) output_comment(struct bb_state *state, const char *fmt, ...) { static char buffer[512]; va_list args; diff --git a/lib.h b/lib.h index 49ef9bb2..472624d0 100644 --- a/lib.h +++ b/lib.h @@ -68,8 +68,10 @@ struct token *skip_to(struct token *, int); struct token *expect(struct token *, int, const char *); #ifdef __GNUC__ #define FORMAT_ATTR(pos) __attribute__ ((__format__ (__printf__, pos, pos+1))) +#define SENTINEL_ATTR __attribute__ ((__sentinel__)) #else #define FORMAT_ATTR(pos) +#define SENTINEL_ATTR #endif extern void die(const char *, ...) FORMAT_ATTR(1); extern void info(struct position, const char *, ...) FORMAT_ATTR(2); @@ -77,10 +79,9 @@ extern void warning(struct position, const char *, ...) FORMAT_ATTR(2); extern void sparse_error(struct position, const char *, ...) FORMAT_ATTR(2); extern void error_die(struct position, const char *, ...) FORMAT_ATTR(2); extern void expression_error(struct expression *, const char *, ...) FORMAT_ATTR(2); -#undef FORMAT_ATTR extern char **handle_switch(char *arg, char **next); -extern void add_pre_buffer(const char *fmt, ...); +extern void add_pre_buffer(const char *fmt, ...) FORMAT_ATTR(1); extern int preprocess_only; extern int Wptr_subtraction_blows; diff --git a/parse.c b/parse.c index 3a9ebc91..4c7f5f1f 100644 --- a/parse.c +++ b/parse.c @@ -343,7 +343,7 @@ static void fn_local_symbol(struct symbol *sym) add_symbol(function_symbol_list, sym); } -static int match_idents(struct token *token, ...) +static int SENTINEL_ATTR match_idents(struct token *token, ...) { va_list args; diff --git a/show-parse.c b/show-parse.c index 3bfe5a9d..0bef01cb 100644 --- a/show-parse.c +++ b/show-parse.c @@ -144,7 +144,7 @@ struct type_name { char *end; }; -static void prepend(struct type_name *name, const char *fmt, ...) +static void FORMAT_ATTR(2) prepend(struct type_name *name, const char *fmt, ...) { static char buffer[512]; int n; @@ -158,7 +158,7 @@ static void prepend(struct type_name *name, const char *fmt, ...) memcpy(name->start, buffer, n); } -static void append(struct type_name *name, const char *fmt, ...) +static void FORMAT_ATTR(2) append(struct type_name *name, const char *fmt, ...) { static char buffer[512]; int n; -- 2.11.4.GIT