From f4aceedd4da965e62df5340a8f06c36d5fc3bbc1 Mon Sep 17 00:00:00 2001 From: Bruce Dawson Date: Tue, 18 Nov 2014 09:55:38 -0800 Subject: Fixing format strings to remove 'z' size specifier. As of the 2013 version VC++ still doesn't support the 'z' size specifier. This makes portable printing of size_t types frustrating. The simplest general solution is to use %u and cast to unsigned. If there was any possibility of the numbers getting larger than 32-bit then we would need better alternatives, but there is not. This was found through code inspection, through /analyze, and through pdfium_test print this non-helpful message: Loaded, parsed and rendered zu pages. Skipped zu bad pages. I can confirm that the fix works on Windows and it should work identically on mac. This is a follow-on to change 02e6ca4c4f. R=tsepez@chromium.org Review URL: https://codereview.chromium.org/738433003 --- core/include/fxcrt/fx_system.h | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'core/include') diff --git a/core/include/fxcrt/fx_system.h b/core/include/fxcrt/fx_system.h index 36050f35dc..355bd74327 100644 --- a/core/include/fxcrt/fx_system.h +++ b/core/include/fxcrt/fx_system.h @@ -293,4 +293,35 @@ typedef base::CheckedNumeric FX_SAFE_SIZE_T; #define FX_OVERRIDE #endif #endif + +// To print a size_t value in a portable way: +// size_t size; +// printf("xyz: %" PRIuS, size); +// The "u" in the macro corresponds to %u, and S is for "size". + +#if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_ + +#if (defined(_INTTYPES_H) || defined(_INTTYPES_H_)) && !defined(PRId64) +#error "inttypes.h has already been included before this header file, but " +#error "without __STDC_FORMAT_MACROS defined." +#endif + +#if !defined(__STDC_FORMAT_MACROS) +#define __STDC_FORMAT_MACROS +#endif + +#include + +#if !defined(PRIuS) +#define PRIuS "zu" +#endif + +#else // _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ + +#if !defined(PRIuS) +#define PRIuS "Iu" +#endif + +#endif + #endif -- cgit v1.2.3