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 <Gilles.Peskine@arm.com>
This commit is contained in:
Gilles Peskine
2026-02-26 21:34:32 +01:00
parent 64ff7fc1dc
commit 4ec9536339

View File

@@ -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, ...)
{