Skip to content

Commit 3e4d868

Browse files
committed
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
1 parent ab84d0f commit 3e4d868

File tree

18 files changed

+34
-32
lines changed

18 files changed

+34
-32
lines changed

contrib/ltree/ltxtquery_io.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ ltxtq_in(PG_FUNCTION_ARGS)
410410
{
411411
ltxtquery *res;
412412

413-
if ((res = queryin((char *) PG_GETARG_POINTER(0), fcinfo->context)) == NULL)
413+
if ((res = queryin(PG_GETARG_POINTER(0), fcinfo->context)) == NULL)
414414
PG_RETURN_NULL();
415415
PG_RETURN_POINTER(res);
416416
}

contrib/pg_trgm/trgm_gist.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ makesign(BITVECP sign, TRGM *a, int siglen)
106106
SETBIT(sign, SIGLENBIT(siglen)); /* set last unused bit */
107107
for (k = 0; k < len; k++)
108108
{
109-
CPTRGM(((char *) &tmp), ptr + k);
109+
CPTRGM(&tmp, ptr + k);
110110
HASH(sign, tmp, siglen);
111111
}
112112
}
@@ -186,7 +186,7 @@ cnt_sml_sign_common(TRGM *qtrg, BITVECP sign, int siglen)
186186

187187
for (k = 0; k < len; k++)
188188
{
189-
CPTRGM(((char *) &tmp), ptr + k);
189+
CPTRGM(&tmp, ptr + k);
190190
count += GETBIT(sign, HASHVAL(tmp, siglen));
191191
}
192192

