Skip to content

Commit

Permalink
Add printf format attributes
Browse files Browse the repository at this point in the history
When compiling with gcc, we already include the attribute on check_msg()
to give compiler warnings about mismatches between printf() like format
strings and the corresponding arguments.  This patch adds similar
attributes for lexical_error() and die().

Suggested-by: Nicolas Iooss <nicolas.iooss_linux@m4x.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
  • Loading branch information
dgibson committed Feb 27, 2017
1 parent f72508e commit 34a9886
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
6 changes: 6 additions & 0 deletions dtc-lexer.l
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,13 @@ static int dts_version = 1;

static void push_input_file(const char *filename);
static bool pop_input_file(void);
#ifdef __GNUC__
static void lexical_error(const char *fmt, ...)
__attribute__((format (printf, 1, 2)));
#else
static void lexical_error(const char *fmt, ...);
#endif

%}

%%
Expand Down
14 changes: 13 additions & 1 deletion util.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,13 @@

#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))

static inline void __attribute__((noreturn)) die(const char *str, ...)
#ifdef __GNUC__
static inline void
__attribute__((noreturn)) __attribute__((format (printf, 1, 2)))
die(const char *str, ...)
#else
static inline void die(const char *str, ...)
#endif
{
va_list ap;

Expand Down Expand Up @@ -59,7 +65,13 @@ static inline void *xrealloc(void *p, size_t len)
}

extern char *xstrdup(const char *s);

#ifdef __GNUC__
extern int __attribute__((format (printf, 2, 3)))
xasprintf(char **strp, const char *fmt, ...);
#else
extern int xasprintf(char **strp, const char *fmt, ...);
#endif
extern char *join_path(const char *path, const char *name);

/**
Expand Down

0 comments on commit 34a9886

Please sign in to comment.