From 4ec9536339a8209720633a78c76f74d707976522 Mon Sep 17 00:00:00 2001 From: Gilles Peskine Date: Thu, 26 Feb 2026 21:34:32 +0100 Subject: [PATCH] Temporarily force standard *printf functions on MingW On MingW, temporarily force the use of the standard versions of `snprintf()` and `vsnprintf()` (since we set `__USE_MINGW_ANSI_STDIO` in `mbedtls_platform_requirements.h`). Do not honor `platform.h` configuration, because with the current TF-PSA-Crypto, `MBEDTLS_PLATFORM_VSNPRINTF_ALT and `MBEDTLS_PLATFORM_SNPRINTF_ALT` are always enabled on MinGW, so what matters is the setting of `__USE_MINGW_ANSI_STDIO` when `platform.c` is built, and until https://github.com/Mbed-TLS/TF-PSA-Crypto/pull/694, the legacy printf functions are used there. Revert this commit once the `tf-psa-crypto` module is updated with the merge of https://github.com/Mbed-TLS/TF-PSA-Crypto/pull/694. Signed-off-by: Gilles Peskine --- library/debug.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/library/debug.c b/library/debug.c index c27d15d12e..59969070c4 100644 --- a/library/debug.c +++ b/library/debug.c @@ -21,6 +21,20 @@ /* DEBUG_BUF_SIZE must be at least 2 */ #define DEBUG_BUF_SIZE 512 +/* Temporary hack: on MingW, do not honor the platform.h configuration + * for snprintf and vsnprintf. Instead, force the native functions, + * which are the standard ones, not the Windows legacy ones. + * + * This hack should be removed once TF-PSA-Crypto has been updated to + * use the standard printf family. + */ +#if defined(__MINGW32__) +#undef mbedtls_snprintf +#define mbedtls_snprintf snprintf +#undef mbedtls_vsnprintf +#define mbedtls_vsnprintf vsnprintf +#endif + int mbedtls_debug_snprintf(char *dest, size_t maxlen, const char *format, ...) {