Attached are some patches to remove unnecessary casts in printf format arguments. Many of these are apparently left over from before use of %zu/%zd and PRIu64/PRId64 were possible. Additionally, there are a few where the cast just cast to the type the input already had, or it just uselessly cast to a different type instead of using the right format argument.
From aa5a44f3c71ae867ce0fb2bca3fce6ce24321b02 Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <[email protected]>
Date: Thu, 4 Dec 2025 12:58:05 +0100
Subject: [PATCH 1/3] Remove unnecessary casts in printf format arguments
 (%zu/%zd)

Many of these are probably left over from before use of %zu/%zd was
portable.
---
 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 +-
 src/bin/pg_combinebackup/write_manifest.c |  4 +-
 src/bin/pg_dump/pg_backup_archiver.c      | 10 ++--
 src/bin/pg_rewind/libpq_source.c          |  2 +-
 src/bin/pg_rewind/local_source.c          |  4 +-
 src/bin/pg_rewind/pg_rewind.c             |  4 +-
 src/interfaces/libpq/fe-connect.c         |  4 +-
 src/interfaces/libpq/fe-misc.c            |  8 +--
 19 files changed, 86 insertions(+), 92 deletions(-)

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 5a1b8483bea..639ba92f75d 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);
                }
diff --git a/src/bin/pg_combinebackup/write_manifest.c 
b/src/bin/pg_combinebackup/write_manifest.c
index 819a3fd0b7a..c845175a82c 100644
--- a/src/bin/pg_combinebackup/write_manifest.c
+++ b/src/bin/pg_combinebackup/write_manifest.c
@@ -259,8 +259,8 @@ flush_manifest(manifest_writer *mwriter)
                        if (wb < 0)
                                pg_fatal("could not write file \"%s\": %m", 
mwriter->pathname);
                        else
-                               pg_fatal("could not write file \"%s\": wrote %d 
of %d",
-                                                mwriter->pathname, (int) wb, 
mwriter->buf.len);
+                               pg_fatal("could not write file \"%s\": wrote 
%zd of %d",
+                                                mwriter->pathname, wb, 
mwriter->buf.len);
                }
 
                if (mwriter->still_checksumming &&
diff --git a/src/bin/pg_dump/pg_backup_archiver.c 
b/src/bin/pg_dump/pg_backup_archiver.c
index c84b017f21b..4a63f7392ae 100644
--- a/src/bin/pg_dump/pg_backup_archiver.c
+++ b/src/bin/pg_dump/pg_backup_archiver.c
@@ -1346,8 +1346,8 @@ PrintTOCSummary(Archive *AHX)
        ahprintf(AH, ";     Dump Version: %d.%d-%d\n",
                         ARCHIVE_MAJOR(AH->version), 
ARCHIVE_MINOR(AH->version), ARCHIVE_REV(AH->version));
        ahprintf(AH, ";     Format: %s\n", fmtName);
-       ahprintf(AH, ";     Integer: %d bytes\n", (int) AH->intSize);
-       ahprintf(AH, ";     Offset: %d bytes\n", (int) AH->offSize);
+       ahprintf(AH, ";     Integer: %zu bytes\n", AH->intSize);
+       ahprintf(AH, ";     Offset: %zu bytes\n", AH->offSize);
        if (AH->archiveRemoteVersion)
                ahprintf(AH, ";     Dumped from database version: %s\n",
                                 AH->archiveRemoteVersion);
@@ -2307,8 +2307,7 @@ _discoverArchiveFormat(ArchiveHandle *AH)
                if (ferror(fh))
                        pg_fatal("could not read input file: %m");
                else
-                       pg_fatal("input file is too short (read %lu, expected 
5)",
-                                        (unsigned long) cnt);
+                       pg_fatal("input file is too short (read %zu, expected 
5)", cnt);
        }
 
        /* Save it, just in case we need it later */
@@ -4185,8 +4184,7 @@ ReadHead(ArchiveHandle *AH)
 
        AH->intSize = AH->ReadBytePtr(AH);
        if (AH->intSize > 32)
-               pg_fatal("sanity check on integer size (%lu) failed",
-                                (unsigned long) AH->intSize);
+               pg_fatal("sanity check on integer size (%zu) failed", 
AH->intSize);
 
        if (AH->intSize > sizeof(int))
                pg_log_warning("archive was made on a machine with larger 
integers, some operations might fail");
diff --git a/src/bin/pg_rewind/libpq_source.c b/src/bin/pg_rewind/libpq_source.c
index e80edb7077e..575585357b7 100644
--- a/src/bin/pg_rewind/libpq_source.c
+++ b/src/bin/pg_rewind/libpq_source.c
@@ -459,7 +459,7 @@ process_queued_fetch_requests(libpq_source *src)
 
                appendArrayEscapedString(&src->paths, rq->path);
                appendStringInfo(&src->offsets, INT64_FORMAT, (int64) 
rq->offset);
-               appendStringInfo(&src->lengths, INT64_FORMAT, (int64) 
rq->length);
+               appendStringInfo(&src->lengths, "%zu", rq->length);
        }
        appendStringInfoChar(&src->paths, '}');
        appendStringInfoChar(&src->offsets, '}');
diff --git a/src/bin/pg_rewind/local_source.c b/src/bin/pg_rewind/local_source.c
index 5a6e805c158..8db1a8c44aa 100644
--- a/src/bin/pg_rewind/local_source.c
+++ b/src/bin/pg_rewind/local_source.c
@@ -112,8 +112,8 @@ local_queue_fetch_file(rewind_source *source, const char 
*path, size_t len)
         * check that the size of the file matches our earlier expectation.
         */
        if (written_len != len)
-               pg_fatal("size of source file \"%s\" changed concurrently: %d 
bytes expected, %d copied",
-                                srcpath, (int) len, (int) written_len);
+               pg_fatal("size of source file \"%s\" changed concurrently: %zu 
bytes expected, %zu copied",
+                                srcpath, len, written_len);
 
        if (close(srcfd) != 0)
                pg_fatal("could not close file \"%s\": %m", srcpath);
diff --git a/src/bin/pg_rewind/pg_rewind.c b/src/bin/pg_rewind/pg_rewind.c
index e9364d04f76..7837e01d83d 100644
--- a/src/bin/pg_rewind/pg_rewind.c
+++ b/src/bin/pg_rewind/pg_rewind.c
@@ -1035,8 +1035,8 @@ digestControlFile(ControlFileData *ControlFile, const 
char *content,
                                  size_t size)
 {
        if (size != PG_CONTROL_FILE_SIZE)
-               pg_fatal("unexpected control file size %d, expected %d",
-                                (int) size, PG_CONTROL_FILE_SIZE);
+               pg_fatal("unexpected control file size %zu, expected %d",
+                                size, PG_CONTROL_FILE_SIZE);
 
        memcpy(ControlFile, content, sizeof(ControlFileData));
 
diff --git a/src/interfaces/libpq/fe-connect.c 
b/src/interfaces/libpq/fe-connect.c
index c3a2448dce5..03eeb3dcdb5 100644
--- a/src/interfaces/libpq/fe-connect.c
+++ b/src/interfaces/libpq/fe-connect.c
@@ -3094,9 +3094,9 @@ PQconnectPoll(PGconn *conn)
                                UNIXSOCK_PATH(portstr, thisport, ch->host);
                                if (strlen(portstr) >= UNIXSOCK_PATH_BUFLEN)
                                {
-                                       libpq_append_conn_error(conn, 
"Unix-domain socket path \"%s\" is too long (maximum %d bytes)",
+                                       libpq_append_conn_error(conn, 
"Unix-domain socket path \"%s\" is too long (maximum %zu bytes)",
                                                                                
        portstr,
-                                                                               
        (int) (UNIXSOCK_PATH_BUFLEN - 1));
+                                                                               
        (UNIXSOCK_PATH_BUFLEN - 1));
                                        goto keep_going;
                                }
 
diff --git a/src/interfaces/libpq/fe-misc.c b/src/interfaces/libpq/fe-misc.c
index dca44fdc5d2..39cf42538de 100644
--- a/src/interfaces/libpq/fe-misc.c
+++ b/src/interfaces/libpq/fe-misc.c
@@ -236,8 +236,8 @@ pqGetInt(int *result, size_t bytes, PGconn *conn)
                        break;
                default:
                        pqInternalNotice(&conn->noticeHooks,
-                                                        "integer of size %lu 
not supported by pqGetInt",
-                                                        (unsigned long) bytes);
+                                                        "integer of size %zu 
not supported by pqGetInt",
+                                                        bytes);
                        return EOF;
        }
 
@@ -269,8 +269,8 @@ pqPutInt(int value, size_t bytes, PGconn *conn)
                        break;
                default:
                        pqInternalNotice(&conn->noticeHooks,
-                                                        "integer of size %lu 
not supported by pqPutInt",
-                                                        (unsigned long) bytes);
+                                                        "integer of size %zu 
not supported by pqPutInt",
+                                                        bytes);
                        return EOF;
        }
 
-- 
2.52.0

From 3df7005b6fdd213273eeccbfecf7650b25012e6c Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <[email protected]>
Date: Thu, 4 Dec 2025 12:58:05 +0100
Subject: [PATCH 2/3] Clean up int64-related format strings

Remove some gratuitous uses of INT64_FORMAT.  Make use of
PRIu64/PRId64 were appropriate, remove unnecessary casts.
---
 contrib/isn/isn.c                | 26 ++++----------------------
 contrib/isn/isn.h                |  2 --
 contrib/pageinspect/btreefuncs.c | 11 +++++------
 src/backend/backup/basebackup.c  |  4 ++--
 src/bin/pg_rewind/pg_rewind.c    |  6 +++---
 5 files changed, 14 insertions(+), 35 deletions(-)

diff --git a/contrib/isn/isn.c b/contrib/isn/isn.c
index 1880c91844e..3caa3af8b4c 100644
--- a/contrib/isn/isn.c
+++ b/contrib/isn/isn.c
@@ -423,19 +423,10 @@ ean2isn(ean13 ean, bool errorOK, ean13 *result, enum 
isn_type accept)
 
 eantoobig:
        if (!errorOK)
-       {
-               char            eanbuf[64];
-
-               /*
-                * Format the number separately to keep the machine-dependent 
format
-                * code out of the translatable message text
-                */
-               snprintf(eanbuf, sizeof(eanbuf), EAN13_FORMAT, ean);
                ereport(ERROR,
                                (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
-                                errmsg("value \"%s\" is out of range for %s 
type",
-                                               eanbuf, isn_names[type])));
-       }
+                                errmsg("value \"%" PRIu64 "\" is out of range 
for %s type",
+                                               ean, isn_names[type])));
        return false;
 }
 
@@ -660,19 +651,10 @@ ean2string(ean13 ean, bool errorOK, char *result, bool 
shortType)
 
 eantoobig:
        if (!errorOK)
-       {
-               char            eanbuf[64];
-
-               /*
-                * Format the number separately to keep the machine-dependent 
format
-                * code out of the translatable message text
-                */
-               snprintf(eanbuf, sizeof(eanbuf), EAN13_FORMAT, ean);
                ereport(ERROR,
                                (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
-                                errmsg("value \"%s\" is out of range for %s 
type",
-                                               eanbuf, isn_names[type])));
-       }
+                                errmsg("value \"%" PRIu64 "\" is out of range 
for %s type",
+                                               ean, isn_names[type])));
        return false;
 }
 
diff --git a/contrib/isn/isn.h b/contrib/isn/isn.h
index 399896ad417..4551d7828fb 100644
--- a/contrib/isn/isn.h
+++ b/contrib/isn/isn.h
@@ -24,8 +24,6 @@
  */
 typedef uint64 ean13;
 
-#define EAN13_FORMAT UINT64_FORMAT
-
 #define PG_GETARG_EAN13(n) PG_GETARG_INT64(n)
 #define PG_RETURN_EAN13(x) PG_RETURN_INT64(x)
 
