Skip to content

[dev] Fix format specifiers for MinGW ANSI stdio #10188

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: development
Choose a base branch
from

Conversation

davidhorstmann-arm
Copy link
Contributor

@davidhorstmann-arm davidhorstmann-arm commented May 21, 2025

Trivial forward-port of #10165

Instead of using the windows-specific "I64d" format specifier, use the friendly MinGW abstraction PRId64, which works both when __USE_MINGW_ANSI_STDIO is enabled and when it is disabled.

PR checklist

Please remove the segment/s on either side of the | symbol as appropriate, and add any relevant link/s to the end of the line.
If the provided content is part of the present PR remove the # symbol.

Instead of using the windows-specific "I64d" format specifier, use the
friendly MinGW abstraction PRId64, which works both when
__USE_MINGW_ANSI_STDIO is enabled and when it is disabled.

Signed-off-by: David Horstmann <[email protected]>
@davidhorstmann-arm davidhorstmann-arm added needs-review Every commit must be reviewed by at least two team members, needs-ci Needs to pass CI tests needs-reviewer This PR needs someone to pick it up for review labels May 21, 2025
@davidhorstmann-arm davidhorstmann-arm force-pushed the fix-mingw-ansi-stdio-dev branch from bbe869b to ecaddcc Compare May 21, 2025 13:54
@davidhorstmann-arm davidhorstmann-arm changed the title [dev] Fix format specifiers for ANSI stdio [dev] Fix format specifiers for MinGW ANSI stdio May 21, 2025
@irwir
Copy link
Contributor

irwir commented May 23, 2025

use the friendly MinGW abstraction

This is in C99 standard, supported in MSVC since VS 2013.
Maybe these macros could be used in v4 directly, without the current intermediate definitions.

@gilles-peskine-arm
Copy link
Contributor

@irwir Unfortunately MinGW lags behind when it comes to C99 support for printf. And PRId64 is not a portable specified for size_t anyway: it only works when size_t is a 64-bit type. The C99 standard specifier for size_t is %zu, but some popular Windows toolchains still don't accept it.

@irwir
Copy link
Contributor

irwir commented May 24, 2025

All PRI* macros (with <inttypes.h> as the standard place) together with %zu and %lld format specifiers appeared in C99.
So both #if and #else branches adhere to C99.
By the way, time format definition conditions below could be reduced to unconditional one line:
#define MBEDTLS_PRINTF_MS_TIME MBEDTLS_PRINTF_LONGLONG

And PRId64 is not a portable specified for size_t anyway: it only works when size_t is a 64-bit type.

Actually, PRIuPTR for size_t as in the code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-ci Needs to pass CI tests needs-review Every commit must be reviewed by at least two team members, needs-reviewer This PR needs someone to pick it up for review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants