Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
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

src/backend/storage/buffer/bufmgr.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2221,7 +2221,7 @@ ExtendBufferedRelShared(BufferManagerRelation bmr,
22212221
buf_block = BufHdrGetBlock(GetBufferDescriptor(buffers[i] - 1));
22222222

22232223
/* new buffers are zero-filled */
2224-
MemSet((char *) buf_block, 0, BLCKSZ);
2224+
MemSet(buf_block, 0, BLCKSZ);
22252225
}
22262226

22272227
/*

src/backend/storage/buffer/localbuf.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ ExtendBufferedRelLocal(BufferManagerRelation bmr,
338338
buf_block = LocalBufHdrGetBlock(buf_hdr);
339339

340340
/* new buffers are zero-filled */
341-
MemSet((char *) buf_block, 0, BLCKSZ);
341+
MemSet(buf_block, 0, BLCKSZ);
342342
}
343343

344344
first_block = smgrnblocks(bmr.smgr, fork);

src/backend/storage/file/fd.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -910,7 +910,7 @@ InitFileAccess(void)
910910
(errcode(ERRCODE_OUT_OF_MEMORY),
911911
errmsg("out of memory")));
912912

913-
MemSet((char *) &(VfdCache[0]), 0, sizeof(Vfd));
913+
MemSet(&(VfdCache[0]), 0, sizeof(Vfd));
914914
VfdCache->fd = VFD_CLOSED;
915915

916916
SizeVfdCache = 1;
@@ -1447,7 +1447,7 @@ AllocateVfd(void)
14471447
*/
14481448
for (i = SizeVfdCache; i < newCacheSize; i++)
14491449
{
1450-
MemSet((char *) &(VfdCache[i]), 0, sizeof(Vfd));
1450+
MemSet(&(VfdCache[i]), 0, sizeof(Vfd));
14511451
VfdCache[i].nextFree = i + 1;
14521452
VfdCache[i].fd = VFD_CLOSED;
14531453
}

src/backend/storage/page/bufpage.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ PageRestoreTempPage(Page tempPage, Page oldPage)
415415
Size pageSize;
416416

417417
pageSize = PageGetPageSize(tempPage);
418-
memcpy((char *) oldPage, (char *) tempPage, pageSize);
418+
memcpy(oldPage, tempPage, pageSize);
419419

420420
pfree(tempPage);
421421
}
@@ -1094,8 +1094,8 @@ PageIndexTupleDelete(Page page, OffsetNumber offnum)
10941094
((char *) &phdr->pd_linp[offidx + 1] - (char *) phdr);
10951095

10961096
if (nbytes > 0)
1097-
memmove((char *) &(phdr->pd_linp[offidx]),
1098-
(char *) &(phdr->pd_linp[offidx + 1]),
1097+
memmove(&(phdr->pd_linp[offidx]),
1098+
&(phdr->pd_linp[offidx + 1]),
10991099
nbytes);
11001100

11011101
/*
@@ -1516,7 +1516,7 @@ PageSetChecksumCopy(Page page, BlockNumber blkno)
15161516
PG_IO_ALIGN_SIZE,
15171517
0);
15181518

1519-
memcpy(pageCopy, (char *) page, BLCKSZ);
1519+
memcpy(pageCopy, page, BLCKSZ);
15201520
((PageHeader) pageCopy)->pd_checksum = pg_checksum_page(pageCopy, blkno);
15211521
return pageCopy;
15221522
}

src/backend/tcop/postgres.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4991,8 +4991,8 @@ ShowUsage(const char *title)
49914991

49924992
getrusage(RUSAGE_SELF, &r);
49934993
gettimeofday(&elapse_t, NULL);
4994-
memcpy((char *) &user, (char *) &r.ru_utime, sizeof(user));
4995-
memcpy((char *) &sys, (char *) &r.ru_stime, sizeof(sys));
4994+
memcpy(&user, &r.ru_utime, sizeof(user));
4995+
memcpy(&sys, &r.ru_stime, sizeof(sys));
49964996
if (elapse_t.tv_usec < Save_t.tv_usec)
49974997
{
49984998
elapse_t.tv_sec--;

src/backend/utils/activity/backend_status.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -597,7 +597,7 @@ pgstat_report_activity(BackendState state, const char *cmd_str)
597597

598598
if (cmd_str != NULL)
599599
{
600-
memcpy((char *) beentry->st_activity_raw, cmd_str, len);
600+
memcpy(beentry->st_activity_raw, cmd_str, len);
601601
beentry->st_activity_raw[len] = '\0';
602602
beentry->st_activity_start_timestamp = start_timestamp;
603603
}
@@ -670,7 +670,7 @@ pgstat_report_appname(const char *appname)
670670
*/
671671
PGSTAT_BEGIN_WRITE_ACTIVITY(beentry);
672672

673-
memcpy((char *) beentry->st_appname, appname, len);
673+
memcpy(beentry->st_appname, appname, len);
674674
beentry->st_appname[len] = '\0';
675675

676676
PGSTAT_END_WRITE_ACTIVITY(beentry);

src/interfaces/ecpg/compatlib/informix.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1035,7 +1035,7 @@ ECPG_informix_reset_sqlca(void)
10351035
if (sqlca == NULL)
10361036
return;
10371037

1038-
memcpy((char *) sqlca, (char *) &sqlca_init, sizeof(struct sqlca_t));
1038+
memcpy(sqlca, &sqlca_init, sizeof(struct sqlca_t));
10391039
}
10401040