diff --git a/contrib/pageinspect/btreefuncs.c b/contrib/pageinspect/btreefuncs.c
index 2e67c9adf5a..0b95a376a36 100644
--- a/contrib/pageinspect/btreefuncs.c
+++ b/contrib/pageinspect/btreefuncs.c
@@ -901,10 +901,10 @@ bt_metap(PG_FUNCTION_ARGS)
        j = 0;
        values[j++] = psprintf("%d", metad->btm_magic);
        values[j++] = psprintf("%d", metad->btm_version);
-       values[j++] = psprintf(INT64_FORMAT, (int64) metad->btm_root);
-       values[j++] = psprintf(INT64_FORMAT, (int64) metad->btm_level);
-       values[j++] = psprintf(INT64_FORMAT, (int64) metad->btm_fastroot);
-       values[j++] = psprintf(INT64_FORMAT, (int64) metad->btm_fastlevel);
+       values[j++] = psprintf("%u", metad->btm_root);
+       values[j++] = psprintf("%u", metad->btm_level);
+       values[j++] = psprintf("%u", metad->btm_fastroot);
+       values[j++] = psprintf("%u", metad->btm_fastlevel);
 
        /*
         * Get values of extended metadata if available, use default values
@@ -914,8 +914,7 @@ bt_metap(PG_FUNCTION_ARGS)
         */
        if (metad->btm_version >= BTREE_NOVAC_VERSION)
        {
-               values[j++] = psprintf(INT64_FORMAT,
-                                                          (int64) 
metad->btm_last_cleanup_num_delpages);
+               values[j++] = psprintf("%u", 
metad->btm_last_cleanup_num_delpages);
                values[j++] = psprintf("%f", 
metad->btm_last_cleanup_num_heap_tuples);
                values[j++] = metad->btm_allequalimage ? "t" : "f";
        }
diff --git a/src/backend/backup/basebackup.c b/src/backend/backup/basebackup.c
index 2be4e069816..1fbc9af72ba 100644
--- a/src/backend/backup/basebackup.c
+++ b/src/backend/backup/basebackup.c
@@ -808,8 +808,8 @@ parse_basebackup_options(List *options, basebackup_options 
*opt)
                        if (maxrate < MAX_RATE_LOWER || maxrate > 
MAX_RATE_UPPER)
                                ereport(ERROR,
                                                
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
-                                                errmsg("%d is outside the 
valid range for parameter \"%s\" (%d .. %d)",
-                                                               (int) maxrate, 
"MAX_RATE", MAX_RATE_LOWER, MAX_RATE_UPPER)));
+                                                errmsg("%" PRId64 " is outside 
the valid range for parameter \"%s\" (%d .. %d)",
+                                                               maxrate, 
"MAX_RATE", MAX_RATE_LOWER, MAX_RATE_UPPER)));
 
                        opt->maxrate = (uint32) maxrate;
                        o_maxrate = true;
diff --git a/src/bin/pg_rewind/pg_rewind.c b/src/bin/pg_rewind/pg_rewind.c
index 7837e01d83d..06c464f6ac5 100644
--- a/src/bin/pg_rewind/pg_rewind.c
+++ b/src/bin/pg_rewind/pg_rewind.c
@@ -514,9 +514,9 @@ main(int argc, char **argv)
         */
        if (showprogress)
        {
-               pg_log_info("need to copy %lu MB (total source directory size 
is %lu MB)",
-                                       (unsigned long) (filemap->fetch_size / 
(1024 * 1024)),
-                                       (unsigned long) (filemap->total_size / 
(1024 * 1024)));
+               pg_log_info("need to copy %" PRIu64 " MB (total source 
directory size is %" PRIu64 " MB)",
+                                       filemap->fetch_size / (1024 * 1024),
+                                       filemap->total_size / (1024 * 1024));
 
                fetch_size = filemap->fetch_size;
                fetch_done = 0;
-- 
2.52.0

From 09d46d19bc43b8de658347fcde1baebf38d9a3b4 Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <[email protected]>
Date: Thu, 4 Dec 2025 12:58:05 +0100
Subject: [PATCH 3/3] Remove useless casts in format arguments

There were a number of useless casts in format arguments, either
where the input to the cast was already in the right type, or
seemingly uselessly casting between types instead of just using the
right format placeholder to begin with.
---
 contrib/amcheck/verify_heapam.c         | 72 ++++++++++++-------------
 src/backend/access/common/printtup.c    |  2 +-
 src/backend/access/rmgrdesc/gindesc.c   |  2 +-
 src/backend/access/transam/xact.c       |  6 +--
 src/backend/access/transam/xlogreader.c | 26 ++++-----
 src/backend/commands/copyfromparse.c    |  2 +-
 src/backend/commands/define.c           |  2 +-
 src/backend/libpq/auth.c                |  4 +-
 src/backend/libpq/pqcomm.c              |  6 +--
 src/backend/libpq/pqmq.c                |  2 +-
 src/backend/parser/parse_type.c         |  2 +-
 src/backend/replication/walreceiver.c   |  4 +-
 src/backend/storage/page/bufpage.c      |  4 +-
 src/backend/utils/adt/format_type.c     |  2 +-
 src/backend/utils/adt/tsvector.c        |  6 +--
 src/backend/utils/adt/xid.c             |  4 +-
 src/bin/pg_ctl/pg_ctl.c                 | 25 +++++----
 src/bin/pgbench/pgbench.c               |  4 +-
 src/bin/psql/common.c                   |  2 +-
 19 files changed, 88 insertions(+), 89 deletions(-)

