diff options
author | James Zern <jzern@google.com> | 2021-11-02 17:19:10 -0700 |
---|---|---|
committer | James Zern <jzern@google.com> | 2021-11-02 17:21:56 -0700 |
commit | dd10ac8f69c1bc77fc69cd10de51092d07fbebb5 (patch) | |
tree | 8f1e0caf276c856beefbbfbaa4ba296b5b51b84b /tools_common.h | |
parent | 340f60524ffa35c7324c54fe404d84cc1a1ac402 (diff) | |
download | libvpx-dd10ac8f69c1bc77fc69cd10de51092d07fbebb5.tar libvpx-dd10ac8f69c1bc77fc69cd10de51092d07fbebb5.tar.gz libvpx-dd10ac8f69c1bc77fc69cd10de51092d07fbebb5.tar.bz2 libvpx-dd10ac8f69c1bc77fc69cd10de51092d07fbebb5.zip |
tools_common.h: add VPX_TOOLS_FORMAT_PRINTF
and use it to set the format attribute for printf like functions. this
allows the examples to be built with -Wformat-nonliteral without
producing warnings.
Bug: webm:1744
Change-Id: I26b4c41c9a42790053b1ae0e4a678af8f2cd1d82
Fixed: webm:1744
Diffstat (limited to 'tools_common.h')
-rw-r--r-- | tools_common.h | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/tools_common.h b/tools_common.h index 4e8851fc1..b9cfb9cc8 100644 --- a/tools_common.h +++ b/tools_common.h @@ -116,12 +116,24 @@ extern "C" { #define VPX_NO_RETURN #endif +// Tells the compiler to perform `printf` format string checking if the +// compiler supports it; see the 'format' attribute in +// <https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html>. +#define VPX_TOOLS_FORMAT_PRINTF(string_index, first_to_check) +#if defined(__has_attribute) +#if __has_attribute(format) +#undef VPX_TOOLS_FORMAT_PRINTF +#define VPX_TOOLS_FORMAT_PRINTF(string_index, first_to_check) \ + __attribute__((__format__(__printf__, string_index, first_to_check))) +#endif +#endif + /* Sets a stdio stream into binary mode */ FILE *set_binary_mode(FILE *stream); -VPX_NO_RETURN void die(const char *fmt, ...); -VPX_NO_RETURN void fatal(const char *fmt, ...); -void warn(const char *fmt, ...); +VPX_NO_RETURN void die(const char *fmt, ...) VPX_TOOLS_FORMAT_PRINTF(1, 2); +VPX_NO_RETURN void fatal(const char *fmt, ...) VPX_TOOLS_FORMAT_PRINTF(1, 2); +void warn(const char *fmt, ...) VPX_TOOLS_FORMAT_PRINTF(1, 2); VPX_NO_RETURN void die_codec(vpx_codec_ctx_t *ctx, const char *s); |