Skip to content

Commit

Permalink
Fix -Wformat / -Wformat-non-iso on MinGW UCRT
Browse files Browse the repository at this point in the history
  • Loading branch information
tongyuantongyu committed Mar 10, 2022
1 parent 1d5ea8e commit 81e7cdf
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions apps/shared/avifutil.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,18 @@

#include "avif/avif.h"

// The %z format specifier is not available with Visual Studios before 2013 and mingw-w64 toolchains
// with `__USE_MINGW_ANSI_STDIO` not set to 1. Hence the %I format specifier must be used instead
// to print out `size_t`. Newer Visual Studios and mingw-w64 toolchains built with the commit
// mentioned with c99 set as the standard supports the %z specifier properly.
// The %z format specifier is not available in old version of msvcrt, which is
// used by Visual Studios before 2013 and usually mingw-w64 toolchains.
// Hence the %I format specifier must be used instead to print out `size_t`.
// Visual Studio from 2015 uses UCRT, which supports the %z specifier properly;
// mingw-w64 toolchains can also be configured to use UCRT.
// Additionally, with c99 set as the standard mingw-w64 toolchains built with
// the commit mentioned can patch format functions to support the %z specifier,
// and this can be detected by `__USE_MINGW_ANSI_STDIO` macro.
//
// Related mingw-w64 commit: bfd33f6c0ec5e652cc9911857dd1492ece8d8383

#if (defined(_MSVC) && _MSVC < 1800) || (defined(__USE_MINGW_ANSI_STDIO) && __USE_MINGW_ANSI_STDIO == 0)
#if !defined(_UCRT) && ((defined(_MSVC) && _MSVC < 1800) || (defined(__USE_MINGW_ANSI_STDIO) && __USE_MINGW_ANSI_STDIO == 0))
#define AVIF_FMT_ZU "%Iu"
#else
#define AVIF_FMT_ZU "%zu"
Expand Down

0 comments on commit 81e7cdf

Please sign in to comment.