diff --git a/contrib/amcheck/verify_heapam.c b/contrib/amcheck/verify_heapam.c
index 4963e9245cb..b2b30ea6f4d 100644
--- a/contrib/amcheck/verify_heapam.c
+++ b/contrib/amcheck/verify_heapam.c
@@ -526,17 +526,17 @@ verify_heapam(PG_FUNCTION_ARGS)
                                if (rdoffnum < FirstOffsetNumber)
                                {
                                        report_corruption(&ctx,
-                                                                         
psprintf("line pointer redirection to item at offset %u precedes minimum offset 
%u",
-                                                                               
           (unsigned) rdoffnum,
-                                                                               
           (unsigned) FirstOffsetNumber));
+                                                                         
psprintf("line pointer redirection to item at offset %d precedes minimum offset 
%d",
+                                                                               
           rdoffnum,
+                                                                               
           FirstOffsetNumber));
                                        continue;
                                }
                                if (rdoffnum > maxoff)
                                {
                                        report_corruption(&ctx,
-                                                                         
psprintf("line pointer redirection to item at offset %u exceeds maximum offset 
%u",
-                                                                               
           (unsigned) rdoffnum,
-                                                                               
           (unsigned) maxoff));
+                                                                         
psprintf("line pointer redirection to item at offset %d exceeds maximum offset 
%d",
+                                                                               
           rdoffnum,
+                                                                               
           maxoff));
                                        continue;
                                }
 
@@ -550,22 +550,22 @@ verify_heapam(PG_FUNCTION_ARGS)
                                if (!ItemIdIsUsed(rditem))
                                {
                                        report_corruption(&ctx,
-                                                                         
psprintf("redirected line pointer points to an unused item at offset %u",
-                                                                               
           (unsigned) rdoffnum));
+                                                                         
psprintf("redirected line pointer points to an unused item at offset %d",
+                                                                               
           rdoffnum));
                                        continue;
                                }
                                else if (ItemIdIsDead(rditem))
                                {
                                        report_corruption(&ctx,
-                                                                         
psprintf("redirected line pointer points to a dead item at offset %u",
-                                                                               
           (unsigned) rdoffnum));
+                                                                         
psprintf("redirected line pointer points to a dead item at offset %d",
+                                                                               
           rdoffnum));
                                        continue;
                                }
                                else if (ItemIdIsRedirected(rditem))
                                {
                                        report_corruption(&ctx,
-                                                                         
psprintf("redirected line pointer points to another redirected line pointer at 
offset %u",
-                                                                               
           (unsigned) rdoffnum));
+                                                                         
psprintf("redirected line pointer points to another redirected line pointer at 
offset %d",
+                                                                               
           rdoffnum));
                                        continue;
                                }
 
@@ -601,10 +601,10 @@ verify_heapam(PG_FUNCTION_ARGS)
                        if (ctx.lp_off + ctx.lp_len > BLCKSZ)
                        {
                                report_corruption(&ctx,
-                                                                 
psprintf("line pointer to page offset %u with length %u ends beyond maximum 
page offset %u",
+                                                                 
psprintf("line pointer to page offset %u with length %u ends beyond maximum 
page offset %d",
                                                                                
   ctx.lp_off,
                                                                                
   ctx.lp_len,
-                                                                               
   (unsigned) BLCKSZ));
+                                                                               
   BLCKSZ));
                                continue;
                        }
 
@@ -678,16 +678,16 @@ verify_heapam(PG_FUNCTION_ARGS)
                                if (!HeapTupleHeaderIsHeapOnly(next_htup))
                                {
                                        report_corruption(&ctx,
-                                                                         
psprintf("redirected line pointer points to a non-heap-only tuple at offset %u",
-                                                                               
           (unsigned) nextoffnum));
+                                                                         
psprintf("redirected line pointer points to a non-heap-only tuple at offset %d",
+                                                                               
           nextoffnum));
                                }
 
                                /* HOT chains should not intersect. */
                                if (predecessor[nextoffnum] != 
InvalidOffsetNumber)
                                {
                                        report_corruption(&ctx,
-                                                                         
psprintf("redirect line pointer points to offset %u, but offset %u also points 
there",
-                                                                               
           (unsigned) nextoffnum, (unsigned) predecessor[nextoffnum]));
+                                                                         
psprintf("redirect line pointer points to offset %d, but offset %d also points 
there",
+                                                                               
           nextoffnum, predecessor[nextoffnum]));
                                        continue;
                                }
 
@@ -719,8 +719,8 @@ verify_heapam(PG_FUNCTION_ARGS)
                        if (predecessor[nextoffnum] != InvalidOffsetNumber)
                        {
                                report_corruption(&ctx,
-                                                                 
psprintf("tuple points to new version at offset %u, but offset %u also points 
there",
-                                                                               
   (unsigned) nextoffnum, (unsigned) predecessor[nextoffnum]));
+                                                                 
psprintf("tuple points to new version at offset %d, but offset %d also points 
there",
+                                                                               
   nextoffnum, predecessor[nextoffnum]));
                                continue;
                        }
 
@@ -743,15 +743,15 @@ verify_heapam(PG_FUNCTION_ARGS)
                                HeapTupleHeaderIsHeapOnly(next_htup))
                        {
                                report_corruption(&ctx,
-                                                                 
psprintf("non-heap-only update produced a heap-only tuple at offset %u",
-                                                                               
   (unsigned) nextoffnum));
+                                                                 
psprintf("non-heap-only update produced a heap-only tuple at offset %d",
+                                                                               
   nextoffnum));
                        }
                        if ((curr_htup->t_infomask2 & HEAP_HOT_UPDATED) &&
                                !HeapTupleHeaderIsHeapOnly(next_htup))
                        {
                                report_corruption(&ctx,
-                                                                 
psprintf("heap-only update produced a non-heap only tuple at offset %u",
-                                                                               
   (unsigned) nextoffnum));
+                                                                 
psprintf("heap-only update produced a non-heap only tuple at offset %d",
+                                                                               
   nextoffnum));
                        }
 
                        /*
@@ -772,10 +772,10 @@ verify_heapam(PG_FUNCTION_ARGS)
                                TransactionIdIsInProgress(curr_xmin))
                        {
                                report_corruption(&ctx,
-                                                                 
psprintf("tuple with in-progress xmin %u was updated to produce a tuple at 
offset %u with committed xmin %u",
-                                                                               
   (unsigned) curr_xmin,
-                                                                               
   (unsigned) ctx.offnum,
-                                                                               
   (unsigned) next_xmin));
+                                                                 
psprintf("tuple with in-progress xmin %u was updated to produce a tuple at 
offset %d with committed xmin %u",
+                                                                               
   curr_xmin,
+                                                                               
   ctx.offnum,
+                                                                               
   next_xmin));
                        }
 
                        /*
@@ -788,16 +788,16 @@ verify_heapam(PG_FUNCTION_ARGS)
                        {
                                if (xmin_commit_status[nextoffnum] == 
XID_IN_PROGRESS)
                                        report_corruption(&ctx,
-                                                                         
psprintf("tuple with aborted xmin %u was updated to produce a tuple at offset 
%u with in-progress xmin %u",
-                                                                               
           (unsigned) curr_xmin,
-                                                                               
           (unsigned) ctx.offnum,
-                                                                               
           (unsigned) next_xmin));
+                                                                         
psprintf("tuple with aborted xmin %u was updated to produce a tuple at offset 
%d with in-progress xmin %u",
+                                                                               
           curr_xmin,
+                                                                               
           ctx.offnum,
+                                                                               
           next_xmin));
                                else if (xmin_commit_status[nextoffnum] == 
XID_COMMITTED)
                                        report_corruption(&ctx,
-                                                                         
psprintf("tuple with aborted xmin %u was updated to produce a tuple at offset 
%u with committed xmin %u",
-                                                                               
           (unsigned) curr_xmin,
-                                                                               
           (unsigned) ctx.offnum,
-                                                                               
           (unsigned) next_xmin));
+                                                                         
psprintf("tuple with aborted xmin %u was updated to produce a tuple at offset 
%d with committed xmin %u",
+                                                                               
           curr_xmin,
+                                                                               
           ctx.offnum,
+                                                                               
           next_xmin));
                        }
                }
 
diff --git a/src/backend/access/common/printtup.c 
b/src/backend/access/common/printtup.c
index 9f05e1d15bd..025fe75916f 100644
--- a/src/backend/access/common/printtup.c
+++ b/src/backend/access/common/printtup.c
@@ -431,7 +431,7 @@ printatt(unsigned attributeId,
                   value != NULL ? " = \"" : "",
                   value != NULL ? value : "",
                   value != NULL ? "\"" : "",
-                  (unsigned int) (attributeP->atttypid),
+                  attributeP->atttypid,
                   attributeP->attlen,
                   attributeP->atttypmod,
                   attributeP->attbyval ? 't' : 'f');
diff --git a/src/backend/access/rmgrdesc/gindesc.c 
b/src/backend/access/rmgrdesc/gindesc.c
index 075c4a0ae93..62e21f8c935 100644
--- a/src/backend/access/rmgrdesc/gindesc.c
+++ b/src/backend/access/rmgrdesc/gindesc.c
@@ -23,7 +23,7 @@ desc_recompress_leaf(StringInfo buf, 
ginxlogRecompressDataLeaf *insertData)
        int                     i;
        char       *walbuf = ((char *) insertData) + 
sizeof(ginxlogRecompressDataLeaf);
 
-       appendStringInfo(buf, " %d segments:", (int) insertData->nactions);
+       appendStringInfo(buf, " %d segments:", insertData->nactions);
 
        for (i = 0; i < insertData->nactions; i++)
        {
diff --git a/src/backend/access/transam/xact.c 
b/src/backend/access/transam/xact.c
index 092e197eba3..e48d4b7af6c 100644
--- a/src/backend/access/transam/xact.c
+++ b/src/backend/access/transam/xact.c
@@ -5709,9 +5709,9 @@ ShowTransactionStateRec(const char *str, TransactionState 
s)
                                                         s->name ? s->name : 
"unnamed",
                                                         
BlockStateAsString(s->blockState),
                                                         
TransStateAsString(s->state),
-                                                        (unsigned int) 
XidFromFullTransactionId(s->fullTransactionId),
-                                                        (unsigned int) 
s->subTransactionId,
-                                                        (unsigned int) 
currentCommandId,
+                                                        
XidFromFullTransactionId(s->fullTransactionId),
+                                                        s->subTransactionId,
+                                                        currentCommandId,
                                                         currentCommandIdUsed ? 
" (used)" : "",
                                                         buf.data)));
        pfree(buf.data);
diff --git a/src/backend/access/transam/xlogreader.c 
b/src/backend/access/transam/xlogreader.c
index 9cc7488e892..5e5001b2101 100644
--- a/src/backend/access/transam/xlogreader.c
+++ b/src/backend/access/transam/xlogreader.c
@@ -1797,8 +1797,8 @@ DecodeXLogRecord(XLogReaderState *state,
                        if (!blk->has_data && blk->data_len != 0)
                        {
                                report_invalid_record(state,
-                                                                         
"BKPBLOCK_HAS_DATA not set, but data length is %u at %X/%08X",
-                                                                         
(unsigned int) blk->data_len,
+                                                                         
"BKPBLOCK_HAS_DATA not set, but data length is %d at %X/%08X",
+                                                                         
blk->data_len,
                                                                          
LSN_FORMAT_ARGS(state->ReadRecPtr));
                                goto err;
                        }
@@ -1833,10 +1833,10 @@ DecodeXLogRecord(XLogReaderState *state,
                                         blk->bimg_len == BLCKSZ))
                                {
                                        report_invalid_record(state,
-                                                                               
  "BKPIMAGE_HAS_HOLE set, but hole offset %u length %u block image length %u at 
%X/%08X",
-                                                                               
  (unsigned int) blk->hole_offset,
-                                                                               
  (unsigned int) blk->hole_length,
-                                                                               
  (unsigned int) blk->bimg_len,
+                                                                               
  "BKPIMAGE_HAS_HOLE set, but hole offset %d length %d block image length %d at 
%X/%08X",
+                                                                               
  blk->hole_offset,
+                                                                               
  blk->hole_length,
+                                                                               
  blk->bimg_len,
                                                                                
  LSN_FORMAT_ARGS(state->ReadRecPtr));
                                        goto err;
                                }
@@ -1849,9 +1849,9 @@ DecodeXLogRecord(XLogReaderState *state,
                                        (blk->hole_offset != 0 || 
blk->hole_length != 0))
                                {
                                        report_invalid_record(state,
-                                                                               
  "BKPIMAGE_HAS_HOLE not set, but hole offset %u length %u at %X/%08X",
-                                                                               
  (unsigned int) blk->hole_offset,
-                                                                               
  (unsigned int) blk->hole_length,
+                                                                               
  "BKPIMAGE_HAS_HOLE not set, but hole offset %d length %d at %X/%08X",
+                                                                               
  blk->hole_offset,
+                                                                               
  blk->hole_length,
                                                                                
  LSN_FORMAT_ARGS(state->ReadRecPtr));
                                        goto err;
                                }
@@ -1863,8 +1863,8 @@ DecodeXLogRecord(XLogReaderState *state,
                                        blk->bimg_len == BLCKSZ)
                                {
                                        report_invalid_record(state,
-                                                                               
  "BKPIMAGE_COMPRESSED set, but block image length %u at %X/%08X",
-                                                                               
  (unsigned int) blk->bimg_len,
+                                                                               
  "BKPIMAGE_COMPRESSED set, but block image length %d at %X/%08X",
+                                                                               
  blk->bimg_len,
                                                                                
  LSN_FORMAT_ARGS(state->ReadRecPtr));
                                        goto err;
                                }
@@ -1878,8 +1878,8 @@ DecodeXLogRecord(XLogReaderState *state,
                                        blk->bimg_len != BLCKSZ)
                                {
                                        report_invalid_record(state,
-                                                                               
  "neither BKPIMAGE_HAS_HOLE nor BKPIMAGE_COMPRESSED set, but block image 
length is %u at %X/%08X",
-                                                                               
  (unsigned int) blk->data_len,
+                                                                               
  "neither BKPIMAGE_HAS_HOLE nor BKPIMAGE_COMPRESSED set, but block image 
length is %d at %X/%08X",
+                                                                               
  blk->data_len,
                                                                                
  LSN_FORMAT_ARGS(state->ReadRecPtr));
                                        goto err;
                                }
diff --git a/src/backend/commands/copyfromparse.c 
b/src/backend/commands/copyfromparse.c
index a09e7fbace3..62afcd8fad1 100644
--- a/src/backend/commands/copyfromparse.c
+++ b/src/backend/commands/copyfromparse.c
@@ -1136,7 +1136,7 @@ CopyFromBinaryOneRow(CopyFromState cstate, ExprContext 
*econtext, Datum *values,
                ereport(ERROR,
                                (errcode(ERRCODE_BAD_COPY_FILE_FORMAT),
                                 errmsg("row field count is %d, expected %d",
-                                               (int) fld_count, attr_count)));
+                                               fld_count, attr_count)));
 
        foreach(cur, cstate->attnumlist)
        {
diff --git a/src/backend/commands/define.c b/src/backend/commands/define.c
index 5e1b867e6f7..3e238c414f7 100644
--- a/src/backend/commands/define.c
+++ b/src/backend/commands/define.c
@@ -42,7 +42,7 @@ defGetString(DefElem *def)
        switch (nodeTag(def->arg))
        {
                case T_Integer:
-                       return psprintf("%ld", (long) intVal(def->arg));
+                       return psprintf("%d", intVal(def->arg));
                case T_Float:
                        return castNode(Float, def->arg)->fval;
                case T_Boolean:
diff --git a/src/backend/libpq/auth.c b/src/backend/libpq/auth.c
index a9181cde87b..8045dbffe04 100644
--- a/src/backend/libpq/auth.c
+++ b/src/backend/libpq/auth.c
@@ -2240,8 +2240,8 @@ InitializeLDAPConnection(Port *port, LDAP **ldap)
        if (!*ldap)
        {
                ereport(LOG,
-                               (errmsg("could not initialize LDAP: error code 
%d",
-                                               (int) LdapGetLastError())));
+                               (errmsg("could not initialize LDAP: error code 
%lu",
+                                               LdapGetLastError())));
 
                return STATUS_ERROR;
        }
diff --git a/src/backend/libpq/pqcomm.c b/src/backend/libpq/pqcomm.c
index 77b62edafb7..40b180644eb 100644
--- a/src/backend/libpq/pqcomm.c
+++ b/src/backend/libpq/pqcomm.c
@@ -618,10 +618,10 @@ ListenServerPort(int family, const char *hostName, 
unsigned short portNumber,
                                         saved_errno == EADDRINUSE ?
                                         (addr->ai_family == AF_UNIX ?
                                          errhint("Is another postmaster 
already running on port %d?",
-                                                         (int) portNumber) :
+                                                         portNumber) :
                                          errhint("Is another postmaster 
already running on port %d?"
                                                          " If not, wait a few 
seconds and retry.",
-                                                         (int) portNumber)) : 
0));
+                                                         portNumber)) : 0));
                        closesocket(fd);
                        continue;
                }
@@ -662,7 +662,7 @@ ListenServerPort(int family, const char *hostName, unsigned 
short portNumber,
                        ereport(LOG,
                        /* translator: first %s is IPv4 or IPv6 */
                                        (errmsg("listening on %s address 
\"%s\", port %d",
-                                                       familyDesc, addrDesc, 
(int) portNumber)));
+                                                       familyDesc, addrDesc, 
portNumber)));
 
                ListenSockets[*NumListenSockets] = fd;
                (*NumListenSockets)++;
