Skip to content

Commit

Permalink
vpx_codec_internal.h: add LIBVPX_FORMAT_PRINTF
Browse files Browse the repository at this point in the history
and use it to set the format attribute for the printf like function
vpx_internal_error(). this allows the main library to be built with
-Wformat-nonliteral without producing warnings; the examples will be
handled in a followup.

Bug: webm:1744
Change-Id: Iebc322e24db35d902c5a2b1ed767d2e10e9c91b9
  • Loading branch information
jzern committed Nov 3, 2021
1 parent c56ab7d commit 340f605
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions vpx/internal/vpx_codec_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -435,9 +435,21 @@ struct vpx_internal_error_info {
#endif
#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 LIBVPX_FORMAT_PRINTF(string_index, first_to_check)
#if defined(__has_attribute)
#if __has_attribute(format)
#undef LIBVPX_FORMAT_PRINTF
#define LIBVPX_FORMAT_PRINTF(string_index, first_to_check) \
__attribute__((__format__(__printf__, string_index, first_to_check)))
#endif
#endif

void vpx_internal_error(struct vpx_internal_error_info *info,
vpx_codec_err_t error, const char *fmt,
...) CLANG_ANALYZER_NORETURN;
vpx_codec_err_t error, const char *fmt, ...)
LIBVPX_FORMAT_PRINTF(3, 4) CLANG_ANALYZER_NORETURN;

#ifdef __cplusplus
} // extern "C"
Expand Down

0 comments on commit 340f605

Please sign in to comment.