Skip printf("%zu") tests with MinGW

MinGW uses a legacy printf by default which doesn't support the `z` modifier
for `size_t`. Skip these test cases on MinGW.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
This commit is contained in:
Gilles Peskine
2026-02-23 20:30:33 +01:00
parent 5c6ec6bcc0
commit 08614e1e96
2 changed files with 18 additions and 1 deletions

View File

@@ -60,16 +60,19 @@ printf "%u", 0x80000000
printf_integer:"%u":PRINTF_CAST_INT:-0x80000000:"2147483648"
printf "%zx", 0x12345678
depends_on:HAVE_C99_PRINTF
printf_integer:"%zx":PRINTF_CAST_SIZE_T:0x12345678:"12345678"
printf "%zu", 0x80000000
depends_on:HAVE_C99_PRINTF
printf_integer:"%zu":PRINTF_CAST_SIZE_T:0x80000000:"2147483648"
printf "%zx", 0xffffffff
depends_on:HAVE_C99_PRINTF
printf_integer:"%zx":PRINTF_CAST_SIZE_T:0xffffffff:"ffffffff"
printf "%zx", 0xffffffffffffffff
depends_on:SIZE_T_AT_LEAST_64_BIT
depends_on:HAVE_C99_PRINTF:SIZE_T_AT_LEAST_64_BIT
printf_integer:"%zx":PRINTF_CAST_SIZE_T:0xffffffffffffffff:"ffffffffffffffff"
printf "%lld", 0x7fffffffffffffff

View File

@@ -19,6 +19,20 @@
#define SIZE_T_AT_LEAST_64_BIT
#endif
/* Older Windows runtimes have a non-compliant printf family, e.g.
* it doesn't understand `%zu` to print a `size_t`. MSVC provides a
* C99-compliant printf family (at least enough for our purposes),
* since Visual Studio 2015. With MinGW, you get the non-compliant legacy
* printf by default, but can select the standard-compliant version
* at compile time. In the Mbed TLS 3.6 LTS, we use the default, so
* we can't rely on %z being understood. The debug module defines
* `MBEDTLS_PRINTF_SIZET` for that, and this is tested in test_suite_debug.
* Here we just skip the test cases that break the legacy Windows printf.
*/
#if !(defined(__MINGW32__))
#define HAVE_C99_PRINTF
#endif
typedef enum {
PRINTF_CAST_INT,
PRINTF_CAST_UNSIGNED,