diff --git a/src/backend/libpq/pqmq.c b/src/backend/libpq/pqmq.c
index 5f39949a367..2b75de0ddef 100644
--- a/src/backend/libpq/pqmq.c
+++ b/src/backend/libpq/pqmq.c
@@ -329,7 +329,7 @@ pq_parse_errornotice(StringInfo msg, ErrorData *edata)
                                edata->funcname = pstrdup(value);
                                break;
                        default:
-                               elog(ERROR, "unrecognized error field code: 
%d", (int) code);
+                               elog(ERROR, "unrecognized error field code: 
%d", code);
                                break;
                }
        }
diff --git a/src/backend/parser/parse_type.c b/src/backend/parser/parse_type.c
index 7713bdc6af0..e07d65fc25b 100644
--- a/src/backend/parser/parse_type.c
+++ b/src/backend/parser/parse_type.c
@@ -382,7 +382,7 @@ typenameTypeMod(ParseState *pstate, const TypeName 
*typeName, Type typ)
 
                        if (IsA(&ac->val, Integer))
                        {
-                               cstr = psprintf("%ld", (long) intVal(&ac->val));
+                               cstr = psprintf("%d", intVal(&ac->val));
                        }
                        else if (IsA(&ac->val, Float))
                        {
diff --git a/src/backend/replication/walreceiver.c 
b/src/backend/replication/walreceiver.c
index 4217fc54e2e..3a94c9683a7 100644
--- a/src/backend/replication/walreceiver.c
+++ b/src/backend/replication/walreceiver.c
@@ -949,8 +949,8 @@ XLogWalRcvWrite(char *buf, Size nbytes, XLogRecPtr recptr, 
TimeLineID tli)
                        ereport(PANIC,
                                        (errcode_for_file_access(),
                                         errmsg("could not write to WAL segment 
%s "
-                                                       "at offset %d, length 
%lu: %m",
-                                                       xlogfname, startoff, 
(unsigned long) segbytes)));
+                                                       "at offset %d, length 
%d: %m",
+                                                       xlogfname, startoff, 
segbytes)));
                }
 
                /* Update state for write */