@@ -373,7 +373,7 @@ gtrgm_consistent(PG_FUNCTION_ARGS)
373373
res = true;
374374
for (k = 0; k < len; k++)
375375
{
376-
CPTRGM(((char *) &tmp), ptr + k);
376+
CPTRGM(&tmp, ptr + k);
377377
if (!GETBIT(sign, HASHVAL(tmp, siglen)))
378378
{
379379
res = false;
@@ -426,7 +426,7 @@ gtrgm_consistent(PG_FUNCTION_ARGS)
426426
check = (bool *) palloc(len * sizeof(bool));
427427
for (k = 0; k < len; k++)
428428
{
429-
CPTRGM(((char *) &tmp), ptr + k);
429+
CPTRGM(&tmp, ptr + k);
430430
check[k] = GETBIT(sign, HASHVAL(tmp, siglen));
431431
}
432432
res = trigramsMatchGraph(cache->graph, check);
@@ -552,7 +552,7 @@ unionkey(BITVECP sbase, TRGM *add, int siglen)
552552

553553
for (i = 0; i < ARRNELEM(add); i++)
554554
{
555-
CPTRGM(((char *) &tmp), ptr + i);
555+
CPTRGM(&tmp, ptr + i);
556556
HASH(sbase, tmp, siglen);
557557
}
558558
}

contrib/postgres_fdw/postgres_fdw.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5660,13 +5660,13 @@ postgresImportForeignSchema(ImportForeignSchemaStmt *stmt, Oid serverOid)
56605660
attname = PQgetvalue(res, i, 1);
56615661
typename = PQgetvalue(res, i, 2);
56625662
attnotnull = PQgetvalue(res, i, 3);
5663-
attdefault = PQgetisnull(res, i, 4) ? (char *) NULL :
5663+
attdefault = PQgetisnull(res, i, 4) ? NULL :
56645664
PQgetvalue(res, i, 4);
5665-
attgenerated = PQgetisnull(res, i, 5) ? (char *) NULL :
5665+
attgenerated = PQgetisnull(res, i, 5) ? NULL :
56665666
PQgetvalue(res, i, 5);
5667-
collname = PQgetisnull(res, i, 6) ? (char *) NULL :
5667+
collname = PQgetisnull(res, i, 6) ? NULL :
56685668
PQgetvalue(res, i, 6);
5669-
collnamespace = PQgetisnull(res, i, 7) ? (char *) NULL :
5669+
collnamespace = PQgetisnull(res, i, 7) ? NULL :
56705670
PQgetvalue(res, i, 7);
56715671

56725672
if (first_item)

src/backend/access/transam/xlog.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4287,7 +4287,7 @@ WriteControlFile(void)
42874287
/* Contents are protected with a CRC */
42884288
INIT_CRC32C(ControlFile->crc);
42894289
COMP_CRC32C(ControlFile->crc,
4290-
(char *) ControlFile,
4290+
ControlFile,
42914291
offsetof(ControlFileData, crc));
42924292
FIN_CRC32C(ControlFile->crc);
42934293

@@ -4405,7 +4405,7 @@ ReadControlFile(void)
44054405
/* Now check the CRC. */
44064406
INIT_CRC32C(crc);
44074407
COMP_CRC32C(crc,
4408-
(char *) ControlFile,
4408+
ControlFile,
44094409
offsetof(ControlFileData, crc));
44104410
FIN_CRC32C(crc);
44114411

src/backend/libpq/auth.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2932,8 +2932,8 @@ PerformRadiusTransaction(const char *server, const char *secret, const char *por
29322932
radius_packet radius_recv_pack;
29332933
radius_packet *packet = &radius_send_pack;
29342934
radius_packet *receivepacket = &radius_recv_pack;
2935-
char *radius_buffer = (char *) &radius_send_pack;
2936-
char *receive_buffer = (char *) &radius_recv_pack;
2935+
void *radius_buffer = &radius_send_pack;
2936+
void *receive_buffer = &radius_recv_pack;
29372937
int32 service = pg_hton32(RADIUS_AUTHENTICATE_ONLY);
29382938
uint8 *cryptvector;
29392939
int encryptedpasswordlen;
@@ -3204,7 +3204,9 @@ PerformRadiusTransaction(const char *server, const char *secret, const char *por
32043204
* original packet */
32053205
if (packetlength > RADIUS_HEADER_LENGTH) /* there may be no
32063206
* attributes at all */
3207-
memcpy(cryptvector + RADIUS_HEADER_LENGTH, receive_buffer + RADIUS_HEADER_LENGTH, packetlength - RADIUS_HEADER_LENGTH);
3207+
memcpy(cryptvector + RADIUS_HEADER_LENGTH,
3208+
(char *) receive_buffer + RADIUS_HEADER_LENGTH,
3209+
packetlength - RADIUS_HEADER_LENGTH);
32083210
memcpy(cryptvector + packetlength, secret, strlen(secret));
32093211

32103212
if (!pg_md5_binary(cryptvector,

src/backend/nodes/copyfuncs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040

4141
/* Copy a field that is a pointer to a C string, or perhaps NULL */
4242
#define COPY_STRING_FIELD(fldname) \
43-
(newnode->fldname = from->fldname ? pstrdup(from->fldname) : (char *) NULL)
43+
(newnode->fldname = from->fldname ? pstrdup(from->fldname) : NULL)
4444

4545
/* Copy a field that is an inline array */
4646
#define COPY_ARRAY_FIELD(fldname) \

src/backend/nodes/makefuncs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ makeSimpleA_Expr(A_Expr_Kind kind, char *name,
5151
A_Expr *a = makeNode(A_Expr);
5252

5353
a->kind = kind;
54-
a->name = list_make1(makeString((char *) name));
54+
a->name = list_make1(makeString(name));
5555
a->lexpr = lexpr;
5656
a->rexpr = rexpr;
5757
a->location = location;

src/backend/storage/page/bufpage.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1502,7 +1502,7 @@ PageSetChecksumCopy(Page page, BlockNumber blkno)
15021502

15031503
/* If we don't need a checksum, just return the passed-in data */
15041504
if (PageIsNew(page) || !DataChecksumsEnabled())
1505-
return (char *) page;
1505+
return page;
15061506

15071507
/*
15081508
* We allocate the copy space once and use it over on each subsequent

src/backend/utils/cache/relmapper.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -854,7 +854,7 @@ read_relmap_file(RelMapFile *map, char *dbpath, bool lock_held, int elevel)
854854

855855
/* verify the CRC */
856856
INIT_CRC32C(crc);
857-
COMP_CRC32C(crc, (char *) map, offsetof(RelMapFile, crc));
857+
COMP_CRC32C(crc, map, offsetof(RelMapFile, crc));
858858
FIN_CRC32C(crc);
859859

860860
if (!EQ_CRC32C(crc, map->crc))
@@ -910,7 +910,7 @@ write_relmap_file(RelMapFile *newmap, bool write_wal, bool send_sinval,
910910
elog(ERROR, "attempt to write bogus relation mapping");
911911

912912
INIT_CRC32C(newmap->crc);
913-
COMP_CRC32C(newmap->crc, (char *) newmap, offsetof(RelMapFile, crc));
913+
COMP_CRC32C(newmap->crc, newmap, offsetof(RelMapFile, crc));
914914
FIN_CRC32C(newmap->crc);
915915

916916
/*

src/backend/utils/error/jsonlog.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ write_jsonlog(ErrorData *edata)
206206
/* Error severity */
207207
if (edata->elevel)
208208
appendJSONKeyValue(&buf, "error_severity",
209-
(char *) error_severity(edata->elevel), true);
209+
error_severity(edata->elevel), true);
210210

211211
/* SQL state code */
212212
if (edata->sqlerrcode)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy