Hi,
On Mon, Nov 24, 2025 at 12:43:28PM -0600, Nathan Bossart wrote:
> On Mon, Nov 24, 2025 at 10:26:32AM +0000, Bertrand Drouvot wrote:
> > This is the same kind of idea as 7f798aca1d5 and ef8fe693606, as their
> > presence
> > could cause risks of hiding actual type mismatches in the future or silently
> > discarding qualifiers. I think that it also improves readability.
>
> Seems reasonable to me.
Thanks for looking at it!
> > Note that it generated more that what is in the attached. I chose not to
> > remove
> > some of them (mainly arithmetic ones) to keep the patch focused on what
> > matters
> > here.
>
> Can you give an example of what you are talking about here?
Things like:
A)
- int k = (int) (targrows * sampler_random_fract(&rstate.randstate));
+ int k = (targrows * sampler_random_fract(&rstate.randstate));
That's a valid cast removal but I'm not sure about the removal added value here.
B)
- sign = (BITVECP) (((char *) sign) + 1);
+ sign = ((sign) + 1);
BITVECP is "typedef char *BITVECP; So that's a valid cast removal but I decided
to keep it for semantic reason.
Same as:
@@ -2277,7 +2277,7 @@ printTrgmColor(StringInfo buf, TrgmColor co)
else if (co == COLOR_BLANK)
appendStringInfoChar(buf, 'b');
else
- appendStringInfo(buf, "%d", (int) co);
+ appendStringInfo(buf, "%d", co);
where TrgmColor is "typedef int TrgmColor;"
C)
- if (((unsigned char *) base)[i] != 0xff)
+ if ((base)[i] != 0xff)
because not safe.
See attached the full list that I decided not to include.
Do you think we should add some of them in the patch? (maybe the ones in
nbtcompare.c for example)
Regards,
--
Bertrand Drouvot
PostgreSQL Contributors Team
RDS Open Source Databases
Amazon Web Services: https://aws.amazon.com
diff --git a/contrib/file_fdw/file_fdw.c b/contrib/file_fdw/file_fdw.c
index 70564a68b13..50d65418ee8 100644
--- a/contrib/file_fdw/file_fdw.c
+++ b/contrib/file_fdw/file_fdw.c
@@ -1294,7 +1294,7 @@ file_acquire_sample_rows(Relation onerel, int elevel,
* Found a suitable tuple, so save it,
replacing one old tuple
* at random
*/
- int k = (int) (targrows *
sampler_random_fract(&rstate.randstate));
+ int k = (targrows *
sampler_random_fract(&rstate.randstate));
Assert(k >= 0 && k < targrows);
heap_freetuple(rows[k]);
diff --git a/contrib/hstore/hstore_gist.c b/contrib/hstore/hstore_gist.c
index 69515dc3d3f..5dc065bcc40 100644
--- a/contrib/hstore/hstore_gist.c
+++ b/contrib/hstore/hstore_gist.c
@@ -37,7 +37,7 @@ typedef char *BITVECP;
for (i = 0; i < SIGLENBIT(siglen); i++)
/* beware of multiple evaluation of arguments to these macros! */
-#define GETBYTE(x,i) ( *( (BITVECP)(x) + (int)( (i) / BITBYTE ) ) )
+#define GETBYTE(x,i) ( *( (BITVECP)(x) + ( (i) / BITBYTE ) ) )
#define GETBITBYTE(x,i) ( (*((char*)(x)) >> (i)) & 0x01 )
#define CLRBIT(x,i) GETBYTE(x,i) &= ~( 0x01 << ( (i) % BITBYTE ) )
#define SETBIT(x,i) GETBYTE(x,i) |= ( 0x01 << ( (i) % BITBYTE ) )
@@ -74,7 +74,7 @@ typedef struct
#define GETENTRY(vec,pos) ((GISTTYPE *)
DatumGetPointer((vec)->vector[(pos)].key))
-#define WISH_F(a,b,c) (double)( -(double)(((a)-(b))*((a)-(b))*((a)-(b)))*(c) )
+#define WISH_F(a,b,c) ( -(double)(((a)-(b))*((a)-(b))*((a)-(b)))*(c) )
/* shorthand for calculating CRC-32 of a single chunk of data. */
static pg_crc32
@@ -258,7 +258,7 @@ sizebitvec(BITVECP sign, int siglen)
LOOPBYTE(siglen)
{
size += SUMBIT(sign);
- sign = (BITVECP) (((char *) sign) + 1);
+ sign = ((sign) + 1);
}
return size;
}
diff --git a/contrib/ltree/_ltree_gist.c b/contrib/ltree/_ltree_gist.c
index 30d516e60bc..c2d89f24dff 100644
--- a/contrib/ltree/_ltree_gist.c
+++ b/contrib/ltree/_ltree_gist.c
@@ -28,7 +28,7 @@ PG_FUNCTION_INFO_V1(_ltree_gist_options);
#define GETENTRY(vec,pos) ((ltree_gist *)
DatumGetPointer((vec)->vector[(pos)].key))
#define NEXTVAL(x) ( (ltree*)( (char*)(x) + INTALIGN( VARSIZE(x) ) ) )
-#define WISH_F(a,b,c) (double)( -(double)(((a)-(b))*((a)-(b))*((a)-(b)))*(c) )
+#define WISH_F(a,b,c) ( -(double)(((a)-(b))*((a)-(b))*((a)-(b)))*(c) )
static void
diff --git a/contrib/ltree/ltree_gist.c b/contrib/ltree/ltree_gist.c
index 932f69bff2d..ba6b46a9d5a 100644
--- a/contrib/ltree/ltree_gist.c
+++ b/contrib/ltree/ltree_gist.c
@@ -225,7 +225,7 @@ ltree_union(PG_FUNCTION_ARGS)
BITVECP sc = LTG_SIGN(cur);
LOOPBYTE(siglen)
- ((unsigned char *) base)[i] |= sc[i];
+ (base)[i] |= sc[i];
}
curtree = LTG_LNODE(cur, siglen);
@@ -242,7 +242,7 @@ ltree_union(PG_FUNCTION_ARGS)
isalltrue = true;
LOOPBYTE(siglen)
{
- if (((unsigned char *) base)[i] != 0xff)
+ if ((base)[i] != 0xff)
{
isalltrue = false;
break;
@@ -352,7 +352,7 @@ ltree_picksplit(PG_FUNCTION_ARGS)
BITVECP sc = LTG_SIGN(lu);
LOOPBYTE(siglen)
- ((unsigned char *) ls)[i] |=
sc[i];
+ (ls)[i] |= sc[i];
}
}
}
@@ -373,7 +373,7 @@ ltree_picksplit(PG_FUNCTION_ARGS)
BITVECP sc = LTG_SIGN(lu);
LOOPBYTE(siglen)
- ((unsigned char *) rs)[i] |=
sc[i];
+ (rs)[i] |= sc[i];
}
}
}
@@ -384,7 +384,7 @@ ltree_picksplit(PG_FUNCTION_ARGS)
lisat = true;
LOOPBYTE(siglen)
{
- if (((unsigned char *) ls)[i] != 0xff)
+ if ((ls)[i] != 0xff)
{
lisat = false;
break;
@@ -397,7 +397,7 @@ ltree_picksplit(PG_FUNCTION_ARGS)
risat = true;
LOOPBYTE(siglen)
{
- if (((unsigned char *) rs)[i] != 0xff)
+ if ((rs)[i] != 0xff)
{
risat = false;
break;
diff --git a/contrib/pg_trgm/trgm_gist.c b/contrib/pg_trgm/trgm_gist.c
index 5ba895217b0..a41fe269c0b 100644
--- a/contrib/pg_trgm/trgm_gist.c
+++ b/contrib/pg_trgm/trgm_gist.c
@@ -727,7 +727,7 @@ gtrgm_penalty(PG_FUNCTION_ARGS)
cache = newcache;
}
- sign = (BITVECP) cache;
+ sign = cache;
if (ISALLTRUE(origval))
*penalty = ((float) (SIGLENBIT(siglen) -
sizebitvec(sign, siglen))) / (float) (SIGLENBIT(siglen) + 1);
@@ -758,7 +758,7 @@ fillcache(CACHESIGN *item, TRGM *key, BITVECP sign, int
siglen)
memcpy(item->sign, GETSIGN(key), siglen);
}
-#define WISH_F(a,b,c) (double)( -(double)(((a)-(b))*((a)-(b))*((a)-(b)))*(c) )
+#define WISH_F(a,b,c) ( -(double)(((a)-(b))*((a)-(b))*((a)-(b)))*(c) )
typedef struct
{
OffsetNumber pos;
diff --git a/contrib/pg_trgm/trgm_regexp.c b/contrib/pg_trgm/trgm_regexp.c
index 149f9eb259c..9ab251d8878 100644
--- a/contrib/pg_trgm/trgm_regexp.c
+++ b/contrib/pg_trgm/trgm_regexp.c
@@ -2277,7 +2277,7 @@ printTrgmColor(StringInfo buf, TrgmColor co)
else if (co == COLOR_BLANK)
appendStringInfoChar(buf, 'b');
else
- appendStringInfo(buf, "%d", (int) co);
+ appendStringInfo(buf, "%d", co);
}
/*
diff --git a/contrib/postgres_fdw/postgres_fdw.c
b/contrib/postgres_fdw/postgres_fdw.c
index 06b52c65300..2ffe836867d 100644
--- a/contrib/postgres_fdw/postgres_fdw.c
+++ b/contrib/postgres_fdw/postgres_fdw.c
@@ -5334,7 +5334,7 @@ analyze_row_processor(PGresult *res, int row,
PgFdwAnalyzeState *astate)
if (astate->rowstoskip <= 0)
{
/* Choose a random reservoir element to replace. */
- pos = (int) (targrows *
sampler_random_fract(&astate->rstate.randstate));
+ pos = (targrows *
sampler_random_fract(&astate->rstate.randstate));
Assert(pos >= 0 && pos < targrows);
heap_freetuple(astate->rows[pos]);
}
diff --git a/contrib/tsm_system_rows/tsm_system_rows.c
b/contrib/tsm_system_rows/tsm_system_rows.c
index f401efa2131..1ebcd1d86d6 100644
--- a/contrib/tsm_system_rows/tsm_system_rows.c
+++ b/contrib/tsm_system_rows/tsm_system_rows.c
@@ -335,7 +335,7 @@ random_relative_prime(uint32 n, pg_prng_state *randstate)
do
{
CHECK_FOR_INTERRUPTS();
- r = (uint32) (sampler_random_fract(randstate) * n);
+ r = (sampler_random_fract(randstate) * n);
} while (r == 0 || gcd(r, n) > 1);
return r;
diff --git a/contrib/tsm_system_time/tsm_system_time.c
b/contrib/tsm_system_time/tsm_system_time.c
index c9c71d8c3af..361c92267a0 100644
--- a/contrib/tsm_system_time/tsm_system_time.c
+++ b/contrib/tsm_system_time/tsm_system_time.c
@@ -348,7 +348,7 @@ random_relative_prime(uint32 n, pg_prng_state *randstate)
do
{
CHECK_FOR_INTERRUPTS();
- r = (uint32) (sampler_random_fract(randstate) * n);
+ r = (sampler_random_fract(randstate) * n);
} while (r == 0 || gcd(r, n) > 1);
return r;
diff --git a/src/backend/access/nbtree/nbtcompare.c
b/src/backend/access/nbtree/nbtcompare.c
index 188c27b4925..bcd3b24de7f 100644
--- a/src/backend/access/nbtree/nbtcompare.c
+++ b/src/backend/access/nbtree/nbtcompare.c
@@ -545,7 +545,7 @@ char_decrement(Relation rel, Datum existing, bool
*underflow)
}
*underflow = false;
- return CharGetDatum((uint8) cexisting - 1);
+ return CharGetDatum(cexisting - 1);
}
static Datum
@@ -561,7 +561,7 @@ char_increment(Relation rel, Datum existing, bool *overflow)
}
*overflow = false;
- return CharGetDatum((uint8) cexisting + 1);
+ return CharGetDatum(cexisting + 1);
}
Datum
diff --git a/src/backend/access/spgist/spgtextproc.c
b/src/backend/access/spgist/spgtextproc.c
index 91f4ab260c2..e5796fb479d 100644
--- a/src/backend/access/spgist/spgtextproc.c
+++ b/src/backend/access/spgist/spgtextproc.c
@@ -67,7 +67,7 @@
* choosing a max prefix size of 32 bytes when BLCKSZ is configured smaller
* than default.
*/
-#define SPGIST_MAX_PREFIX_LENGTH Max((int) (BLCKSZ - 258 * 16 - 100), 32)
+#define SPGIST_MAX_PREFIX_LENGTH Max((BLCKSZ - 258 * 16 - 100), 32)
/*
* Strategy for collation aware operator on text is equal to btree strategy
diff --git a/src/backend/commands/analyze.c b/src/backend/commands/analyze.c
index 25089fae3e0..8dc7c9398bf 100644
--- a/src/backend/commands/analyze.c
+++ b/src/backend/commands/analyze.c
@@ -1287,7 +1287,7 @@ acquire_sample_rows(Relation onerel, int elevel,
* Found a suitable tuple, so save it,
replacing one old
* tuple at random
*/
- int k = (int)
(targrows * sampler_random_fract(&rstate.randstate));
+ int k = (targrows *
sampler_random_fract(&rstate.randstate));
Assert(k >= 0 && k < targrows);
heap_freetuple(rows[k]);
diff --git a/src/backend/executor/execGrouping.c
b/src/backend/executor/execGrouping.c
index 8b64a625ca5..c295dd94801 100644
--- a/src/backend/executor/execGrouping.c
+++ b/src/backend/executor/execGrouping.c
@@ -360,7 +360,7 @@ EstimateTupleHashTableSpace(double nentries,
return SIZE_MAX;
/* We don't bother estimating size of the miscellaneous overhead data */
- return (Size) (sh_space + tuples_space);
+ return (sh_space + tuples_space);
}
/*
diff --git a/src/backend/libpq/pqcomm.c b/src/backend/libpq/pqcomm.c
index 25f739a6a17..170b6b9e3c1 100644
--- a/src/backend/libpq/pqcomm.c
+++ b/src/backend/libpq/pqcomm.c
@@ -456,7 +456,7 @@ ListenServerPort(int family, const char *hostName, unsigned
short portNumber,
ereport(LOG,
(errmsg("Unix-domain socket path \"%s\"
is too long (maximum %d 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/bitmapset.c b/src/backend/nodes/bitmapset.c
index b4ecf0b0390..d6de78482c7 100644
--- a/src/backend/nodes/bitmapset.c
+++ b/src/backend/nodes/bitmapset.c
@@ -1073,13 +1073,13 @@ bms_add_range(Bitmapset *a, int lower, int upper)
*/
if (lwordnum == uwordnum)
{
- a->words[lwordnum] |= ~(bitmapword) (((bitmapword) 1 <<
lbitnum) - 1)
+ a->words[lwordnum] |= ~(((bitmapword) 1 << lbitnum) - 1)
& (~(bitmapword) 0) >> ushiftbits;
}
else
{
/* turn on lbitnum and all bits left of it */
- a->words[wordnum++] |= ~(bitmapword) (((bitmapword) 1 <<
lbitnum) - 1);
+ a->words[wordnum++] |= ~(((bitmapword) 1 << lbitnum) - 1);
/* turn on all bits for any intermediate words */
while (wordnum < uwordnum)
diff --git a/src/backend/optimizer/geqo/geqo_main.c
b/src/backend/optimizer/geqo/geqo_main.c
index 0064556087a..be65da2b002 100644
--- a/src/backend/optimizer/geqo/geqo_main.c
+++ b/src/backend/optimizer/geqo/geqo_main.c
@@ -244,7 +244,7 @@ geqo(PlannerInfo *root, int number_of_rels, List
*initial_rels)
#if defined(GEQO_DEBUG)
if (edge_failures != 0)
elog(LOG, "[GEQO] failures: %d, average: %d",
- edge_failures, (int) number_generations /
edge_failures);
+ edge_failures, number_generations / edge_failures);
else
elog(LOG, "[GEQO] no edge failures detected");
#else
diff --git a/src/backend/postmaster/syslogger.c
b/src/backend/postmaster/syslogger.c
index 50c2edec1f6..1b17c69b4d2 100644
--- a/src/backend/postmaster/syslogger.c
+++ b/src/backend/postmaster/syslogger.c
@@ -883,7 +883,7 @@ process_pipe_input(char *logbuffer, int *bytes_in_logbuffer)
int dest = LOG_DESTINATION_STDERR;
/* While we have enough for a header, process data... */
- while (count >= (int) (offsetof(PipeProtoHeader, data) + 1))
+ while (count >= (offsetof(PipeProtoHeader, data) + 1))
{
PipeProtoHeader p;
int chunklen;
diff --git a/src/backend/storage/smgr/md.c b/src/backend/storage/smgr/md.c
index e3f335a8340..cd19dd7316d 100644
--- a/src/backend/storage/smgr/md.c
+++ b/src/backend/storage/smgr/md.c
@@ -132,7 +132,7 @@ static MemoryContext MdCxt; /* context for all
MdfdVec objects */
#define MD_PATH_STR_MAXLEN \
(\
REL_PATH_STR_MAXLEN \
- + sizeof((char)'.') \
+ + sizeof('.') \
+ SEGMENT_CHARS \
)
typedef struct MdPathStr
diff --git a/src/backend/storage/sync/sync.c b/src/backend/storage/sync/sync.c
index fc16db90133..e3cab800f5a 100644
--- a/src/backend/storage/sync/sync.c
+++ b/src/backend/storage/sync/sync.c
@@ -374,7 +374,7 @@ ProcessSyncRequests(void)
continue;
/* Else assert we haven't missed it */
- Assert((CycleCtr) (entry->cycle_ctr + 1) == sync_cycle_ctr);
+ Assert((entry->cycle_ctr + 1) == sync_cycle_ctr);
/*
* If fsync is off then we don't have to bother opening the
file at
diff --git a/src/backend/tcop/postgres.c b/src/backend/tcop/postgres.c
index 7dd75a490aa..702c3d16691 100644
--- a/src/backend/tcop/postgres.c
+++ b/src/backend/tcop/postgres.c
@@ -303,7 +303,7 @@ InteractiveBackend(StringInfo inBuf)
*/
/* Add '\0' to make it look the same as message case. */
- appendStringInfoChar(inBuf, (char) '\0');
+ appendStringInfoChar(inBuf, '\0');
/*
* if the query echo flag was given, print the query..
diff --git a/src/backend/utils/adt/like.c b/src/backend/utils/adt/like.c
index 4216ac17f43..32cfe6310c2 100644
--- a/src/backend/utils/adt/like.c
+++ b/src/backend/utils/adt/like.c
@@ -454,5 +454,5 @@ like_escape_bytea(PG_FUNCTION_ARGS)
bytea *esc = PG_GETARG_BYTEA_PP(1);
bytea *result = SB_do_like_escape((text *) pat, (text *) esc);
- PG_RETURN_BYTEA_P((bytea *) result);
+ PG_RETURN_BYTEA_P(result);
}
diff --git a/src/backend/utils/adt/numutils.c b/src/backend/utils/adt/numutils.c
index 3bf30774a0c..f468bc2cd7e 100644
--- a/src/backend/utils/adt/numutils.c
+++ b/src/backend/utils/adt/numutils.c
@@ -1102,7 +1102,7 @@ pg_ultoa_n(uint32 value, char *a)
}
else
{
- *a = (char) ('0' + value);
+ *a = ('0' + value);
}
return olength;
@@ -1211,7 +1211,7 @@ pg_ulltoa_n(uint64 value, char *a)
memcpy(pos - 2, DIGIT_TABLE + c, 2);
}
else
- *a = (char) ('0' + value2);
+ *a = ('0' + value2);
return olength;
}
diff --git a/src/backend/utils/adt/pgstatfuncs.c
b/src/backend/utils/adt/pgstatfuncs.c
index 3d98d064a94..7aaf1ee1f16 100644
--- a/src/backend/utils/adt/pgstatfuncs.c
+++ b/src/backend/utils/adt/pgstatfuncs.c
@@ -1446,7 +1446,7 @@ pgstat_get_io_time_index(IOOp io_op)
static inline double
pg_stat_us_to_ms(PgStat_Counter val_ms)
{
- return val_ms * (double) 0.001;
+ return val_ms * 0.001;
}
/*
diff --git a/src/backend/utils/adt/selfuncs.c b/src/backend/utils/adt/selfuncs.c
index 540aa9628d7..53d96cbea50 100644
--- a/src/backend/utils/adt/selfuncs.c
+++ b/src/backend/utils/adt/selfuncs.c
@@ -5456,7 +5456,7 @@ convert_timevalue_to_scalar(Datum value, Oid typid, bool
*failure)
TimeTzADT *timetz = DatumGetTimeTzADTP(value);
/* use GMT-equivalent time */
- return (double) (timetz->time + (timetz->zone *
1000000.0));
+ return (timetz->time + (timetz->zone *
1000000.0));
}
}
diff --git a/src/backend/utils/adt/tsgistidx.c
b/src/backend/utils/adt/tsgistidx.c
index 935187b37c7..23fca62c199 100644
--- a/src/backend/utils/adt/tsgistidx.c
+++ b/src/backend/utils/adt/tsgistidx.c
@@ -575,7 +575,7 @@ fillcache(CACHESIGN *item, SignTSVector *key, int siglen)
memcpy(item->sign, GETSIGN(key), siglen);
}
-#define WISH_F(a,b,c) (double)( -(double)(((a)-(b))*((a)-(b))*((a)-(b)))*(c) )
+#define WISH_F(a,b,c) ( -(double)(((a)-(b))*((a)-(b))*((a)-(b)))*(c) )
typedef struct
{
OffsetNumber pos;
diff --git a/src/backend/utils/adt/tsquery_gist.c
b/src/backend/utils/adt/tsquery_gist.c
index f7f94c1c760..ec7da50fc67 100644
--- a/src/backend/utils/adt/tsquery_gist.c
+++ b/src/backend/utils/adt/tsquery_gist.c
@@ -161,7 +161,7 @@ comparecost(const void *a, const void *b)
((const SPLITCOST *) b)->cost);
}
-#define WISH_F(a,b,c) (double)( -(double)(((a)-(b))*((a)-(b))*((a)-(b)))*(c) )
+#define WISH_F(a,b,c) ( -(double)(((a)-(b))*((a)-(b))*((a)-(b)))*(c) )
Datum
gtsquery_picksplit(PG_FUNCTION_ARGS)
diff --git a/src/backend/utils/error/elog.c b/src/backend/utils/error/elog.c
index 29643c51439..bd86de0a293 100644
--- a/src/backend/utils/error/elog.c
+++ b/src/backend/utils/error/elog.c
@@ -2703,7 +2703,7 @@ get_formatted_log_time(void)
pg_localtime(&stamp_time, log_timezone));
/* 'paste' milliseconds into place... */
- sprintf(msbuf, ".%03d", (int) (saved_timeval.tv_usec / 1000));
+ sprintf(msbuf, ".%03d", (saved_timeval.tv_usec / 1000));
memcpy(formatted_log_time + 19, msbuf, 4);
return formatted_log_time;
@@ -3046,7 +3046,7 @@ log_status_format(StringInfo buf, const char *format,
ErrorData *edata)
snprintf(strfbuf, sizeof(strfbuf),
"%ld.%03d",
(long)
saved_timeval.tv_sec,
- (int)
(saved_timeval.tv_usec / 1000));
+ (saved_timeval.tv_usec
/ 1000));
if (padding != 0)
appendStringInfo(buf, "%*s",
padding, strfbuf);
diff --git a/src/backend/utils/mb/conversion_procs/euc_tw_and_big5/big5.c
b/src/backend/utils/mb/conversion_procs/euc_tw_and_big5/big5.c
index 68f76aa8cb8..abef1f22bb4 100644
--- a/src/backend/utils/mb/conversion_procs/euc_tw_and_big5/big5.c
+++ b/src/backend/utils/mb/conversion_procs/euc_tw_and_big5/big5.c
@@ -264,7 +264,7 @@ static unsigned short BinarySearchRange
* Its radix is 0x5e. But there is no distance
bias like big5.
*/
distance = tmp * 0x5e
- + ((int) (code & 0x00ff) - (int)
(array[mid].code & 0x00ff));
+ + ((code & 0x00ff) - (array[mid].code &
0x00ff));
/*
* NOTE: Similar to big5 to cns conversion, we
extract
diff --git a/src/backend/utils/mb/wstrcmp.c b/src/backend/utils/mb/wstrcmp.c
index dad3ae023a3..f16a2d47252 100644
--- a/src/backend/utils/mb/wstrcmp.c
+++ b/src/backend/utils/mb/wstrcmp.c
@@ -43,5 +43,5 @@ pg_char_and_wchar_strcmp(const char *s1, const pg_wchar *s2)
while ((pg_wchar) *s1 == *s2++)
if (*s1++ == 0)
return 0;
- return *(const unsigned char *) s1 - *(const pg_wchar *) (s2 - 1);
+ return *(const unsigned char *) s1 - *(s2 - 1);
}
diff --git a/src/backend/utils/mmgr/aset.c b/src/backend/utils/mmgr/aset.c
index bcd09c07533..bce86fcd304 100644
--- a/src/backend/utils/mmgr/aset.c
+++ b/src/backend/utils/mmgr/aset.c
@@ -517,7 +517,7 @@ AllocSetContextCreateInternal(MemoryContext parent,
*/
set->allocChunkLimit = ALLOC_CHUNK_LIMIT;
while ((Size) (set->allocChunkLimit + ALLOC_CHUNKHDRSZ) >
- (Size) ((maxBlockSize - ALLOC_BLOCKHDRSZ) /
ALLOC_CHUNK_FRACTION))
+ ((maxBlockSize - ALLOC_BLOCKHDRSZ) / ALLOC_CHUNK_FRACTION))
set->allocChunkLimit >>= 1;
/* Finally, do the type-independent part of context creation */
diff --git a/src/backend/utils/mmgr/bump.c b/src/backend/utils/mmgr/bump.c
index e60ec94e139..dd4bb93ff81 100644
--- a/src/backend/utils/mmgr/bump.c
+++ b/src/backend/utils/mmgr/bump.c
@@ -228,7 +228,7 @@ BumpContextCreate(MemoryContext parent, const char *name,
Size minContextSize,
*/
set->allocChunkLimit = Min(maxBlockSize, MEMORYCHUNK_MAX_VALUE);
while ((Size) (set->allocChunkLimit + Bump_CHUNKHDRSZ) >
- (Size) ((Size) (maxBlockSize - Bump_BLOCKHDRSZ) /
Bump_CHUNK_FRACTION))
+ ((maxBlockSize - Bump_BLOCKHDRSZ) / Bump_CHUNK_FRACTION))
set->allocChunkLimit >>= 1;
/* Finally, do the type-independent part of context creation */
@@ -626,10 +626,10 @@ BumpBlockFree(BumpContext *set, BumpBlock *block)
/* release the block from the list of blocks */
dlist_delete(&block->node);
- ((MemoryContext) set)->mem_allocated -= ((char *) block->endptr - (char
*) block);
+ ((MemoryContext) set)->mem_allocated -= (block->endptr - (char *)
block);
#ifdef CLOBBER_FREED_MEMORY
- wipe_mem(block, ((char *) block->endptr - (char *) block));
+ wipe_mem(block, (block->endptr - (char *) block));
#endif
/* As in aset.c, free block-header vchunks explicitly */
diff --git a/src/backend/utils/mmgr/generation.c
b/src/backend/utils/mmgr/generation.c
index f6203501956..c9960573ea1 100644
--- a/src/backend/utils/mmgr/generation.c
+++ b/src/backend/utils/mmgr/generation.c
@@ -263,7 +263,7 @@ GenerationContextCreate(MemoryContext parent,
*/
set->allocChunkLimit = Min(maxBlockSize, MEMORYCHUNK_MAX_VALUE);
while ((Size) (set->allocChunkLimit + Generation_CHUNKHDRSZ) >
- (Size) ((Size) (maxBlockSize - Generation_BLOCKHDRSZ) /
Generation_CHUNK_FRACTION))
+ ((maxBlockSize - Generation_BLOCKHDRSZ) /
Generation_CHUNK_FRACTION))
set->allocChunkLimit >>= 1;
/* Finally, do the type-independent part of context creation */
diff --git a/src/bin/pg_basebackup/walmethods.c
b/src/bin/pg_basebackup/walmethods.c
index eaaabc5f374..8a625481aa2 100644
--- a/src/bin/pg_basebackup/walmethods.c
+++ b/src/bin/pg_basebackup/walmethods.c
@@ -644,7 +644,7 @@ CreateWalDirectoryMethod(const char *basedir,
DirectoryMethodData *wwmethod;
wwmethod = pg_malloc0(sizeof(DirectoryMethodData));
- *((const WalWriteMethodOps **) &wwmethod->base.ops) =
+ *(&wwmethod->base.ops) =
&WalDirectoryMethodOps;
wwmethod->base.compression_algorithm = compression_algorithm;
wwmethod->base.compression_level = compression_level;
@@ -1361,7 +1361,7 @@ CreateWalTarMethod(const char *tarbase,
".tar.gz" : ".tar";
wwmethod = pg_malloc0(sizeof(TarMethodData));
- *((const WalWriteMethodOps **) &wwmethod->base.ops) =
+ *(&wwmethod->base.ops) =
&WalTarMethodOps;
wwmethod->base.compression_algorithm = compression_algorithm;
wwmethod->base.compression_level = compression_level;
diff --git a/src/bin/pg_upgrade/pg_upgrade.c b/src/bin/pg_upgrade/pg_upgrade.c
index 490e98fa26f..e4be03a3d36 100644
--- a/src/bin/pg_upgrade/pg_upgrade.c
+++ b/src/bin/pg_upgrade/pg_upgrade.c
@@ -295,7 +295,7 @@ make_outputdirs(char *pgdata)
strftime(timebuf, sizeof(timebuf), "%Y%m%dT%H%M%S", localtime(&tt));
/* append milliseconds */
snprintf(timebuf + strlen(timebuf), sizeof(timebuf) - strlen(timebuf),
- ".%03d", (int) (time.tv_usec / 1000));
+ ".%03d", (time.tv_usec / 1000));
log_opts.basedir = (char *) pg_malloc0(MAXPGPATH);
len = snprintf(log_opts.basedir, MAXPGPATH, "%s/%s", log_opts.rootdir,
timebuf);
diff --git a/src/bin/pgbench/pgbench.c b/src/bin/pgbench/pgbench.c
index 68774a59efd..fb515181a66 100644
--- a/src/bin/pgbench/pgbench.c
+++ b/src/bin/pgbench/pgbench.c
@@ -1120,7 +1120,7 @@ getExponentialRand(pg_prng_state *state, int64 min, int64
max,
Assert((1.0 - cut) != 0.0);
rand = -log(cut + (1.0 - cut) * uniform) / parameter;
/* return int64 random number within between min and max */
- return min + (int64) ((max - min + 1) * rand);
+ return min + ((max - min + 1) * rand);
}
/* random number generator: gaussian distribution from min to max inclusive */
@@ -1156,7 +1156,7 @@ getGaussianRand(pg_prng_state *state, int64 min, int64
max,
rand = (stdev + parameter) / (parameter * 2.0);
/* return int64 random number within between min and max */
- return min + (int64) ((max - min + 1) * rand);
+ return min + ((max - min + 1) * rand);
}
/*
diff --git a/src/common/d2s.c b/src/common/d2s.c
index 5322c465d53..e0ac9d36c57 100644
--- a/src/common/d2s.c
+++ b/src/common/d2s.c
@@ -736,7 +736,7 @@ to_chars_df(const floating_decimal_64 v, const uint32
olength, char *const resul
}
else
{
- result[index] = (char) ('0' + output2);
+ result[index] = ('0' + output2);
}
if (index == 1)
@@ -917,7 +917,7 @@ to_chars(floating_decimal_64 v, const bool sign, char
*const result)
}
else
{
- result[index] = (char) ('0' + output2);
+ result[index] = ('0' + output2);
}
/* Print decimal point if needed. */
@@ -946,7 +946,7 @@ to_chars(floating_decimal_64 v, const bool sign, char
*const result)
const int32 c = exp % 10;
memcpy(result + index, DIGIT_TABLE + 2 * (exp / 10), 2);
- result[index + 2] = (char) ('0' + c);
+ result[index + 2] = ('0' + c);
index += 3;
}
else
diff --git a/src/common/f2s.c b/src/common/f2s.c
index a239a8765b0..c94d2261511 100644
--- a/src/common/f2s.c
+++ b/src/common/f2s.c
@@ -517,7 +517,7 @@ to_chars_f(const floating_decimal_32 v, const uint32
olength, char *const result
}
else
{
- result[index] = (char) ('0' + output);
+ result[index] = ('0' + output);
}
if (index == 1)
@@ -655,7 +655,7 @@ to_chars(const floating_decimal_32 v, const bool sign, char
*const result)
}
else
{
- result[index] = (char) ('0' + output);
+ result[index] = ('0' + output);
}
/* Print decimal point if needed. */
diff --git a/src/interfaces/ecpg/compatlib/informix.c
b/src/interfaces/ecpg/compatlib/informix.c
index ca11a81f1bc..5e546950820 100644
--- a/src/interfaces/ecpg/compatlib/informix.c
+++ b/src/interfaces/ecpg/compatlib/informix.c
@@ -383,7 +383,7 @@ dectoasc(decimal *np, char *cp, int len, int right)
char *str;
numeric *nres;
- rsetnull(CSTRINGTYPE, (char *) cp);
+ rsetnull(CSTRINGTYPE, cp);
if (risnull(CDECIMALTYPE, (char *) np))
return 0;
@@ -410,7 +410,7 @@ dectoasc(decimal *np, char *cp, int len, int right)
* TODO: have to take care of len here and create exponential notation
if
* necessary
*/
- if ((int) (strlen(str) + 1) > len)
+ if ((strlen(str) + 1) > len)
{
if (len > 1)
{
diff --git a/src/interfaces/ecpg/ecpglib/data.c
b/src/interfaces/ecpg/ecpglib/data.c
index d5d40f7b654..b5b9dd7412f 100644
--- a/src/interfaces/ecpg/ecpglib/data.c
+++ b/src/interfaces/ecpg/ecpglib/data.c
@@ -390,7 +390,7 @@ ecpg_get_data(const PGresult *results, int act_tuple, int
act_field, int lineno,
*((int *) (var + offset
* act_tuple)) = (int) res;
break;
case ECPGt_long:
- *((long *) (var +
offset * act_tuple)) = (long) res;
+ *((long *) (var +
offset * act_tuple)) = res;
break;
default:
/* Cannot happen */
@@ -419,7 +419,7 @@ ecpg_get_data(const PGresult *results, int act_tuple, int
act_field, int lineno,
*((unsigned int *) (var
+ offset * act_tuple)) = (unsigned int) ures;
break;
case ECPGt_unsigned_long:
- *((unsigned long *)
(var + offset * act_tuple)) = (unsigned long) ures;
+ *((unsigned long *)
(var + offset * act_tuple)) = ures;
break;
default:
/* Cannot happen */
@@ -557,7 +557,7 @@ ecpg_get_data(const PGresult *results, int act_tuple, int
act_field, int lineno,
case ECPGt_unsigned_char:
case ECPGt_string:
{
- char *str = (char *) (var
+ offset * act_tuple);
+ char *str = (var + offset
* act_tuple);
/*
* If varcharsize is unknown
and the offset is that of
diff --git a/src/interfaces/ecpg/pgtypeslib/dt_common.c
b/src/interfaces/ecpg/pgtypeslib/dt_common.c
index c4119ab7932..fe960edc236 100644
--- a/src/interfaces/ecpg/pgtypeslib/dt_common.c
+++ b/src/interfaces/ecpg/pgtypeslib/dt_common.c
@@ -892,7 +892,7 @@ EncodeDateTime(struct tm *tm, fsec_t fsec, bool print_tz,
int tz, const char *tz
/* Backward-compatible with traditional Postgres
abstime dates */
day = date2j(tm->tm_year, tm->tm_mon, tm->tm_mday);
- tm->tm_wday = (int) ((day + date2j(2000, 1, 1) + 1) %
7);
+ tm->tm_wday = ((day + date2j(2000, 1, 1) + 1) % 7);
memcpy(str, days[tm->tm_wday], 3);
strcpy(str + 3, " ");
diff --git a/src/interfaces/ecpg/test/expected/sql-desc.c
b/src/interfaces/ecpg/test/expected/sql-desc.c
index bdd12a506be..ecf0bd60e2a 100644
--- a/src/interfaces/ecpg/test/expected/sql-desc.c
+++ b/src/interfaces/ecpg/test/expected/sql-desc.c
@@ -280,7 +280,7 @@ if (sqlca.sqlcode < 0) sqlprint();}
#line 65 "desc.pgc"
- { ECPGset_desc_header(__LINE__, "indesc", (int)(1));
+ { ECPGset_desc_header(__LINE__, "indesc", (1));
#line 67 "desc.pgc"
diff --git a/src/interfaces/libpq/fe-connect.c
b/src/interfaces/libpq/fe-connect.c
index c3a2448dce5..b87774334ce 100644
--- a/src/interfaces/libpq/fe-connect.c
+++ b/src/interfaces/libpq/fe-connect.c
@@ -3096,7 +3096,7 @@ keep_going:
/* We will come back to here until there is
{
libpq_append_conn_error(conn,
"Unix-domain socket path \"%s\" is too long (maximum %d bytes)",
portstr,
-
(int) (UNIXSOCK_PATH_BUFLEN - 1));
+
(UNIXSOCK_PATH_BUFLEN - 1));
goto keep_going;
}
diff --git a/src/test/isolation/isolation_main.c
b/src/test/isolation/isolation_main.c
index a13f9cdcaf7..f9b165c5cf4 100644
--- a/src/test/isolation/isolation_main.c
+++ b/src/test/isolation/isolation_main.c
@@ -125,7 +125,7 @@ isolation_init(int argc, char **argv)
if (argv0_len >= MAXPGPATH)
{
fprintf(stderr, _("path for isolationtester executable is
longer than %d bytes\n"),
- (int) (MAXPGPATH - 1));
+ (MAXPGPATH - 1));
exit(2);
}
diff --git a/src/test/regress/regress.c b/src/test/regress/regress.c
index 56cc0567b1c..bad6c576b2f 100644
--- a/src/test/regress/regress.c
+++ b/src/test/regress/regress.c
@@ -1082,7 +1082,7 @@ test_enc_conversion(PG_FUNCTION_ARGS)
errdetail("String of %d bytes is too
long for encoding conversion.",
(int) srclen)));
- dstsize = (Size) srclen * MAX_CONVERSION_GROWTH + 1;
+ dstsize = srclen * MAX_CONVERSION_GROWTH + 1;
dst = MemoryContextAlloc(CurrentMemoryContext, dstsize);
/* perform conversion */
diff --git a/src/timezone/localtime.c b/src/timezone/localtime.c
index 20147f1a2c2..fb68594b868 100644
--- a/src/timezone/localtime.c
+++ b/src/timezone/localtime.c
@@ -1522,7 +1522,7 @@ timesub(const pg_time_t *timep, int_fast32_t offset,
ip = mon_lengths[isleap(y)];
for (tmp->tm_mon = 0; idays >= ip[tmp->tm_mon]; ++(tmp->tm_mon))
idays -= ip[tmp->tm_mon];
- tmp->tm_mday = (int) (idays + 1);
+ tmp->tm_mday = (idays + 1);
tmp->tm_isdst = 0;
tmp->tm_gmtoff = offset;
return tmp;
diff --git a/src/timezone/zic.c b/src/timezone/zic.c
index a8c1de9910d..1b4f3017f12 100644
--- a/src/timezone/zic.c
+++ b/src/timezone/zic.c
@@ -3891,7 +3891,7 @@ will not work with pre-2004 versions of zic"));
return min_time;
if (dayoff > max_time / SECSPERDAY)
return max_time;
- t = (zic_t) dayoff * SECSPERDAY;
+ t = dayoff * SECSPERDAY;
return tadd(t, rp->r_tod);
}