diff --git a/src/backend/storage/page/bufpage.c 
b/src/backend/storage/page/bufpage.c
index 91c8e758b19..05376431ef2 100644
--- a/src/backend/storage/page/bufpage.c
+++ b/src/backend/storage/page/bufpage.c
@@ -1438,8 +1438,8 @@ PageIndexTupleOverwrite(Page page, OffsetNumber offnum,
                offset != MAXALIGN(offset))
                ereport(ERROR,
                                (errcode(ERRCODE_DATA_CORRUPTED),
-                                errmsg("corrupted line pointer: offset = %u, 
size = %u",
-                                               offset, (unsigned int) 
oldsize)));
+                                errmsg("corrupted line pointer: offset = %u, 
size = %d",
+                                               offset, oldsize)));
 
        /*
         * Determine actual change in space requirement, check for page 
overflow.
diff --git a/src/backend/utils/adt/format_type.c 
b/src/backend/utils/adt/format_type.c
index 9948c26e76c..0afd1cb3563 100644
--- a/src/backend/utils/adt/format_type.c
+++ b/src/backend/utils/adt/format_type.c
@@ -378,7 +378,7 @@ printTypmod(const char *typname, int32 typmod, Oid 
typmodout)
        if (typmodout == InvalidOid)
        {
                /* Default behavior: just print the integer typmod with parens 
*/
-               res = psprintf("%s(%d)", typname, (int) typmod);
+               res = psprintf("%s(%d)", typname, typmod);
        }
        else
        {
diff --git a/src/backend/utils/adt/tsvector.c b/src/backend/utils/adt/tsvector.c
index 1fa2e3729bf..f568f1fce99 100644
--- a/src/backend/utils/adt/tsvector.c
+++ b/src/backend/utils/adt/tsvector.c
@@ -210,9 +210,9 @@ tsvectorin(PG_FUNCTION_ARGS)
                if (toklen >= MAXSTRLEN)
                        ereturn(escontext, (Datum) 0,
                                        
(errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
-                                        errmsg("word is too long (%ld bytes, 
max %ld bytes)",
-                                                       (long) toklen,
-                                                       (long) (MAXSTRLEN - 
1))));
+                                        errmsg("word is too long (%d bytes, 
max %d bytes)",
+                                                       toklen,
+                                                       MAXSTRLEN - 1)));
 
                if (cur - tmpbuf > MAXSTRPOS)
                        ereturn(escontext, (Datum) 0,
diff --git a/src/backend/utils/adt/xid.c b/src/backend/utils/adt/xid.c
index 3d0c48769cc..8a6e0390709 100644
--- a/src/backend/utils/adt/xid.c
+++ b/src/backend/utils/adt/xid.c
@@ -45,7 +45,7 @@ xidout(PG_FUNCTION_ARGS)
        TransactionId transactionId = PG_GETARG_TRANSACTIONID(0);
        char       *result = (char *) palloc(16);
 
-       snprintf(result, 16, "%lu", (unsigned long) transactionId);
+       snprintf(result, 16, "%u", transactionId);
        PG_RETURN_CSTRING(result);
 }
 
@@ -362,7 +362,7 @@ cidout(PG_FUNCTION_ARGS)
        CommandId       c = PG_GETARG_COMMANDID(0);
        char       *result = (char *) palloc(16);
 
-       snprintf(result, 16, "%lu", (unsigned long) c);
+       snprintf(result, 16, "%u", c);
        PG_RETURN_CSTRING(result);
 }
 
diff --git a/src/bin/pg_ctl/pg_ctl.c b/src/bin/pg_ctl/pg_ctl.c
index 4f666d91036..dfe7b4d2f9e 100644
--- a/src/bin/pg_ctl/pg_ctl.c
+++ b/src/bin/pg_ctl/pg_ctl.c
@@ -564,7 +564,7 @@ start_postmaster(void)
        if (!CreateRestrictedProcess(cmd, &pi, false))
        {
                write_stderr(_("%s: could not start server: error code %lu\n"),
-                                        progname, (unsigned long) 
GetLastError());
+                                        progname, GetLastError());
                exit(1);
        }
        /* Don't close command process handle here; caller must do so */
