From 11266c962a9f658bb817458c11d2986322b106d3 Mon Sep 17 00:00:00 2001 From: Simon Marchi Date: Wed, 9 Oct 2019 15:10:00 -0400 Subject: [PATCH] Fix: format string warnings on mingw Since we have added format string attributes in the tap.h file, we get these diagnostics on Windows: CC test_bitfield.o test_bitfield.c: In function 'run_test_unsigned_write': test_bitfield.c:51:36: error: unknown conversion type character 'l' in format [-Werror=format=] 51 | #define DIAG_FMT_STR(val_type_fmt) "Failed reading value written \"%s\"-wise, with start=%i" \ | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ test_bitfield.c:51:36: note: in definition of macro 'DIAG_FMT_STR' 51 | #define DIAG_FMT_STR(val_type_fmt) "Failed reading value written \"%s\"-wise, with start=%i" \ | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ test_bitfield.c:173:8: note: in expansion of macro 'check_result' 173 | if (check_result(src_ui, readval, target.c, unsigned char, | ^~~~~~~~~~~~ test_bitfield.c:175:9: note: format string is defined here 175 | "%llX")) { | ^ By default, printf on Windows doesn't know about the `ll` format string length modifier (as in %llx). However, we build Babeltrace with the __USE_MINGW_ANSI_STDIO macro defined, which makes mingw use a replacement printf implementation that knows about `ll`. When we define our own functions with a format attribute, we must then use __MINGW_PRINTF_FORMAT instead of `printf`. __MINGW_PRINTF_FORMAT will take the right value, depending on __USE_MINGW_ANSI_STDIO, so it will validate the format string according to the selected printf implementation. Change-Id: I89b194e915250a0e0a617817a1cd10fedb156639 Signed-off-by: Simon Marchi Reviewed-on: https://review.lttng.org/c/babeltrace/+/2161 Reviewed-by: Francis Deslauriers Tested-by: jenkins --- tests/utils/tap/tap.h | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/tests/utils/tap/tap.h b/tests/utils/tap/tap.h index 764f75da..190c4a94 100644 --- a/tests/utils/tap/tap.h +++ b/tests/utils/tap/tap.h @@ -74,21 +74,27 @@ #define skip_end() } while(0); -__attribute__((format(printf, 5, 6))) +#ifdef __MINGW_PRINTF_FORMAT +# define PRINT_FORMAT __MINGW_PRINTF_FORMAT +#else +# define PRINT_FORMAT printf +#endif + +__attribute__((format(PRINT_FORMAT, 5, 6))) unsigned int _gen_result(int, const char *, const char *, unsigned int, const char *, ...); int plan_no_plan(void); int plan_skip_all(const char *); int plan_tests(unsigned int); -__attribute__((format(printf, 1, 2))) +__attribute__((format(PRINT_FORMAT, 1, 2))) unsigned int diag(const char *, ...); void diag_multiline(const char *); -__attribute__((format(printf, 2, 3))) +__attribute__((format(PRINT_FORMAT, 2, 3))) int skip(unsigned int, const char *, ...); -__attribute__((format(printf, 1, 2))) +__attribute__((format(PRINT_FORMAT, 1, 2))) void todo_start(const char *, ...); void todo_end(void); -- 2.34.1