Skip to content

Commit 827b406

Browse files
committed
Remove unnecessary (char *) casts [mem]
Remove (char *) casts around memory functions such as memcmp(), memcpy(), or memset() where the cast is useless. Since these functions don't take char * arguments anyway, these casts are at best complicated casts to (void *), about which see commit 7f798ac. 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 506183b commit 827b406

File tree

20 files changed

+44
-48
lines changed

20 files changed

+44
-48
lines changed

contrib/pg_trgm/trgm_gist.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ gtrgm_consistent(PG_FUNCTION_ARGS)
228228
if (cache == NULL ||
229229
cache->strategy != strategy ||
230230
VARSIZE(cache->query) != querysize ||
231-
memcmp((char *) cache->query, (char *) query, querysize) != 0)
231+
memcmp(cache->query, query, querysize) != 0)
232232
{
233233
gtrgm_consistent_cache *newcache;
234234
TrgmPackedGraph *graph = NULL;
@@ -284,12 +284,12 @@ gtrgm_consistent(PG_FUNCTION_ARGS)
284284
newcache->strategy = strategy;
285285
newcache->query = (text *)
286286
((char *) newcache + MAXALIGN(sizeof(gtrgm_consistent_cache)));
287-
memcpy((char *) newcache->query, (char *) query, querysize);
287+
memcpy(newcache->query, query, querysize);
288288
if (qtrg)
289289
{
290290
newcache->trigrams = (TRGM *)
291291
((char *) newcache->query + MAXALIGN(querysize));
292-
memcpy((char *) newcache->trigrams, (char *) qtrg, qtrgsize);
292+
memcpy((char *) newcache->trigrams, qtrg, qtrgsize);
293293
/* release qtrg in case it was made in fn_mcxt */
294294
pfree(qtrg);
295295
}

contrib/xml2/xpath.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -278,8 +278,8 @@ xpath_string(PG_FUNCTION_ARGS)
278278
/* We could try casting to string using the libxml function? */
279279

280280
xpath = (xmlChar *) palloc(pathsize + 9);
281-
memcpy((char *) xpath, "string(", 7);
282-
memcpy((char *) (xpath + 7), VARDATA_ANY(xpathsupp), pathsize);
281+
memcpy(xpath, "string(", 7);
282+
memcpy(xpath + 7, VARDATA_ANY(xpathsupp), pathsize);
283283
xpath[pathsize + 7] = ')';
284284
xpath[pathsize + 8] = '\0';
285285

src/backend/access/common/heaptuple.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -787,7 +787,7 @@ heap_copytuple(HeapTuple tuple)
787787
newTuple->t_self = tuple->t_self;
788788
newTuple->t_tableOid = tuple->t_tableOid;
789789
newTuple->t_data = (HeapTupleHeader) ((char *) newTuple + HEAPTUPLESIZE);
790-
memcpy((char *) newTuple->t_data, (char *) tuple->t_data, tuple->t_len);
790+
memcpy(newTuple->t_data, tuple->t_data, tuple->t_len);
791791
return newTuple;
792792
}
793793

@@ -813,7 +813,7 @@ heap_copytuple_with_tuple(HeapTuple src, HeapTuple dest)
813813
dest->t_self = src->t_self;
814814
dest->t_tableOid = src->t_tableOid;
815815
dest->t_data = (HeapTupleHeader) palloc(src->t_len);
816-
memcpy((char *) dest->t_data, (char *) src->t_data, src->t_len);
816+
memcpy(dest->t_data, src->t_data, src->t_len);
817817
}
818818

819819
/*
@@ -1097,7 +1097,7 @@ heap_copy_tuple_as_datum(HeapTuple tuple, TupleDesc tupleDesc)
10971097
* the given tuple came from disk, rather than from heap_form_tuple).
10981098
*/
10991099
td = (HeapTupleHeader) palloc(tuple->t_len);
1100-
memcpy((char *) td, (char *) tuple->t_data, tuple->t_len);
1100+
memcpy(td, tuple->t_data, tuple->t_len);
11011101

11021102
HeapTupleHeaderSetDatumLength(td, tuple->t_len);
11031103
HeapTupleHeaderSetTypeId(td, tupleDesc->tdtypeid);

src/backend/access/heap/heapam_xlog.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -480,11 +480,11 @@ heap_xlog_insert(XLogReaderState *record)
480480

481481
newlen = datalen - SizeOfHeapHeader;
482482
Assert(datalen > SizeOfHeapHeader && newlen <= MaxHeapTupleSize);
483-
memcpy((char *) &xlhdr, data, SizeOfHeapHeader);
483+
memcpy(&xlhdr, data, SizeOfHeapHeader);
484484
data += SizeOfHeapHeader;
485485