@@ -1537,7 +1537,7 @@ pgwin32_doRegister(void)
                CloseServiceHandle(hSCM);
                write_stderr(_("%s: could not register service \"%s\": error 
code %lu\n"),
                                         progname, register_servicename,
-                                        (unsigned long) GetLastError());
+                                        GetLastError());
                exit(1);
        }
        CloseServiceHandle(hService);
@@ -1567,7 +1567,7 @@ pgwin32_doUnregister(void)
                CloseServiceHandle(hSCM);
                write_stderr(_("%s: could not open service \"%s\": error code 
%lu\n"),
                                         progname, register_servicename,
-                                        (unsigned long) GetLastError());
+                                        GetLastError());
                exit(1);
        }
        if (!DeleteService(hService))
@@ -1576,7 +1576,7 @@ pgwin32_doUnregister(void)
                CloseServiceHandle(hSCM);
                write_stderr(_("%s: could not unregister service \"%s\": error 
code %lu\n"),
                                         progname, register_servicename,
-                                        (unsigned long) GetLastError());
+                                        GetLastError());
                exit(1);
        }
        CloseServiceHandle(hService);
@@ -1725,7 +1725,7 @@ pgwin32_doRunAsService(void)
        {
                write_stderr(_("%s: could not start service \"%s\": error code 
%lu\n"),
                                         progname, register_servicename,
-                                        (unsigned long) GetLastError());
+                                        GetLastError());
                exit(1);
        }
 }
@@ -1797,7 +1797,7 @@ CreateRestrictedProcess(char *cmd, PROCESS_INFORMATION 
*processInfo, bool as_ser
                 * it doesn't cast DWORD before printing.
                 */
                write_stderr(_("%s: could not open process token: error code 
%lu\n"),
-                                        progname, (unsigned long) 
GetLastError());
+                                        progname, GetLastError());
                return 0;
        }
 
@@ -1811,7 +1811,7 @@ CreateRestrictedProcess(char *cmd, PROCESS_INFORMATION 
*processInfo, bool as_ser
                                                                  0, 
&dropSids[1].Sid))
        {
                write_stderr(_("%s: could not allocate SIDs: error code %lu\n"),
-                                        progname, (unsigned long) 
GetLastError());
+                                        progname, GetLastError());
                return 0;
        }
 
@@ -1837,7 +1837,7 @@ CreateRestrictedProcess(char *cmd, PROCESS_INFORMATION 
*processInfo, bool as_ser
        if (!b)
        {
                write_stderr(_("%s: could not create restricted token: error 
code %lu\n"),
-                                        progname, (unsigned long) 
GetLastError());
+                                        progname, GetLastError());
                return 0;
        }
 
@@ -1856,8 +1856,7 @@ CreateRestrictedProcess(char *cmd, PROCESS_INFORMATION 
*processInfo, bool as_ser
                        HANDLE          job;
                        char            jobname[128];
 
-                       sprintf(jobname, "PostgreSQL_%lu",
-                                       (unsigned long) 
processInfo->dwProcessId);
+                       sprintf(jobname, "PostgreSQL_%lu", 
processInfo->dwProcessId);
 
                        job = CreateJobObject(NULL, jobname);
                        if (job)
@@ -1919,7 +1918,7 @@ GetPrivilegesToDelete(HANDLE hToken)
                !LookupPrivilegeValue(NULL, SE_CHANGE_NOTIFY_NAME, 
&luidChangeNotify))
        {
                write_stderr(_("%s: could not get LUIDs for privileges: error 
code %lu\n"),
-                                        progname, (unsigned long) 
GetLastError());
+                                        progname, GetLastError());
                return NULL;
        }
 
@@ -1927,7 +1926,7 @@ GetPrivilegesToDelete(HANDLE hToken)
                GetLastError() != ERROR_INSUFFICIENT_BUFFER)
        {
                write_stderr(_("%s: could not get token information: error code 
%lu\n"),
-                                        progname, (unsigned long) 
GetLastError());
+                                        progname, GetLastError());
                return NULL;
        }
 
@@ -1942,7 +1941,7 @@ GetPrivilegesToDelete(HANDLE hToken)
        if (!GetTokenInformation(hToken, TokenPrivileges, tokenPrivs, length, 
&length))
        {
                write_stderr(_("%s: could not get token information: error code 
%lu\n"),
-                                        progname, (unsigned long) 
GetLastError());
+                                        progname, GetLastError());
                free(tokenPrivs);
                return NULL;
        }
diff --git a/src/bin/pgbench/pgbench.c b/src/bin/pgbench/pgbench.c
index 68774a59efd..188f24df7a6 100644
--- a/src/bin/pgbench/pgbench.c
+++ b/src/bin/pgbench/pgbench.c
@@ -6274,8 +6274,8 @@ parseScriptWeight(const char *option, char **script)
                if (errno != 0 || badp == sep + 1 || *badp != '\0')
                        pg_fatal("invalid weight specification: %s", sep);
                if (wtmp > INT_MAX || wtmp < 0)
-                       pg_fatal("weight specification out of range (0 .. %d): 
%lld",
-                                        INT_MAX, (long long) wtmp);
+                       pg_fatal("weight specification out of range (0 .. %d): 
%ld",
+                                        INT_MAX, wtmp);
                weight = wtmp;
        }
        else
diff --git a/src/bin/psql/common.c b/src/bin/psql/common.c
index cd329ade12b..1a28ba6c02b 100644
--- a/src/bin/psql/common.c
+++ b/src/bin/psql/common.c
@@ -1021,7 +1021,7 @@ PrintQueryStatus(PGresult *result, FILE *printQueryFout)
        if (pset.logfile)
                fprintf(pset.logfile, "%s\n", cmdstatus);
 
-       snprintf(buf, sizeof(buf), "%u", (unsigned int) PQoidValue(result));
+       snprintf(buf, sizeof(buf), "%u", PQoidValue(result));
        SetVariable(pset.vars, "LASTOID", buf);
 }
 
-- 
2.52.0

Reply via email to