10411041
int

src/interfaces/ecpg/ecpglib/misc.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ static FILE *debugstream = NULL;
6666
void
6767
ecpg_init_sqlca(struct sqlca_t *sqlca)
6868
{
69-
memcpy((char *) sqlca, (char *) &sqlca_init, sizeof(struct sqlca_t));
69+
memcpy(sqlca, &sqlca_init, sizeof(struct sqlca_t));
7070
}
7171

7272
bool
@@ -316,10 +316,10 @@ ECPGset_noind_null(enum ECPGttype type, void *ptr)
316316
*((long long *) ptr) = LONG_LONG_MIN;
317317
break;
318318
case ECPGt_float:
319-
memset((char *) ptr, 0xff, sizeof(float));
319+
memset(ptr, 0xff, sizeof(float));
320320
break;
321321
case ECPGt_double:
322-
memset((char *) ptr, 0xff, sizeof(double));
322+
memset(ptr, 0xff, sizeof(double));
323323
break;
324324
case ECPGt_varchar:
325325
*(((struct ECPGgeneric_varchar *) ptr)->arr) = 0x00;
@@ -329,18 +329,18 @@ ECPGset_noind_null(enum ECPGttype type, void *ptr)
329329
((struct ECPGgeneric_bytea *) ptr)->len = 0;
330330
break;
331331
case ECPGt_decimal:
332-
memset((char *) ptr, 0, sizeof(decimal));
332+
memset(ptr, 0, sizeof(decimal));
333333
((decimal *) ptr)->sign = NUMERIC_NULL;
334334
break;
335335
case ECPGt_numeric:
336-
memset((char *) ptr, 0, sizeof(numeric));
336+
memset(ptr, 0, sizeof(numeric));
337337
((numeric *) ptr)->sign = NUMERIC_NULL;
338338
break;
339339
case ECPGt_interval:
340-
memset((char *) ptr, 0xff, sizeof(interval));
340+
memset(ptr, 0xff, sizeof(interval));
341341
break;
342342
case ECPGt_timestamp:
343-
memset((char *) ptr, 0xff, sizeof(timestamp));
343+
memset(ptr, 0xff, sizeof(timestamp));
344344
break;
345345
default:
346346
break;

src/interfaces/libpq/fe-lobj.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -870,7 +870,7 @@ lo_initialize(PGconn *conn)
870870
libpq_append_conn_error(conn, "out of memory");
871871
return -1;
872872
}
873-
MemSet((char *) lobjfuncs, 0, sizeof(PGlobjfuncs));
873+
MemSet(lobjfuncs, 0, sizeof(PGlobjfuncs));
874874

875875
/*
876876
* Execute the query to get all the functions at once. (Not all of them

src/interfaces/libpq/fe-secure-gssapi.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -698,7 +698,7 @@ pqsecure_open_gss(PGconn *conn)
698698
/* Queue the token for writing */
699699
netlen = pg_hton32(output.length);
700700

701-
memcpy(PqGSSSendBuffer, (char *) &netlen, sizeof(uint32));
701+
memcpy(PqGSSSendBuffer, &netlen, sizeof(uint32));
702702
PqGSSSendLength += sizeof(uint32);
703703

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

0 commit comments

Comments
 (0)