diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2014-01-23 17:18:23 -0500 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2014-01-23 17:18:33 -0500 |
commit | ac4ef637ad2ff2a24847f67d14027b8745f6741e (patch) | |
tree | cb49061503740d1bd9a0c916df55a29b4973fa64 /src/backend/access | |
parent | ec8f692c3cd5760435712b7ec4afa8f014ed7b2e (diff) | |
download | postgresql-ac4ef637ad2ff2a24847f67d14027b8745f6741e.tar.gz postgresql-ac4ef637ad2ff2a24847f67d14027b8745f6741e.zip |
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/backend/access')
-rw-r--r-- | src/backend/access/common/indextuple.c | 5 | ||||
-rw-r--r-- | src/backend/access/gin/ginentrypage.c | 5 | ||||
-rw-r--r-- | src/backend/access/hash/hashinsert.c | 5 | ||||
-rw-r--r-- | src/backend/access/heap/hio.c | 7 | ||||
-rw-r--r-- | src/backend/access/heap/rewriteheap.c | 5 | ||||
-rw-r--r-- | src/backend/access/nbtree/nbtinsert.c | 5 | ||||
-rw-r--r-- | src/backend/access/nbtree/nbtsort.c | 5 | ||||
-rw-r--r-- | src/backend/access/spgist/spgdoinsert.c | 6 | ||||
-rw-r--r-- | src/backend/access/spgist/spgutils.c | 11 | ||||
-rw-r--r-- | src/backend/access/transam/xlog.c | 4 |
10 files changed, 25 insertions, 33 deletions
diff --git a/src/backend/access/common/indextuple.c b/src/backend/access/common/indextuple.c index 840a2924b0a..b4c68e9fe27 100644 --- a/src/backend/access/common/indextuple.c +++ b/src/backend/access/common/indextuple.c @@ -165,9 +165,8 @@ index_form_tuple(TupleDesc tupleDescriptor, if ((size & INDEX_SIZE_MASK) != size) ereport(ERROR, (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED), - errmsg("index row requires %lu bytes, maximum size is %lu", - (unsigned long) size, - (unsigned long) INDEX_SIZE_MASK))); + errmsg("index row requires %zu bytes, maximum size is %zu", + size, (Size) INDEX_SIZE_MASK))); infomask |= size; diff --git a/src/backend/access/gin/ginentrypage.c b/src/backend/access/gin/ginentrypage.c index d5aa243a659..5c7893419d4 100644 --- a/src/backend/access/gin/ginentrypage.c +++ b/src/backend/access/gin/ginentrypage.c @@ -105,9 +105,8 @@ GinFormTuple(GinState *ginstate, if (errorTooBig) ereport(ERROR, (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED), - errmsg("index row size %lu exceeds maximum %lu for index \"%s\"", - (unsigned long) newsize, - (unsigned long) GinMaxItemSize, + errmsg("index row size %zu exceeds maximum %zu for index \"%s\"", + (Size) newsize, (Size) GinMaxItemSize, RelationGetRelationName(ginstate->index)))); pfree(itup); return NULL; diff --git a/src/backend/access/hash/hashinsert.c b/src/backend/access/hash/hashinsert.c index 090db0bdf8b..49211eef9a3 100644 --- a/src/backend/access/hash/hashinsert.c +++ b/src/backend/access/hash/hashinsert.c @@ -65,9 +65,8 @@ _hash_doinsert(Relation rel, IndexTuple itup) if (itemsz > HashMaxItemSize((Page) metap)) ereport(ERROR, (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED), - errmsg("index row size %lu exceeds hash maximum %lu", - (unsigned long) itemsz, - (unsigned long) HashMaxItemSize((Page) metap)), + errmsg("index row size %zu exceeds hash maximum %zu", + itemsz, HashMaxItemSize((Page) metap)), errhint("Values larger than a buffer page cannot be indexed."))); /* diff --git a/src/backend/access/heap/hio.c b/src/backend/access/heap/hio.c index a0a97784f1c..b306398aec1 100644 --- a/src/backend/access/heap/hio.c +++ b/src/backend/access/heap/hio.c @@ -237,9 +237,8 @@ RelationGetBufferForTuple(Relation relation, Size len, if (len > MaxHeapTupleSize) ereport(ERROR, (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED), - errmsg("row is too big: size %lu, maximum size %lu", - (unsigned long) len, - (unsigned long) MaxHeapTupleSize))); + errmsg("row is too big: size %zu, maximum size %zu", + len, MaxHeapTupleSize))); /* Compute desired extra freespace due to fillfactor option */ saveFreeSpace = RelationGetTargetPageFreeSpace(relation, @@ -477,7 +476,7 @@ RelationGetBufferForTuple(Relation relation, Size len, if (len > PageGetHeapFreeSpace(page)) { /* We should not get here given the test at the top */ - elog(PANIC, "tuple is too big: size %lu", (unsigned long) len); + elog(PANIC, "tuple is too big: size %zu", len); } /* diff --git a/src/backend/access/heap/rewriteheap.c b/src/backend/access/heap/rewriteheap.c index bb719c76947..c34ab9865f8 100644 --- a/src/backend/access/heap/rewriteheap.c +++ b/src/backend/access/heap/rewriteheap.c @@ -601,9 +601,8 @@ raw_heap_insert(RewriteState state, HeapTuple tup) if (len > MaxHeapTupleSize) ereport(ERROR, (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED), - errmsg("row is too big: size %lu, maximum size %lu", - (unsigned long) len, - (unsigned long) MaxHeapTupleSize))); + errmsg("row is too big: size %zu, maximum size %zu", + len, MaxHeapTupleSize))); /* Compute desired extra freespace due to fillfactor option */ saveFreeSpace = RelationGetTargetPageFreeSpace(state->rs_new_rel, diff --git a/src/backend/access/nbtree/nbtinsert.c b/src/backend/access/nbtree/nbtinsert.c index 11d930bd8da..49c084a5abe 100644 --- a/src/backend/access/nbtree/nbtinsert.c +++ b/src/backend/access/nbtree/nbtinsert.c @@ -537,9 +537,8 @@ _bt_findinsertloc(Relation rel, if (itemsz > BTMaxItemSize(page)) ereport(ERROR, (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED), - errmsg("index row size %lu exceeds maximum %lu for index \"%s\"", - (unsigned long) itemsz, - (unsigned long) BTMaxItemSize(page), + errmsg("index row size %zu exceeds maximum %zu for index \"%s\"", + itemsz, BTMaxItemSize(page), RelationGetRelationName(rel)), errhint("Values larger than 1/3 of a buffer page cannot be indexed.\n" "Consider a function index of an MD5 hash of the value, " diff --git a/src/backend/access/nbtree/nbtsort.c b/src/backend/access/nbtree/nbtsort.c index 504eb716006..9ddc2754997 100644 --- a/src/backend/access/nbtree/nbtsort.c +++ b/src/backend/access/nbtree/nbtsort.c @@ -482,9 +482,8 @@ _bt_buildadd(BTWriteState *wstate, BTPageState *state, IndexTuple itup) if (itupsz > BTMaxItemSize(npage)) ereport(ERROR, (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED), - errmsg("index row size %lu exceeds maximum %lu for index \"%s\"", - (unsigned long) itupsz, - (unsigned long) BTMaxItemSize(npage), + errmsg("index row size %zu exceeds maximum %zu for index \"%s\"", + itupsz, BTMaxItemSize(npage), RelationGetRelationName(wstate->index)), errhint("Values larger than 1/3 of a buffer page cannot be indexed.\n" "Consider a function index of an MD5 hash of the value, " diff --git a/src/backend/access/spgist/spgdoinsert.c b/src/backend/access/spgist/spgdoinsert.c index 2f6a8781b1e..1f5d97694db 100644 --- a/src/backend/access/spgist/spgdoinsert.c +++ b/src/backend/access/spgist/spgdoinsert.c @@ -1885,9 +1885,9 @@ spgdoinsert(Relation index, SpGistState *state, if (leafSize > SPGIST_PAGE_CAPACITY && !state->config.longValuesOK) ereport(ERROR, (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED), - errmsg("index row size %lu exceeds maximum %lu for index \"%s\"", - (unsigned long) (leafSize - sizeof(ItemIdData)), - (unsigned long) (SPGIST_PAGE_CAPACITY - sizeof(ItemIdData)), + errmsg("index row size %zu exceeds maximum %zu for index \"%s\"", + leafSize - sizeof(ItemIdData), + SPGIST_PAGE_CAPACITY - sizeof(ItemIdData), RelationGetRelationName(index)), errhint("Values larger than a buffer page cannot be indexed."))); diff --git a/src/backend/access/spgist/spgutils.c b/src/backend/access/spgist/spgutils.c index 1754f05aea4..3cbad99e46a 100644 --- a/src/backend/access/spgist/spgutils.c +++ b/src/backend/access/spgist/spgutils.c @@ -602,9 +602,8 @@ spgFormNodeTuple(SpGistState *state, Datum label, bool isnull) if ((size & INDEX_SIZE_MASK) != size) ereport(ERROR, (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED), - errmsg("index row requires %lu bytes, maximum size is %lu", - (unsigned long) size, - (unsigned long) INDEX_SIZE_MASK))); + errmsg("index row requires %zu bytes, maximum size is %zu", + (Size) size, (Size) INDEX_SIZE_MASK))); tup = (SpGistNodeTuple) palloc0(size); @@ -661,9 +660,9 @@ spgFormInnerTuple(SpGistState *state, bool hasPrefix, Datum prefix, if (size > SPGIST_PAGE_CAPACITY - sizeof(ItemIdData)) ereport(ERROR, (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED), - errmsg("SP-GiST inner tuple size %lu exceeds maximum %lu", - (unsigned long) size, - (unsigned long) (SPGIST_PAGE_CAPACITY - sizeof(ItemIdData))), + errmsg("SP-GiST inner tuple size %zu exceeds maximum %zu", + (Size) size, + SPGIST_PAGE_CAPACITY - sizeof(ItemIdData)), errhint("Values larger than a buffer page cannot be indexed."))); /* diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c index 8679d0aa7f4..9559d6d6aef 100644 --- a/src/backend/access/transam/xlog.c +++ b/src/backend/access/transam/xlog.c @@ -2738,9 +2738,9 @@ XLogWrite(XLogwrtRqst WriteRqst, bool flexible) ereport(PANIC, (errcode_for_file_access(), errmsg("could not write to log file %s " - "at offset %u, length %lu: %m", + "at offset %u, length %zu: %m", XLogFileNameP(ThisTimeLineID, openLogSegNo), - openLogOff, (unsigned long) nbytes))); + openLogOff, nbytes))); } nleft -= written; from += written; |