Fix: format string warnings on mingw
authorSimon Marchi <simon.marchi@efficios.com>
Wed, 9 Oct 2019 19:10:00 +0000 (15:10 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Thu, 17 Oct 2019 16:13:26 +0000 (12:13 -0400)
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 <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/2161
Reviewed-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Tested-by: jenkins <jenkins@lttng.org>
tests/utils/tap/tap.h

index 764f75dae00469463eb9e2e058e24356e204172b..190c4a942b42c10ba1a7684131c5993699e3a41d 100644 (file)
 
 #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);
 
This page took 0.026556 seconds and 4 git commands to generate.