486486
htup = &tbuf.hdr;
487-
MemSet((char *) htup, 0, SizeofHeapTupleHeader);
487+
MemSet(htup, 0, SizeofHeapTupleHeader);
488488
/* PG73FORMAT: get bitmap [+ padding] [+ oid] + data */
489489
memcpy((char *) htup + SizeofHeapTupleHeader,
490490
data,
@@ -625,10 +625,10 @@ heap_xlog_multi_insert(XLogReaderState *record)
625625
newlen = xlhdr->datalen;
626626
Assert(newlen <= MaxHeapTupleSize);
627627
htup = &tbuf.hdr;
628-
MemSet((char *) htup, 0, SizeofHeapTupleHeader);
628+
MemSet(htup, 0, SizeofHeapTupleHeader);
629629
/* PG73FORMAT: get bitmap [+ padding] [+ oid] + data */
630630
memcpy((char *) htup + SizeofHeapTupleHeader,
631-
(char *) tupdata,
631+
tupdata,
632632
newlen);
633633
tupdata += newlen;
634634

@@ -854,14 +854,14 @@ heap_xlog_update(XLogReaderState *record, bool hot_update)
854854
recdata += sizeof(uint16);
855855
}
856856

857-
memcpy((char *) &xlhdr, recdata, SizeOfHeapHeader);
857+
memcpy(&xlhdr, recdata, SizeOfHeapHeader);
858858
recdata += SizeOfHeapHeader;
859859

860860
tuplen = recdata_end - recdata;
861861
Assert(tuplen <= MaxHeapTupleSize);
862862

863863
htup = &tbuf.hdr;
864-
MemSet((char *) htup, 0, SizeofHeapTupleHeader);
864+
MemSet(htup, 0, SizeofHeapTupleHeader);
865865

866866
/*
867867
* Reconstruct the new tuple using the prefix and/or suffix from the

src/backend/access/table/toast_helper.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ toast_tuple_init(ToastTupleContext *ttc)
7575
{
7676
if (ttc->ttc_isnull[i] ||
7777
!VARATT_IS_EXTERNAL_ONDISK(new_value) ||
78-
memcmp((char *) old_value, (char *) new_value,
78+
memcmp(old_value, new_value,
7979
VARSIZE_EXTERNAL(old_value)) != 0)
8080
{
8181
/*

src/backend/access/transam/xlog.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2089,7 +2089,7 @@ AdvanceXLInsertBuffer(XLogRecPtr upto, TimeLineID tli, bool opportunistic)
20892089
* Be sure to re-zero the buffer so that bytes beyond what we've
20902090
* written will look like zeroes and not valid XLOG records...
20912091
*/
2092-
MemSet((char *) NewPage, 0, XLOG_BLCKSZ);
2092+
MemSet(NewPage, 0, XLOG_BLCKSZ);
20932093

20942094
/*
20952095
* Fill the new page's header

src/backend/access/transam/xlogreader.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -794,7 +794,7 @@ XLogDecodeNextRecord(XLogReaderState *state, bool nonblocking)
794794
readOff = ReadPageInternal(state, targetPagePtr,
795795
pageHeaderSize + len);
796796

797-
memcpy(buffer, (char *) contdata, len);
797+
memcpy(buffer, contdata, len);
798798
buffer += len;
799799
gotlen += len;
800800

src/backend/bootstrap/bootstrap.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -463,8 +463,8 @@ boot_openrel(char *relname)
463463
{
464464
if (attrtypes[i] == NULL)
465465
attrtypes[i] = AllocateAttribute();
466-
memmove((char *) attrtypes[i],
467-
(char *) TupleDescAttr(boot_reldesc->rd_att, i),
466+
memmove(attrtypes[i],
467+
TupleDescAttr(boot_reldesc->rd_att, i),
468468
ATTRIBUTE_FIXED_PART_SIZE);
469469

470470
{

src/backend/libpq/be-secure-gssapi.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -641,7 +641,7 @@ secure_open_gssapi(Port *port)
641641
return -1;
642642
}
643643

644-
memcpy(PqGSSSendBuffer, (char *) &netlen, sizeof(uint32));
644+
memcpy(PqGSSSendBuffer, &netlen, sizeof(uint32));
645645
PqGSSSendLength += sizeof(uint32);
646646

647647
memcpy(PqGSSSendBuffer + PqGSSSendLength, output.value, output.length);

src/backend/replication/logical/decode.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1177,9 +1177,7 @@ DecodeMultiInsert(LogicalDecodingContext *ctx, XLogRecordBuffer *buf)
11771177

11781178
memset(header, 0, SizeofHeapTupleHeader);
11791179

1180-
memcpy((char *) tuple->t_data + SizeofHeapTupleHeader,
1181-
(char *) data,
1182-
datalen);
1180+
memcpy((char *) tuple->t_data + SizeofHeapTupleHeader, data, datalen);
11831181
header->t_infomask = xlhdr->t_infomask;
11841182
header->t_infomask2 = xlhdr->t_infomask2;
11851183
header->t_hoff = xlhdr->t_hoff;
@@ -1265,9 +1263,7 @@ DecodeXLogTuple(char *data, Size len, HeapTuple tuple)
12651263
tuple->t_tableOid = InvalidOid;
12661264

12671265
/* data is not stored aligned, copy to aligned storage */
1268-
memcpy((char *) &xlhdr,
1269-
data,
1270-
SizeOfHeapHeader);
1266+
memcpy(&xlhdr, data, SizeOfHeapHeader);
12711267

12721268
memset(header, 0, SizeofHeapTupleHeader);
12731269

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