1
0
mirror of https://github.com/postgres/postgres.git synced 2025-12-10 14:22:35 +03:00

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.

Reviewed-by: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
Discussion: https://www.postgresql.org/message-id/flat/07fa29f9-42d7-4aac-8834-197918cbbab6%40eisentraut.org
This commit is contained in:
Peter Eisentraut
2025-12-09 06:58:39 +01:00
parent 907caf5c39
commit 2268f2b91b
19 changed files with 88 additions and 89 deletions

View File

@@ -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));
}
}

View File

@@ -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');

View File

@@ -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++)
{

View File

@@ -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);

View File

@@ -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;
}

View File

@@ -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)
{

View File

@@ -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:

View File

@@ -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;
}

View File

@@ -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)++;

View File

@@ -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;
}
}

View File

@@ -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))
{

View File

@@ -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 */

View File

@@ -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.

View File

@@ -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
{

View File

@@ -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,

View File

@@ -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);
}

View File

@@ -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;
}

View File

@@ -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

View File

@@ -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);
}