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)
commit11266c962a9f658bb817458c11d2986322b106d3
treeda3b1e07473f1014ede174f6e25c039bc84fe7ee
parent98b5e1698a1a66c3be41755936474f2d4d762072
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 <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
This page took 0.024117 seconds and 4 git commands to generate.