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
This commit is contained in:
Peter Eisentraut 2025-02-20 19:49:27 +01:00
parent ab84d0ff80
commit 3e4d868615
18 changed files with 34 additions and 32 deletions

View File

@ -410,7 +410,7 @@ ltxtq_in(PG_FUNCTION_ARGS)
{
ltxtquery *res;
if ((res = queryin((char *) PG_GETARG_POINTER(0), fcinfo->context)) == NULL)
if ((res = queryin(PG_GETARG_POINTER(0), fcinfo->context)) == NULL)
PG_RETURN_NULL();
PG_RETURN_POINTER(res);
}

View File

@ -106,7 +106,7 @@ makesign(BITVECP sign, TRGM *a, int siglen)
SETBIT(sign, SIGLENBIT(siglen)); /* set last unused bit */
for (k = 0; k < len; k++)
{
CPTRGM(((char *) &tmp), ptr + k);
CPTRGM(&tmp, ptr + k);
HASH(sign, tmp, siglen);
}
}
@ -186,7 +186,7 @@ cnt_sml_sign_common(TRGM *qtrg, BITVECP sign, int siglen)
for (k = 0; k < len; k++)
{
CPTRGM(((char *) &tmp), ptr + k);
CPTRGM(&tmp, ptr + k);
count += GETBIT(sign, HASHVAL(tmp, siglen));
}
@ -373,7 +373,7 @@ gtrgm_consistent(PG_FUNCTION_ARGS)
res = true;
for (k = 0; k < len; k++)
{
CPTRGM(((char *) &tmp), ptr + k);
CPTRGM(&tmp, ptr + k);
if (!GETBIT(sign, HASHVAL(tmp, siglen)))
{
res = false;
@ -426,7 +426,7 @@ gtrgm_consistent(PG_FUNCTION_ARGS)
check = (bool *) palloc(len * sizeof(bool));
for (k = 0; k < len; k++)
{
CPTRGM(((char *) &tmp), ptr + k);
CPTRGM(&tmp, ptr + k);
check[k] = GETBIT(sign, HASHVAL(tmp, siglen));
}
res = trigramsMatchGraph(cache->graph, check);
@ -552,7 +552,7 @@ unionkey(BITVECP sbase, TRGM *add, int siglen)
for (i = 0; i < ARRNELEM(add); i++)
{
CPTRGM(((char *) &tmp), ptr + i);
CPTRGM(&tmp, ptr + i);
HASH(sbase, tmp, siglen);
}
}

View File

@ -5660,13 +5660,13 @@ postgresImportForeignSchema(ImportForeignSchemaStmt *stmt, Oid serverOid)
attname = PQgetvalue(res, i, 1);
typename = PQgetvalue(res, i, 2);
attnotnull = PQgetvalue(res, i, 3);
attdefault = PQgetisnull(res, i, 4) ? (char *) NULL :
attdefault = PQgetisnull(res, i, 4) ? NULL :
PQgetvalue(res, i, 4);
attgenerated = PQgetisnull(res, i, 5) ? (char *) NULL :
attgenerated = PQgetisnull(res, i, 5) ? NULL :
PQgetvalue(res, i, 5);
collname = PQgetisnull(res, i, 6) ? (char *) NULL :
collname = PQgetisnull(res, i, 6) ? NULL :
PQgetvalue(res, i, 6);
collnamespace = PQgetisnull(res, i, 7) ? (char *) NULL :
collnamespace = PQgetisnull(res, i, 7) ? NULL :
PQgetvalue(res, i, 7);
if (first_item)

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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