MingW: insist on standard-compliant printf() and friends

Always activate `__USE_MINGW_ANSI_STDIO` unless overridden on the command
line. This is necessary with older versions of MingW and/or Windows,
where snprintf does not always zero-terminate the buffer, and does
not support formats such as `"%zu"` for size_t and `"%lld"` for long long.

Simplify debug.h accordingly. The macros `MBEDTLS_PRINTF_SIZET`,
`MBEDTLS_PRINTF_SIZET_HAX` and `MBEDTLS_PRINTF_LONGLONG` are no longer
needed, but they are still used in our code base and must stay in debug.h
for backward compatibility.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
This commit is contained in:
Gilles Peskine
2026-01-30 20:39:10 +01:00
parent 3c67824964
commit cdf3b0a535
2 changed files with 24 additions and 25 deletions

View File

@@ -15,4 +15,18 @@
#ifndef MBEDTLS_MBEDTLS_PLATFORM_REQUIREMENTS_H
#define MBEDTLS_MBEDTLS_PLATFORM_REQUIREMENTS_H
/* On Mingw-w64, force the use of a C99-compliant printf() and friends.
* This is necessary on older versions of Mingw and/or Windows runtimes
* where snprintf does not always zero-terminate the buffer, and does
* not support formats such as "%zu" for size_t and "%lld" for long long.
*
* Defining __USE_MINGW_ANSI_STDIO=0 may work and provide a small code size
* and performance benefit for some combinations of older Mingw and Windows
* versions. Do this at your own risk and make sure that least
* test_suite_debug passes.
*/
#if !defined(__USE_MINGW_ANSI_STDIO)
#define __USE_MINGW_ANSI_STDIO 1
#endif
#endif /* MBEDTLS_MBEDTLS_PLATFORM_REQUIREMENTS_H */