mirror of
https://github.com/Mbed-TLS/mbedtls-framework.git
synced 2026-08-24 03:59:53 +00:00
Stop using MBEDTLS_PRINTF_SIZET
Since Mbed TLS 3.6.0, all officially supported versions of Visual Studio a printf function family that is sufficiently compliant to C99 for our purposes, in particular supporting `%zu` for `size_t`. The only platform without `%zu` that we semi-officially support is older versions of MinGW, still used in our CI. MinGW provides either a Windows legacy printf or a standards-compliant printf depending on the value of `__USE_MINGW_ANSI_STDIO` when compiling each C file. Force the use of the compliant version. Don't rely on `MBEDTLS_PRINTF_SIZET`, which is defined in `<mbedtls/debug.h>` and no longer considers the Windows legacy version in Mbed TLS >= 4.1. Signed-off-by: Gilles Peskine <[email protected]>
This commit is contained in:
@@ -110,6 +110,17 @@ class Base:
|
||||
|
||||
''')
|
||||
|
||||
if not header:
|
||||
# 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.
|
||||
prologue += strip_indentation(f'''
|
||||
#if !defined(__USE_MINGW_ANSI_STDIO)
|
||||
#define __USE_MINGW_ANSI_STDIO 1
|
||||
#endif
|
||||
''')
|
||||
|
||||
for include in self._INCLUDES:
|
||||
prologue += "#include {}\n".format(include)
|
||||
|
||||
@@ -403,7 +414,6 @@ class Logging(Base):
|
||||
#if defined(MBEDTLS_FS_IO) && defined(MBEDTLS_TEST_HOOKS)
|
||||
#include <stdio.h>
|
||||
#include <inttypes.h>
|
||||
#include <mbedtls/debug.h> // for MBEDTLS_PRINTF_SIZET
|
||||
#include <mbedtls/platform.h> // for mbedtls_fprintf
|
||||
#endif /* defined(MBEDTLS_FS_IO) && defined(MBEDTLS_TEST_HOOKS) */
|
||||
""")
|
||||
@@ -412,7 +422,7 @@ class Logging(Base):
|
||||
'int': '%d',
|
||||
'long': '%ld',
|
||||
'long long': '%lld',
|
||||
'size_t': '%"MBEDTLS_PRINTF_SIZET"',
|
||||
'size_t': '%zu',
|
||||
'unsigned': '0x%08x',
|
||||
'unsigned int': '0x%08x',
|
||||
'unsigned long': '0x%08lx',
|
||||
|
||||
Reference in New Issue
Block a user