1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-28 23:42:10 +03:00

Allow use of "z" flag in our printf calls, and use it where appropriate.

Since C99, it's been standard for printf and friends to accept a "z" size
modifier, meaning "whatever size size_t has".  Up to now we've generally
dealt with printing size_t values by explicitly casting them to unsigned
long and using the "l" modifier; but this is really the wrong thing on
platforms where pointers are wider than longs (such as Win64).  So let's
start using "z" instead.  To ensure we can do that on all platforms, teach
src/port/snprintf.c to understand "z", and add a configure test to force
use of that implementation when the platform's version doesn't handle "z".

Having done that, modify a bunch of places that were using the
unsigned-long hack to use "z" instead.  This patch doesn't pretend to have
gotten everyplace that could benefit, but it catches many of them.  I made
an effort in particular to ensure that all uses of the same error message
text were updated together, so as not to increase the number of
translatable strings.

It's possible that this change will result in format-string warnings from
pre-C99 compilers.  We might have to reconsider if there are any popular
compilers that will warn about this; but let's start by seeing what the
buildfarm thinks.

Andres Freund, with a little additional work by me
This commit is contained in:
Tom Lane
2014-01-23 17:18:23 -05:00
parent ec8f692c3c
commit ac4ef637ad
27 changed files with 221 additions and 125 deletions

View File

@ -1533,8 +1533,8 @@ for the exact reason.]])],
# Force use of our snprintf if system's doesn't do arg control
# See comment above at snprintf test for details.
if test "$enable_nls" = yes -a "$pgac_need_repl_snprintf" = no; then
PGAC_FUNC_PRINTF_ARG_CONTROL
if test $pgac_cv_printf_arg_control != yes ; then
PGAC_FUNC_SNPRINTF_ARG_CONTROL
if test $pgac_cv_snprintf_arg_control != yes ; then
pgac_need_repl_snprintf=yes
fi
fi
@ -1617,6 +1617,14 @@ AC_DEFINE_UNQUOTED(INT64_FORMAT, $INT64_FORMAT,
AC_DEFINE_UNQUOTED(UINT64_FORMAT, $UINT64_FORMAT,
[Define to the appropriate snprintf format for unsigned 64-bit ints.])
# Also force use of our snprintf if the system's doesn't support the %z flag.
if test "$pgac_need_repl_snprintf" = no; then
PGAC_FUNC_SNPRINTF_SIZE_T_SUPPORT
if test "$pgac_cv_snprintf_size_t_support" != yes; then
pgac_need_repl_snprintf=yes
fi
fi
# Now we have checked all the reasons to replace snprintf
if test $pgac_need_repl_snprintf = yes; then
AC_DEFINE(USE_REPL_SNPRINTF, 1, [Use replacement snprintf() functions.])