summaryrefslogtreecommitdiff
path: root/src/port/snprintf.c
diff options
context:
space:
mode:
authorTom Lane2014-01-23 22:18:23 +0000
committerTom Lane2014-01-23 22:18:33 +0000
commitac4ef637ad2ff2a24847f67d14027b8745f6741e (patch)
treecb49061503740d1bd9a0c916df55a29b4973fa64 /src/port/snprintf.c
parentec8f692c3cd5760435712b7ec4afa8f014ed7b2e (diff)
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
Diffstat (limited to 'src/port/snprintf.c')
-rw-r--r--src/port/snprintf.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/port/snprintf.c b/src/port/snprintf.c
index 9f719505f49..d3f890fae99 100644
--- a/src/port/snprintf.c
+++ b/src/port/snprintf.c
@@ -386,6 +386,19 @@ nextch1:
else
longflag = 1;
goto nextch1;
+ case 'z':
+#if SIZEOF_SIZE_T == 8
+#ifdef HAVE_LONG_INT_64
+ longflag = 1;
+#elif defined(HAVE_LONG_LONG_INT_64)
+ longlongflag = 1;
+#else
+#error "Don't know how to print 64bit integers"
+#endif
+#else
+ /* assume size_t is same size as int */
+#endif
+ goto nextch1;
case 'h':
case '\'':
/* ignore these */
@@ -619,6 +632,19 @@ nextch2:
else
longflag = 1;
goto nextch2;
+ case 'z':
+#if SIZEOF_SIZE_T == 8
+#ifdef HAVE_LONG_INT_64
+ longflag = 1;
+#elif defined(HAVE_LONG_LONG_INT_64)
+ longlongflag = 1;
+#else
+#error "Don't know how to print 64bit integers"
+#endif
+#else
+ /* assume size_t is same size as int */
+#endif
+ goto nextch2;
case 'h':
case '\'':
/* ignore these */