aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPeter Eisentraut <peter@eisentraut.org>2025-02-20 19:49:27 +0100
committerPeter Eisentraut <peter@eisentraut.org>2025-02-20 19:49:27 +0100
commit3e4d868615408370fe6c2977c32f45a47c372b00 (patch)
treead4dd9cb02d58fb938f2f8e1a8c352bcd9bfe314 /src
parentab84d0ff806dd791ea9da5f1ca302daf3cf42980 (diff)
downloadpostgresql-3e4d868615408370fe6c2977c32f45a47c372b00.tar.gz
postgresql-3e4d868615408370fe6c2977c32f45a47c372b00.zip
Remove various unnecessary (char *) casts
Remove a number of (char *) casts that are unnecessary. Or in some cases, rewrite the code to make the purpose of the cast clearer. Reviewed-by: Dagfinn Ilmari Mannsåker <ilmari@ilmari.org> Discussion: https://www.postgresql.org/message-id/flat/fd1fcedb-3492-4fc8-9e3e-74b97f2db6c7%40eisentraut.org
Diffstat (limited to 'src')
-rw-r--r--src/backend/access/transam/xlog.c4
-rw-r--r--src/backend/libpq/auth.c8
-rw-r--r--src/backend/nodes/copyfuncs.c2
-rw-r--r--src/backend/nodes/makefuncs.c2
-rw-r--r--src/backend/storage/page/bufpage.c2
-rw-r--r--src/backend/utils/cache/relmapper.c4
-rw-r--r--src/backend/utils/error/jsonlog.c2
-rw-r--r--src/bin/pg_basebackup/pg_receivewal.c2
-rw-r--r--src/bin/pg_dump/compress_gzip.c2
-rw-r--r--src/bin/pg_rewind/pg_rewind.c2
-rw-r--r--src/bin/psql/describe.c2
-rw-r--r--src/common/controldata_utils.c4
-rw-r--r--src/interfaces/ecpg/ecpglib/descriptor.c4
-rw-r--r--src/interfaces/ecpg/ecpglib/execute.c2
-rw-r--r--src/interfaces/ecpg/pgtypeslib/numeric.c4
15 files changed, 24 insertions, 22 deletions
diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c
index f9bf5ba7509..d10704360a6 100644
--- a/src/backend/access/transam/xlog.c
+++ b/src/backend/access/transam/xlog.c
@@ -4287,7 +4287,7 @@ WriteControlFile(void)
/* Contents are protected with a CRC */
INIT_CRC32C(ControlFile->crc);
COMP_CRC32C(ControlFile->crc,
- (char *) ControlFile,
+ ControlFile,
offsetof(ControlFileData, crc));
FIN_CRC32C(ControlFile->crc);
@@ -4405,7 +4405,7 @@ ReadControlFile(void)
/* Now check the CRC. */
INIT_CRC32C(crc);
COMP_CRC32C(crc,
- (char *) ControlFile,
+ ControlFile,
offsetof(ControlFileData, crc));
FIN_CRC32C(crc);
diff --git a/src/backend/libpq/auth.c b/src/backend/libpq/auth.c
index 0f65014e64f..81e2f8184e3 100644
--- a/src/backend/libpq/auth.c
+++ b/src/backend/libpq/auth.c
@@ -2932,8 +2932,8 @@ PerformRadiusTransaction(const char *server, const char *secret, const char *por
radius_packet radius_recv_pack;
radius_packet *packet = &radius_send_pack;
radius_packet *receivepacket = &radius_recv_pack;
- char *radius_buffer = (char *) &radius_send_pack;
- char *receive_buffer = (char *) &radius_recv_pack;
+ void *radius_buffer = &radius_send_pack;
+ void *receive_buffer = &radius_recv_pack;
int32 service = pg_hton32(RADIUS_AUTHENTICATE_ONLY);
uint8 *cryptvector;
int encryptedpasswordlen;
@@ -3204,7 +3204,9 @@ PerformRadiusTransaction(const char *server, const char *secret, const char *por
* original packet */
if (packetlength > RADIUS_HEADER_LENGTH) /* there may be no
* attributes at all */
- memcpy(cryptvector + RADIUS_HEADER_LENGTH, receive_buffer + RADIUS_HEADER_LENGTH, packetlength - RADIUS_HEADER_LENGTH);
+ memcpy(cryptvector + RADIUS_HEADER_LENGTH,
+ (char *) receive_buffer + RADIUS_HEADER_LENGTH,
+ packetlength - RADIUS_HEADER_LENGTH);
memcpy(cryptvector + packetlength, secret, strlen(secret));
if (!pg_md5_binary(cryptvector,
diff --git a/src/backend/nodes/copyfuncs.c b/src/backend/nodes/copyfuncs.c
index 45915767825..475693b08bc 100644
--- a/src/backend/nodes/copyfuncs.c
+++ b/src/backend/nodes/copyfuncs.c
@@ -40,7 +40,7 @@
/* Copy a field that is a pointer to a C string, or perhaps NULL */
#define COPY_STRING_FIELD(fldname) \
- (newnode->fldname = from->fldname ? pstrdup(from->fldname) : (char *) NULL)
+ (newnode->fldname = from->fldname ? pstrdup(from->fldname) : NULL)
/* Copy a field that is an inline array */
#define COPY_ARRAY_FIELD(fldname) \
diff --git a/src/backend/nodes/makefuncs.c b/src/backend/nodes/makefuncs.c
index 007612563ca..dbbc2f1e30d 100644
--- a/src/backend/nodes/makefuncs.c
+++ b/src/backend/nodes/makefuncs.c
@@ -51,7 +51,7 @@ makeSimpleA_Expr(A_Expr_Kind kind, char *name,
A_Expr *a = makeNode(A_Expr);
a->kind = kind;
- a->name = list_make1(makeString((char *) name));
+ a->name = list_make1(makeString(name));
a->lexpr = lexpr;
a->rexpr = rexpr;
a->location = location;
diff --git a/src/backend/storage/page/bufpage.c b/src/backend/storage/page/bufpage.c
index 91da73dda8b..ecc81aacfc3 100644
--- a/src/backend/storage/page/bufpage.c
+++ b/src/backend/storage/page/bufpage.c
@@ -1502,7 +1502,7 @@ PageSetChecksumCopy(Page page, BlockNumber blkno)
/* If we don't need a checksum, just return the passed-in data */
if (PageIsNew(page) || !DataChecksumsEnabled())
- return (char *) page;
+ return page;
/*
* We allocate the copy space once and use it over on each subsequent
diff --git a/src/backend/utils/cache/relmapper.c b/src/backend/utils/cache/relmapper.c
index 7dcbf1d5c5c..abf89f0776e 100644
--- a/src/backend/utils/cache/relmapper.c
+++ b/src/backend/utils/cache/relmapper.c
@@ -854,7 +854,7 @@ read_relmap_file(RelMapFile *map, char *dbpath, bool lock_held, int elevel)
/* verify the CRC */
INIT_CRC32C(crc);
- COMP_CRC32C(crc, (char *) map, offsetof(RelMapFile, crc));
+ COMP_CRC32C(crc, map, offsetof(RelMapFile, crc));
FIN_CRC32C(crc);
if (!EQ_CRC32C(crc, map->crc))
@@ -910,7 +910,7 @@ write_relmap_file(RelMapFile *newmap, bool write_wal, bool send_sinval,
elog(ERROR, "attempt to write bogus relation mapping");
INIT_CRC32C(newmap->crc);
- COMP_CRC32C(newmap->crc, (char *) newmap, offsetof(RelMapFile, crc));
+ COMP_CRC32C(newmap->crc, newmap, offsetof(RelMapFile, crc));
FIN_CRC32C(newmap->crc);
/*
diff --git a/src/backend/utils/error/jsonlog.c b/src/backend/utils/error/jsonlog.c
index 6533f1d6888..549e0f48ee8 100644
--- a/src/backend/utils/error/jsonlog.c
+++ b/src/backend/utils/error/jsonlog.c
@@ -206,7 +206,7 @@ write_jsonlog(ErrorData *edata)
/* Error severity */
if (edata->elevel)
appendJSONKeyValue(&buf, "error_severity",
- (char *) error_severity(edata->elevel), true);
+ error_severity(edata->elevel), true);
/* SQL state code */
if (edata->sqlerrcode)
diff --git a/src/bin/pg_basebackup/pg_receivewal.c b/src/bin/pg_basebackup/pg_receivewal.c
index 176c40facad..de3584018b0 100644
--- a/src/bin/pg_basebackup/pg_receivewal.c
+++ b/src/bin/pg_basebackup/pg_receivewal.c
@@ -342,7 +342,7 @@ FindStreamingStart(uint32 *tli)
if (lseek(fd, (off_t) (-4), SEEK_END) < 0)
pg_fatal("could not seek in compressed file \"%s\": %m",
fullpath);
- r = read(fd, (char *) buf, sizeof(buf));
+ r = read(fd, buf, sizeof(buf));
if (r != sizeof(buf))
{
if (r < 0)
diff --git a/src/bin/pg_dump/compress_gzip.c b/src/bin/pg_dump/compress_gzip.c
index f9e5f00aaa1..23f617209e6 100644
--- a/src/bin/pg_dump/compress_gzip.c
+++ b/src/bin/pg_dump/compress_gzip.c
@@ -129,7 +129,7 @@ DeflateCompressorCommon(ArchiveHandle *AH, CompressorState *cs, bool flush)
*/
size_t len = gzipcs->outsize - zp->avail_out;
- cs->writeF(AH, (char *) out, len);
+ cs->writeF(AH, out, len);
}
zp->next_out = out;
zp->avail_out = gzipcs->outsize;
diff --git a/src/bin/pg_rewind/pg_rewind.c b/src/bin/pg_rewind/pg_rewind.c
index cae81cd6cb1..2ce99d06d1d 100644
--- a/src/bin/pg_rewind/pg_rewind.c
+++ b/src/bin/pg_rewind/pg_rewind.c
@@ -1007,7 +1007,7 @@ checkControlFile(ControlFileData *ControlFile)
/* Calculate CRC */
INIT_CRC32C(crc);
- COMP_CRC32C(crc, (char *) ControlFile, offsetof(ControlFileData, crc));
+ COMP_CRC32C(crc, ControlFile, offsetof(ControlFileData, crc));
FIN_CRC32C(crc);
/* And simply compare it */
diff --git a/src/bin/psql/describe.c b/src/bin/psql/describe.c
index 3b7ba66fad0..e6cf468ac9e 100644
--- a/src/bin/psql/describe.c
+++ b/src/bin/psql/describe.c
@@ -1741,7 +1741,7 @@ describeOneTableDetails(const char *schemaname,
*(PQgetvalue(res, 0, 13)) : 'd';
if (pset.sversion >= 120000)
tableinfo.relam = PQgetisnull(res, 0, 14) ?
- (char *) NULL : pg_strdup(PQgetvalue(res, 0, 14));
+ NULL : pg_strdup(PQgetvalue(res, 0, 14));
else
tableinfo.relam = NULL;
PQclear(res);
diff --git a/src/common/controldata_utils.c b/src/common/controldata_utils.c
index 27ce27d7647..34d8a3a4e31 100644
--- a/src/common/controldata_utils.c
+++ b/src/common/controldata_utils.c
@@ -135,7 +135,7 @@ retry:
/* Check the CRC. */
INIT_CRC32C(crc);
COMP_CRC32C(crc,
- (char *) ControlFile,
+ ControlFile,
offsetof(ControlFileData, crc));
FIN_CRC32C(crc);
@@ -199,7 +199,7 @@ update_controlfile(const char *DataDir,
/* Recalculate CRC of control file */
INIT_CRC32C(ControlFile->crc);
COMP_CRC32C(ControlFile->crc,
- (char *) ControlFile,
+ ControlFile,
offsetof(ControlFileData, crc));
FIN_CRC32C(ControlFile->crc);
diff --git a/src/interfaces/ecpg/ecpglib/descriptor.c b/src/interfaces/ecpg/ecpglib/descriptor.c
index 8525a6812f2..651d5c8b2ed 100644
--- a/src/interfaces/ecpg/ecpglib/descriptor.c
+++ b/src/interfaces/ecpg/ecpglib/descriptor.c
@@ -198,7 +198,7 @@ get_char_item(int lineno, void *var, enum ECPGttype vartype, char *value, int va
case ECPGt_char:
case ECPGt_unsigned_char:
case ECPGt_string:
- strncpy((char *) var, value, varcharsize);
+ strncpy(var, value, varcharsize);
break;
case ECPGt_varchar:
{
@@ -597,7 +597,7 @@ set_desc_attr(struct descriptor_item *desc_item, struct variable *var,
}
ecpg_free(desc_item->data); /* free() takes care of a potential NULL value */
- desc_item->data = (char *) tobeinserted;
+ desc_item->data = tobeinserted;
}
diff --git a/src/interfaces/ecpg/ecpglib/execute.c b/src/interfaces/ecpg/ecpglib/execute.c
index b5089eac787..f52da06de9a 100644
--- a/src/interfaces/ecpg/ecpglib/execute.c
+++ b/src/interfaces/ecpg/ecpglib/execute.c
@@ -278,7 +278,7 @@ ecpg_is_type_an_array(int type, const struct statement *stmt, const struct varia
isarray = ECPG_ARRAY_NONE;
else
{
- isarray = (atoi((char *) PQgetvalue(query, 0, 0)) == -1) ? ECPG_ARRAY_ARRAY : ECPG_ARRAY_VECTOR;
+ isarray = (atoi(PQgetvalue(query, 0, 0)) == -1) ? ECPG_ARRAY_ARRAY : ECPG_ARRAY_VECTOR;
if (ecpg_dynamic_type(type) == SQL3_CHARACTER ||
ecpg_dynamic_type(type) == SQL3_CHARACTER_VARYING)
{
diff --git a/src/interfaces/ecpg/pgtypeslib/numeric.c b/src/interfaces/ecpg/pgtypeslib/numeric.c
index 35e7b92da40..bb2a86981ca 100644
--- a/src/interfaces/ecpg/pgtypeslib/numeric.c
+++ b/src/interfaces/ecpg/pgtypeslib/numeric.c
@@ -232,7 +232,7 @@ get_str_from_var(numeric *var, int dscale)
if (var->sign == NUMERIC_NAN)
{
- str = (char *) pgtypes_alloc(4);
+ str = pgtypes_alloc(4);
if (str == NULL)
return NULL;
sprintf(str, "NaN");
@@ -269,7 +269,7 @@ get_str_from_var(numeric *var, int dscale)
/*
* Allocate space for the result
*/
- if ((str = (char *) pgtypes_alloc(Max(0, dscale) + Max(0, var->weight) + 4)) == NULL)
+ if ((str = pgtypes_alloc(Max(0, dscale) + Max(0, var->weight) + 4)) == NULL)
return NULL;
cp = str;