From 2b117bb014d066549c319dcd73bd538e32b0c408 Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Tue, 9 Dec 2025 06:58:39 +0100 Subject: Remove unnecessary casts in printf format arguments (%zu/%zd) Many of these are probably left over from before use of %zu/%zd was portable. Reviewed-by: Bertrand Drouvot Discussion: https://www.postgresql.org/message-id/flat/07fa29f9-42d7-4aac-8834-197918cbbab6%40eisentraut.org --- src/backend/access/gist/gistutil.c | 4 +-- src/backend/access/gist/gistxlog.c | 6 ++-- src/backend/access/hash/hash_xlog.c | 6 ++-- src/backend/backup/basebackup_server.c | 8 ++--- src/backend/libpq/auth.c | 12 +++---- src/backend/libpq/pqcomm.c | 4 +-- src/backend/nodes/outfuncs.c | 4 +-- src/backend/storage/page/bufpage.c | 20 +++++------ src/backend/utils/adt/array_expanded.c | 4 +-- src/backend/utils/adt/arrayfuncs.c | 64 +++++++++++++++++----------------- src/backend/utils/adt/varchar.c | 8 ++--- src/backend/utils/misc/guc.c | 2 +- 12 files changed, 69 insertions(+), 73 deletions(-) (limited to 'src/backend') diff --git a/src/backend/access/gist/gistutil.c b/src/backend/access/gist/gistutil.c index 75272827837..0a29a6013ef 100644 --- a/src/backend/access/gist/gistutil.c +++ b/src/backend/access/gist/gistutil.c @@ -46,8 +46,8 @@ gistfillbuffer(Page page, IndexTuple *itup, int len, OffsetNumber off) l = PageAddItem(page, itup[i], sz, off, false, false); if (l == InvalidOffsetNumber) - elog(ERROR, "failed to add item to GiST index page, item %d out of %d, size %d bytes", - i, len, (int) sz); + elog(ERROR, "failed to add item to GiST index page, item %d out of %d, size %zu bytes", + i, len, sz); off++; } } diff --git a/src/backend/access/gist/gistxlog.c b/src/backend/access/gist/gistxlog.c index 3f5340b9206..6484ca5e2ca 100644 --- a/src/backend/access/gist/gistxlog.c +++ b/src/backend/access/gist/gistxlog.c @@ -99,8 +99,7 @@ gistRedoPageUpdateRecord(XLogReaderState *record) itup = (IndexTuple) data; itupsize = IndexTupleSize(itup); if (!PageIndexTupleOverwrite(page, offnum, itup, itupsize)) - elog(ERROR, "failed to add item to GiST index page, size %d bytes", - (int) itupsize); + elog(ERROR, "failed to add item to GiST index page, size %zu bytes", itupsize); data += itupsize; /* should be nothing left after consuming 1 tuple */ Assert(data - begin == datalen); @@ -135,8 +134,7 @@ gistRedoPageUpdateRecord(XLogReaderState *record) l = PageAddItem(page, itup, sz, off, false, false); if (l == InvalidOffsetNumber) - elog(ERROR, "failed to add item to GiST index page, size %d bytes", - (int) sz); + elog(ERROR, "failed to add item to GiST index page, size %zu bytes", sz); off++; ninserted++; } diff --git a/src/backend/access/hash/hash_xlog.c b/src/backend/access/hash/hash_xlog.c index 923cab44507..b3c0294884c 100644 --- a/src/backend/access/hash/hash_xlog.c +++ b/src/backend/access/hash/hash_xlog.c @@ -557,8 +557,7 @@ hash_xlog_move_page_contents(XLogReaderState *record) l = PageAddItem(writepage, itup, itemsz, towrite[ninserted], false, false); if (l == InvalidOffsetNumber) - elog(ERROR, "hash_xlog_move_page_contents: failed to add item to hash index page, size %d bytes", - (int) itemsz); + elog(ERROR, "hash_xlog_move_page_contents: failed to add item to hash index page, size %zu bytes", itemsz); ninserted++; } @@ -689,8 +688,7 @@ hash_xlog_squeeze_page(XLogReaderState *record) l = PageAddItem(writepage, itup, itemsz, towrite[ninserted], false, false); if (l == InvalidOffsetNumber) - elog(ERROR, "hash_xlog_squeeze_page: failed to add item to hash index page, size %d bytes", - (int) itemsz); + elog(ERROR, "hash_xlog_squeeze_page: failed to add item to hash index page, size %zu bytes", itemsz); ninserted++; } diff --git a/src/backend/backup/basebackup_server.c b/src/backend/backup/basebackup_server.c index f5c0c61640a..7678c6a231d 100644 --- a/src/backend/backup/basebackup_server.c +++ b/src/backend/backup/basebackup_server.c @@ -176,9 +176,9 @@ bbsink_server_archive_contents(bbsink *sink, size_t len) /* short write: complain appropriately */ ereport(ERROR, (errcode(ERRCODE_DISK_FULL), - errmsg("could not write file \"%s\": wrote only %d of %d bytes at offset %u", + errmsg("could not write file \"%s\": wrote only %d of %zu bytes at offset %u", FilePathName(mysink->file), - nbytes, (int) len, (unsigned) mysink->filepos), + nbytes, len, (unsigned) mysink->filepos), errhint("Check free disk space."))); } @@ -269,9 +269,9 @@ bbsink_server_manifest_contents(bbsink *sink, size_t len) /* short write: complain appropriately */ ereport(ERROR, (errcode(ERRCODE_DISK_FULL), - errmsg("could not write file \"%s\": wrote only %d of %d bytes at offset %u", + errmsg("could not write file \"%s\": wrote only %d of %zu bytes at offset %u", FilePathName(mysink->file), - nbytes, (int) len, (unsigned) mysink->filepos), + nbytes, len, (unsigned) mysink->filepos), errhint("Check free disk space."))); } diff --git a/src/backend/libpq/auth.c b/src/backend/libpq/auth.c index 5854a2433bb..a9181cde87b 100644 --- a/src/backend/libpq/auth.c +++ b/src/backend/libpq/auth.c @@ -998,8 +998,8 @@ pg_GSS_recvauth(Port *port) gbuf.length = buf.len; gbuf.value = buf.data; - elog(DEBUG4, "processing received GSS token of length %u", - (unsigned int) gbuf.length); + elog(DEBUG4, "processing received GSS token of length %zu", + gbuf.length); maj_stat = gss_accept_sec_context(&min_stat, &port->gss->ctx, @@ -1017,9 +1017,9 @@ pg_GSS_recvauth(Port *port) pfree(buf.data); elog(DEBUG5, "gss_accept_sec_context major: %u, " - "minor: %u, outlen: %u, outflags: %x", + "minor: %u, outlen: %zu, outflags: %x", maj_stat, min_stat, - (unsigned int) port->gss->outbuf.length, gflags); + port->gss->outbuf.length, gflags); CHECK_FOR_INTERRUPTS(); @@ -1034,8 +1034,8 @@ pg_GSS_recvauth(Port *port) /* * Negotiation generated data to be sent to the client. */ - elog(DEBUG4, "sending GSS response token of length %u", - (unsigned int) port->gss->outbuf.length); + elog(DEBUG4, "sending GSS response token of length %zu", + port->gss->outbuf.length); sendAuthRequest(port, AUTH_REQ_GSS_CONT, port->gss->outbuf.value, port->gss->outbuf.length); diff --git a/src/backend/libpq/pqcomm.c b/src/backend/libpq/pqcomm.c index 25f739a6a17..77b62edafb7 100644 --- a/src/backend/libpq/pqcomm.c +++ b/src/backend/libpq/pqcomm.c @@ -454,9 +454,9 @@ ListenServerPort(int family, const char *hostName, unsigned short portNumber, if (strlen(unixSocketPath) >= UNIXSOCK_PATH_BUFLEN) { ereport(LOG, - (errmsg("Unix-domain socket path \"%s\" is too long (maximum %d bytes)", + (errmsg("Unix-domain socket path \"%s\" is too long (maximum %zu bytes)", unixSocketPath, - (int) (UNIXSOCK_PATH_BUFLEN - 1)))); + (UNIXSOCK_PATH_BUFLEN - 1)))); return STATUS_ERROR; } if (Lock_AF_UNIX(unixSocketDir, unixSocketPath) != STATUS_OK) diff --git a/src/backend/nodes/outfuncs.c b/src/backend/nodes/outfuncs.c index 0abca9f803b..808909537e4 100644 --- a/src/backend/nodes/outfuncs.c +++ b/src/backend/nodes/outfuncs.c @@ -354,7 +354,7 @@ outDatum(StringInfo str, Datum value, int typlen, bool typbyval) if (typbyval) { s = (char *) (&value); - appendStringInfo(str, "%u [ ", (unsigned int) length); + appendStringInfo(str, "%zu [ ", length); for (Size i = 0; i < (Size) sizeof(Datum); i++) appendStringInfo(str, "%d ", (int) (s[i])); appendStringInfoChar(str, ']'); @@ -366,7 +366,7 @@ outDatum(StringInfo str, Datum value, int typlen, bool typbyval) appendStringInfoString(str, "0 [ ]"); else { - appendStringInfo(str, "%u [ ", (unsigned int) length); + appendStringInfo(str, "%zu [ ", length); for (Size i = 0; i < length; i++) appendStringInfo(str, "%d ", (int) (s[i])); appendStringInfoChar(str, ']'); diff --git a/src/backend/storage/page/bufpage.c b/src/backend/storage/page/bufpage.c index aac6e695954..91c8e758b19 100644 --- a/src/backend/storage/page/bufpage.c +++ b/src/backend/storage/page/bufpage.c @@ -785,8 +785,8 @@ PageRepairFragmentation(Page page) if (totallen > (Size) (pd_special - pd_lower)) ereport(ERROR, (errcode(ERRCODE_DATA_CORRUPTED), - errmsg("corrupted item lengths: total %u, available space %u", - (unsigned int) totallen, pd_special - pd_lower))); + errmsg("corrupted item lengths: total %zu, available space %u", + totallen, pd_special - pd_lower))); compactify_tuples(itemidbase, nstorage, page, presorted); } @@ -1088,8 +1088,8 @@ PageIndexTupleDelete(Page page, OffsetNumber offnum) offset != MAXALIGN(offset)) ereport(ERROR, (errcode(ERRCODE_DATA_CORRUPTED), - errmsg("corrupted line pointer: offset = %u, size = %u", - offset, (unsigned int) size))); + errmsg("corrupted line pointer: offset = %u, size = %zu", + offset, size))); /* Amount of space to actually be deleted */ size = MAXALIGN(size); @@ -1229,8 +1229,8 @@ PageIndexMultiDelete(Page page, OffsetNumber *itemnos, int nitems) offset != MAXALIGN(offset)) ereport(ERROR, (errcode(ERRCODE_DATA_CORRUPTED), - errmsg("corrupted line pointer: offset = %u, size = %u", - offset, (unsigned int) size))); + errmsg("corrupted line pointer: offset = %u, size = %zu", + offset, size))); if (nextitm < nitems && offnum == itemnos[nextitm]) { @@ -1262,8 +1262,8 @@ PageIndexMultiDelete(Page page, OffsetNumber *itemnos, int nitems) if (totallen > (Size) (pd_special - pd_lower)) ereport(ERROR, (errcode(ERRCODE_DATA_CORRUPTED), - errmsg("corrupted item lengths: total %u, available space %u", - (unsigned int) totallen, pd_special - pd_lower))); + errmsg("corrupted item lengths: total %zu, available space %u", + totallen, pd_special - pd_lower))); /* * Looks good. Overwrite the line pointers with the copy, from which we've @@ -1326,8 +1326,8 @@ PageIndexTupleDeleteNoCompact(Page page, OffsetNumber offnum) offset != MAXALIGN(offset)) ereport(ERROR, (errcode(ERRCODE_DATA_CORRUPTED), - errmsg("corrupted line pointer: offset = %u, size = %u", - offset, (unsigned int) size))); + errmsg("corrupted line pointer: offset = %u, size = %zu", + offset, size))); /* Amount of space to actually be deleted */ size = MAXALIGN(size); diff --git a/src/backend/utils/adt/array_expanded.c b/src/backend/utils/adt/array_expanded.c index fc036d1eb30..23627114f57 100644 --- a/src/backend/utils/adt/array_expanded.c +++ b/src/backend/utils/adt/array_expanded.c @@ -271,8 +271,8 @@ EA_get_flat_size(ExpandedObjectHeader *eohptr) if (!AllocSizeIsValid(nbytes)) ereport(ERROR, (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED), - errmsg("array size exceeds the maximum allowed (%d)", - (int) MaxAllocSize))); + errmsg("array size exceeds the maximum allowed (%zu)", + MaxAllocSize))); } if (dnulls) diff --git a/src/backend/utils/adt/arrayfuncs.c b/src/backend/utils/adt/arrayfuncs.c index cc76bdde723..24e5b2adea1 100644 --- a/src/backend/utils/adt/arrayfuncs.c +++ b/src/backend/utils/adt/arrayfuncs.c @@ -333,8 +333,8 @@ array_in(PG_FUNCTION_ARGS) if (!AllocSizeIsValid(nbytes)) ereturn(escontext, (Datum) 0, (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED), - errmsg("array size exceeds the maximum allowed (%d)", - (int) MaxAllocSize))); + errmsg("array size exceeds the maximum allowed (%zu)", + MaxAllocSize))); } } if (hasnulls) @@ -492,8 +492,8 @@ ReadArrayDimensions(char **srcptr, int *ndim_p, int *dim, int *lBound, pg_add_s32_overflow(ub, 1, &ub)) ereturn(escontext, false, (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED), - errmsg("array size exceeds the maximum allowed (%d)", - (int) MaxArraySize))); + errmsg("array size exceeds the maximum allowed (%zu)", + MaxArraySize))); dim[ndim] = ub; ndim++; @@ -725,8 +725,8 @@ ReadArrayStr(char **srcptr, if (maxitems >= MaxArraySize) ereturn(escontext, false, (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED), - errmsg("array size exceeds the maximum allowed (%d)", - (int) MaxArraySize))); + errmsg("array size exceeds the maximum allowed (%zu)", + MaxArraySize))); maxitems = Min(maxitems * 2, MaxArraySize); values = repalloc_array(values, Datum, maxitems); nulls = repalloc_array(nulls, bool, maxitems); @@ -1531,8 +1531,8 @@ ReadArrayBinary(StringInfo buf, if (!AllocSizeIsValid(totbytes)) ereport(ERROR, (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED), - errmsg("array size exceeds the maximum allowed (%d)", - (int) MaxAllocSize))); + errmsg("array size exceeds the maximum allowed (%zu)", + MaxAllocSize))); } } *hasnulls = hasnull; @@ -2339,8 +2339,8 @@ array_set_element(Datum arraydatum, pg_add_s32_overflow(dim[0], addedbefore, &dim[0])) ereport(ERROR, (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED), - errmsg("array size exceeds the maximum allowed (%d)", - (int) MaxArraySize))); + errmsg("array size exceeds the maximum allowed (%zu)", + MaxArraySize))); lb[0] = indx[0]; if (addedbefore > 1) newhasnulls = true; /* will insert nulls */ @@ -2354,8 +2354,8 @@ array_set_element(Datum arraydatum, pg_add_s32_overflow(dim[0], addedafter, &dim[0])) ereport(ERROR, (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED), - errmsg("array size exceeds the maximum allowed (%d)", - (int) MaxArraySize))); + errmsg("array size exceeds the maximum allowed (%zu)", + MaxArraySize))); if (addedafter > 1) newhasnulls = true; /* will insert nulls */ } @@ -2616,8 +2616,8 @@ array_set_element_expanded(Datum arraydatum, pg_add_s32_overflow(dim[0], addedbefore, &dim[0])) ereport(ERROR, (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED), - errmsg("array size exceeds the maximum allowed (%d)", - (int) MaxArraySize))); + errmsg("array size exceeds the maximum allowed (%zu)", + MaxArraySize))); lb[0] = indx[0]; dimschanged = true; if (addedbefore > 1) @@ -2632,8 +2632,8 @@ array_set_element_expanded(Datum arraydatum, pg_add_s32_overflow(dim[0], addedafter, &dim[0])) ereport(ERROR, (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED), - errmsg("array size exceeds the maximum allowed (%d)", - (int) MaxArraySize))); + errmsg("array size exceeds the maximum allowed (%zu)", + MaxArraySize))); dimschanged = true; if (addedafter > 1) newhasnulls = true; /* will insert nulls */ @@ -2893,8 +2893,8 @@ array_set_slice(Datum arraydatum, pg_add_s32_overflow(dim[i], 1, &dim[i])) ereport(ERROR, (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED), - errmsg("array size exceeds the maximum allowed (%d)", - (int) MaxArraySize))); + errmsg("array size exceeds the maximum allowed (%zu)", + MaxArraySize))); lb[i] = lowerIndx[i]; } @@ -2947,8 +2947,8 @@ array_set_slice(Datum arraydatum, pg_add_s32_overflow(dim[0], addedbefore, &dim[0])) ereport(ERROR, (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED), - errmsg("array size exceeds the maximum allowed (%d)", - (int) MaxArraySize))); + errmsg("array size exceeds the maximum allowed (%zu)", + MaxArraySize))); lb[0] = lowerIndx[0]; if (addedbefore > 1) newhasnulls = true; /* will insert nulls */ @@ -2962,8 +2962,8 @@ array_set_slice(Datum arraydatum, pg_add_s32_overflow(dim[0], addedafter, &dim[0])) ereport(ERROR, (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED), - errmsg("array size exceeds the maximum allowed (%d)", - (int) MaxArraySize))); + errmsg("array size exceeds the maximum allowed (%zu)", + MaxArraySize))); if (addedafter > 1) newhasnulls = true; /* will insert nulls */ } @@ -3303,8 +3303,8 @@ array_map(Datum arrayd, if (!AllocSizeIsValid(nbytes)) ereport(ERROR, (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED), - errmsg("array size exceeds the maximum allowed (%d)", - (int) MaxAllocSize))); + errmsg("array size exceeds the maximum allowed (%zu)", + MaxAllocSize))); } } @@ -3543,8 +3543,8 @@ construct_md_array(Datum *elems, if (!AllocSizeIsValid(nbytes)) ereport(ERROR, (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED), - errmsg("array size exceeds the maximum allowed (%d)", - (int) MaxAllocSize))); + errmsg("array size exceeds the maximum allowed (%zu)", + MaxAllocSize))); } /* Allocate and initialize result array */ @@ -5375,8 +5375,8 @@ accumArrayResult(ArrayBuildState *astate, if (!AllocSizeIsValid(astate->alen * sizeof(Datum))) ereport(ERROR, (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED), - errmsg("array size exceeds the maximum allowed (%d)", - (int) MaxAllocSize))); + errmsg("array size exceeds the maximum allowed (%zu)", + MaxAllocSize))); astate->dvalues = (Datum *) repalloc(astate->dvalues, astate->alen * sizeof(Datum)); astate->dnulls = (bool *) @@ -6214,8 +6214,8 @@ array_fill_internal(ArrayType *dims, ArrayType *lbs, !AllocSizeIsValid(totbytes)) ereport(ERROR, (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED), - errmsg("array size exceeds the maximum allowed (%d)", - (int) MaxAllocSize))); + errmsg("array size exceeds the maximum allowed (%zu)", + MaxAllocSize))); /* * This addition can't overflow, but it might cause us to go past @@ -6558,8 +6558,8 @@ array_replace_internal(ArrayType *array, if (!AllocSizeIsValid(nbytes)) ereport(ERROR, (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED), - errmsg("array size exceeds the maximum allowed (%d)", - (int) MaxAllocSize))); + errmsg("array size exceeds the maximum allowed (%zu)", + MaxAllocSize))); } nresult++; } diff --git a/src/backend/utils/adt/varchar.c b/src/backend/utils/adt/varchar.c index 3f40c9da1a0..39fc27e1f11 100644 --- a/src/backend/utils/adt/varchar.c +++ b/src/backend/utils/adt/varchar.c @@ -158,8 +158,8 @@ bpchar_input(const char *s, size_t len, int32 atttypmod, Node *escontext) if (s[j] != ' ') ereturn(escontext, NULL, (errcode(ERRCODE_STRING_DATA_RIGHT_TRUNCATION), - errmsg("value too long for type character(%d)", - (int) maxlen))); + errmsg("value too long for type character(%zu)", + maxlen))); } /* @@ -472,8 +472,8 @@ varchar_input(const char *s, size_t len, int32 atttypmod, Node *escontext) if (s[j] != ' ') ereturn(escontext, NULL, (errcode(ERRCODE_STRING_DATA_RIGHT_TRUNCATION), - errmsg("value too long for type character varying(%d)", - (int) maxlen))); + errmsg("value too long for type character varying(%zu)", + maxlen))); } len = mbmaxlen; diff --git a/src/backend/utils/misc/guc.c b/src/backend/utils/misc/guc.c index c6484aea087..d495ff15945 100644 --- a/src/backend/utils/misc/guc.c +++ b/src/backend/utils/misc/guc.c @@ -1504,7 +1504,7 @@ InitializeGUCOptionsFromEnvironment(void) new_limit = 2048; source = PGC_S_DYNAMIC_DEFAULT; } - snprintf(limbuf, sizeof(limbuf), "%d", (int) new_limit); + snprintf(limbuf, sizeof(limbuf), "%zd", new_limit); SetConfigOption("max_stack_depth", limbuf, PGC_POSTMASTER, source); } -- cgit v1.2.3