Skip to content

Commit aa69541

Browse files
committed
Remove useless casts to (void *) in arguments of some system functions
The affected functions are: bsearch, memcmp, memcpy, memset, memmove, qsort, repalloc Reviewed-by: Corey Huinker <corey.huinker@gmail.com> Discussion: https://www.postgresql.org/message-id/flat/fd9adf5d-b1aa-e82f-e4c7-263c30145807%40enterprisedb.com
1 parent d9d7fe6 commit aa69541

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+116
-119
lines changed

contrib/btree_gist/btree_bit.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ gbt_bit_xfrm(bytea *leaf)
8484
while (sz < padded_sz)
8585
((char *) out)[sz++] = 0;
8686
SET_VARSIZE(out, padded_sz);
87-
memcpy((void *) VARDATA(out), (void *) VARBITS(leaf), VARBITBYTES(leaf));
87+
memcpy(VARDATA(out), VARBITS(leaf), VARBITBYTES(leaf));
8888
return out;
8989
}
9090

contrib/btree_gist/btree_interval.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,8 @@ gbt_intv_compress(PG_FUNCTION_ARGS)
157157
{
158158
Interval *key = DatumGetIntervalP(entry->key);
159159

160-
memcpy((void *) r, (void *) key, INTERVALSIZE);
161-
memcpy((void *) (r + INTERVALSIZE), (void *) key, INTERVALSIZE);
160+
memcpy(r, key, INTERVALSIZE);
161+
memcpy(r + INTERVALSIZE, key, INTERVALSIZE);
162162
}
163163
else
164164
{

contrib/btree_gist/btree_utils_num.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@ gbt_num_compress(GISTENTRY *entry, const gbtree_ninfo *tinfo)
8787

8888
Assert(tinfo->indexsize >= 2 * tinfo->size);
8989

90-
memcpy((void *) &r[0], leaf, tinfo->size);
91-
memcpy((void *) &r[tinfo->size], leaf, tinfo->size);
90+
memcpy(&r[0], leaf, tinfo->size);
91+
memcpy(&r[tinfo->size], leaf, tinfo->size);
9292
retval = palloc(sizeof(GISTENTRY));
9393
gistentryinit(*retval, PointerGetDatum(r), entry->rel, entry->page,
9494
entry->offset, false);
@@ -184,7 +184,7 @@ gbt_num_union(GBT_NUMKEY *out, const GistEntryVector *entryvec, const gbtree_nin
184184
o.lower = &((GBT_NUMKEY *) out)[0];
185185
o.upper = &((GBT_NUMKEY *) out)[tinfo->size];
186186

187-
memcpy((void *) out, (void *) cur, 2 * tinfo->size);
187+
memcpy(out, cur, 2 * tinfo->size);
188188

189189
for (i = 1; i < numranges; i++)
190190
{
@@ -360,7 +360,7 @@ gbt_num_picksplit(const GistEntryVector *entryvec, GIST_SPLITVEC *v,
360360
arr[i].t = (GBT_NUMKEY *) DatumGetPointer((entryvec->vector[i].key));
361361
arr[i].i = i;
362362
}
363-
qsort_arg((void *) &arr[FirstOffsetNumber], maxoff - FirstOffsetNumber + 1, sizeof(Nsrt), (qsort_arg_comparator) tinfo->f_cmp, (void *) flinfo);
363+
qsort_arg(&arr[FirstOffsetNumber], maxoff - FirstOffsetNumber + 1, sizeof(Nsrt), (qsort_arg_comparator) tinfo->f_cmp, flinfo);
364364

365365
/* We do simply create two parts */
366366

contrib/btree_gist/btree_utils_var.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -502,11 +502,11 @@ gbt_var_picksplit(const GistEntryVector *entryvec, GIST_SPLITVEC *v,
502502
varg.tinfo = tinfo;
503503
varg.collation = collation;
504504
varg.flinfo = flinfo;
505-
qsort_arg((void *) &arr[FirstOffsetNumber],
505+
qsort_arg(&arr[FirstOffsetNumber],
506506
maxoff - FirstOffsetNumber + 1,
507507
sizeof(Vsrt),
508508
gbt_vsrt_cmp,
509-
(void *) &varg);
509+
&varg);
510510

511511
/* We do simply create two parts */
512512

contrib/btree_gist/btree_uuid.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,8 @@ gbt_uuid_compress(PG_FUNCTION_ARGS)
110110

111111
retval = palloc(sizeof(GISTENTRY));
112112

113-
memcpy((void *) r, (void *) key, UUID_LEN);
114-
memcpy((void *) (r + UUID_LEN), (void *) key, UUID_LEN);
113+
memcpy(r, key, UUID_LEN);
114+
memcpy(r + UUID_LEN, key, UUID_LEN);
115115
gistentryinit(*retval, PointerGetDatum(r),
116116
entry->rel, entry->page,
117117
entry->offset, false);

contrib/citext/citext.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ internal_citext_pattern_cmp(text *left, text *right, Oid collid)
8080
llen = strlen(lcstr);
8181
rlen = strlen(rcstr);
8282

83-
result = memcmp((void *) lcstr, (void *) rcstr, Min(llen, rlen));
83+
result = memcmp(lcstr, rcstr, Min(llen, rlen));
8484
if (result == 0)
8585
{
8686
if (llen < rlen)

contrib/hstore/hstore_gist.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ ghstore_picksplit(PG_FUNCTION_ARGS)
436436
size_beta = hemdist(datum_r, _j, siglen);
437437
costvector[j - 1].cost = abs(size_alpha - size_beta);
438438
}
439-
qsort((void *) costvector, maxoff, sizeof(SPLITCOST), comparecost);
439+
qsort(costvector, maxoff, sizeof(SPLITCOST), comparecost);
440440

441441
union_l = GETSIGN(datum_l);
442442
union_r = GETSIGN(datum_r);
@@ -465,7 +465,7 @@ ghstore_picksplit(PG_FUNCTION_ARGS)
465465
if (ISALLTRUE(datum_l) || ISALLTRUE(_j))
466466
{
467467
if (!ISALLTRUE(datum_l))
468-
memset((void *) union_l, 0xff, siglen);
468+
memset(union_l, 0xff, siglen);
469469
}
470470
else
471471
{
@@ -481,7 +481,7 @@ ghstore_picksplit(PG_FUNCTION_ARGS)
481481
if (ISALLTRUE(datum_r) || ISALLTRUE(_j))
482482
{
483483
if (!ISALLTRUE(datum_r))
484-
memset((void *) union_r, 0xff, siglen);
484+
memset(union_r, 0xff, siglen);
485485
}
486486
else
487487
{

contrib/hstore/hstore_io.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ hstoreUniquePairs(Pairs *a, int32 l, int32 *buflen)
365365
return l;
366366
}
367367

368-
qsort((void *) a, l, sizeof(Pairs), comparePairs);
368+
qsort(a, l, sizeof(Pairs), comparePairs);
369369

370370
/*
371371
* We can't use qunique here because we have some clean-up code to run on

contrib/intarray/_int_gist.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ g_int_compress(PG_FUNCTION_ARGS)
243243
/*
244244
* shunt everything down to start at the right place
245245
*/
246-
memmove((void *) &dr[0], (void *) &dr[2 * j], 2 * (len - j) * sizeof(int32));
246+
memmove(&dr[0], &dr[2 * j], 2 * (len - j) * sizeof(int32));
247247
}
248248

249249
/*
@@ -260,7 +260,7 @@ g_int_compress(PG_FUNCTION_ARGS)
260260
min = ((int64) dr[i] - (int64) dr[i - 1]);
261261
cand = i;
262262
}
263-
memmove((void *) &dr[cand - 1], (void *) &dr[cand + 1], (len - cand - 1) * sizeof(int32));
263+
memmove(&dr[cand - 1], &dr[cand + 1], (len - cand - 1) * sizeof(int32));
264264
len -= 2;
265265
}
266266

@@ -542,7 +542,7 @@ g_int_picksplit(PG_FUNCTION_ARGS)
542542
pfree(union_d);
543543
costvector[i - 1].cost = fabsf((size_alpha - size_l) - (size_beta - size_r));
544544
}
545-
qsort((void *) costvector, maxoff, sizeof(SPLITCOST), comparecost);
545+
qsort(costvector, maxoff, sizeof(SPLITCOST), comparecost);
546546

547547
/*
548548
* Now split up the regions between the two seeds. An important property

contrib/intarray/_int_tool.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ isort(int32 *a, int len)
212212
{
213213
bool r = false;
214214

215-
qsort_arg(a, len, sizeof(int32), isort_cmp, (void *) &r);
215+
qsort_arg(a, len, sizeof(int32), isort_cmp, &r);
216216
return r;
217217
}
218218

contrib/intarray/_intbig_gist.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ g_intbig_picksplit(PG_FUNCTION_ARGS)
395395
size_beta = hemdist(datum_r, _j, siglen);
396396
costvector[j - 1].cost = abs(size_alpha - size_beta);
397397
}
398-
qsort((void *) costvector, maxoff, sizeof(SPLITCOST), comparecost);
398+
qsort(costvector, maxoff, sizeof(SPLITCOST), comparecost);
399399

400400
union_l = GETSIGN(datum_l);
401401
union_r = GETSIGN(datum_r);
@@ -424,7 +424,7 @@ g_intbig_picksplit(PG_FUNCTION_ARGS)
424424
if (ISALLTRUE(datum_l) || ISALLTRUE(_j))
425425
{
426426
if (!ISALLTRUE(datum_l))
427-
memset((void *) union_l, 0xff, siglen);
427+
memset(union_l, 0xff, siglen);
428428
}
429429
else
430430
{
@@ -440,7 +440,7 @@ g_intbig_picksplit(PG_FUNCTION_ARGS)
440440
if (ISALLTRUE(datum_r) || ISALLTRUE(_j))
441441
{
442442
if (!ISALLTRUE(datum_r))
443-
memset((void *) union_r, 0xff, siglen);
443+
memset(union_r, 0xff, siglen);
444444
}
445445
else
446446
{

contrib/ltree/_ltree_gist.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ _ltree_picksplit(PG_FUNCTION_ARGS)
319319
size_beta = hemdist(datum_r, _j, siglen);
320320
costvector[j - 1].cost = abs(size_alpha - size_beta);
321321
}
322-
qsort((void *) costvector, maxoff, sizeof(SPLITCOST), comparecost);
322+
qsort(costvector, maxoff, sizeof(SPLITCOST), comparecost);
323323

324324
union_l = LTG_SIGN(datum_l);
325325
union_r = LTG_SIGN(datum_r);
@@ -348,7 +348,7 @@ _ltree_picksplit(PG_FUNCTION_ARGS)
348348
if (LTG_ISALLTRUE(datum_l) || LTG_ISALLTRUE(_j))
349349
{
350350
if (!LTG_ISALLTRUE(datum_l))
351-
memset((void *) union_l, 0xff, siglen);
351+
memset(union_l, 0xff, siglen);
352352
}
353353
else
354354
{
@@ -364,7 +364,7 @@ _ltree_picksplit(PG_FUNCTION_ARGS)
364364
if (LTG_ISALLTRUE(datum_r) || LTG_ISALLTRUE(_j))
365365
{
366366
if (!LTG_ISALLTRUE(datum_r))
367-
memset((void *) union_r, 0xff, siglen);
367+
memset(union_r, 0xff, siglen);
368368
}
369369
else
370370
{

contrib/ltree/ltree_gist.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ ltree_picksplit(PG_FUNCTION_ARGS)
328328
array[j].r = LTG_GETLNODE(lu, siglen);
329329
}
330330

331-
qsort((void *) &array[FirstOffsetNumber], maxoff - FirstOffsetNumber + 1,
331+
qsort(&array[FirstOffsetNumber], maxoff - FirstOffsetNumber + 1,
332332
sizeof(RIX), treekey_cmp);
333333

334334
lu_l = lu_r = ru_l = ru_r = NULL;

contrib/ltree/ltxtquery_io.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -195,10 +195,10 @@ pushval_asis(QPRS_STATE *state, int type, char *strval, int lenval, uint16 flag)
195195
int32 tmp = state->curop - state->op;
196196

197197
state->lenop *= 2;
198-
state->op = (char *) repalloc((void *) state->op, state->lenop);
198+
state->op = (char *) repalloc(state->op, state->lenop);
199199
state->curop = state->op + tmp;
200200
}
201-
memcpy((void *) state->curop, (void *) strval, lenval);
201+
memcpy(state->curop, strval, lenval);
202202
state->curop += lenval;
203203
*(state->curop) = '\0';
204204
state->curop++;
@@ -391,7 +391,7 @@ queryin(char *buf, struct Node *escontext)
391391
}
392392

393393
/* set user-friendly operand view */
394-
memcpy((void *) GETOPERAND(query), (void *) state.op, state.sumlen);
394+
memcpy(GETOPERAND(query), state.op, state.sumlen);
395395
pfree(state.op);
396396

397397
/* set left operand's position for every operator */

contrib/pg_surgery/heap_surgery.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ heap_force_common(FunctionCallInfo fcinfo, HeapTupleForceOption heap_force_opt)
131131
* array.
132132
*/
133133
if (ntids > 1)
134-
qsort((void *) tids, ntids, sizeof(ItemPointerData), tidcmp);
134+
qsort(tids, ntids, sizeof(ItemPointerData), tidcmp);
135135

136136
curr_start_ptr = next_start_ptr = 0;
137137
nblocks = RelationGetNumberOfBlocks(rel);

contrib/pg_trgm/trgm_gist.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ makesign(BITVECP sign, TRGM *a, int siglen)
102102
trgm *ptr = GETARR(a);
103103
int32 tmp = 0;
104104

105-
MemSet((void *) sign, 0, siglen);
105+
MemSet(sign, 0, siglen);
106106
SETBIT(sign, SIGLENBIT(siglen)); /* set last unused bit */
107107
for (k = 0; k < len; k++)
108108
{
@@ -755,7 +755,7 @@ fillcache(CACHESIGN *item, TRGM *key, BITVECP sign, int siglen)
755755
else if (ISALLTRUE(key))
756756
item->allistrue = true;
757757
else
758-
memcpy((void *) item->sign, (void *) GETSIGN(key), siglen);
758+
memcpy(item->sign, GETSIGN(key), siglen);
759759
}
760760

761761
#define WISH_F(a,b,c) (double)( -(double)(((a)-(b))*((a)-(b))*((a)-(b)))*(c) )
@@ -872,7 +872,7 @@ gtrgm_picksplit(PG_FUNCTION_ARGS)
872872
size_beta = hemdistcache(&(cache[seed_2]), &(cache[j]), siglen);
873873
costvector[j - 1].cost = abs(size_alpha - size_beta);
874874
}
875-
qsort((void *) costvector, maxoff, sizeof(SPLITCOST), comparecost);
875+
qsort(costvector, maxoff, sizeof(SPLITCOST), comparecost);
876876

877877
for (k = 0; k < maxoff; k++)
878878
{
@@ -921,7 +921,7 @@ gtrgm_picksplit(PG_FUNCTION_ARGS)
921921
if (ISALLTRUE(datum_l) || cache[j].allistrue)
922922
{
923923
if (!ISALLTRUE(datum_l))
924-
memset((void *) GETSIGN(datum_l), 0xff, siglen);
924+
memset(GETSIGN(datum_l), 0xff, siglen);
925925
}
926926
else
927927
{
@@ -937,7 +937,7 @@ gtrgm_picksplit(PG_FUNCTION_ARGS)
937937
if (ISALLTRUE(datum_r) || cache[j].allistrue)
938938
{
939939
if (!ISALLTRUE(datum_r))
940-
memset((void *) GETSIGN(datum_r), 0xff, siglen);
940+
memset(GETSIGN(datum_r), 0xff, siglen);
941941
}
942942
else
943943
{

contrib/pg_trgm/trgm_op.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ generate_trgm(char *str, int slen)
376376
*/
377377
if (len > 1)
378378
{
379-
qsort((void *) GETARR(trg), len, sizeof(trgm), comp_trgm);
379+
qsort(GETARR(trg), len, sizeof(trgm), comp_trgm);
380380
len = qunique(GETARR(trg), len, sizeof(trgm), comp_trgm);
381381
}
382382

@@ -929,7 +929,7 @@ generate_wildcard_trgm(const char *str, int slen)
929929
*/
930930
if (len > 1)
931931
{
932-
qsort((void *) GETARR(trg), len, sizeof(trgm), comp_trgm);
932+
qsort(GETARR(trg), len, sizeof(trgm), comp_trgm);
933933
len = qunique(GETARR(trg), len, sizeof(trgm), comp_trgm);
934934
}
935935

doc/src/sgml/xfunc.sgml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2456,8 +2456,8 @@ copytext(PG_FUNCTION_ARGS)
24562456
* VARDATA is a pointer to the data region of the new struct. The source
24572457
* could be a short datum, so retrieve its data through VARDATA_ANY.
24582458
*/
2459-
memcpy((void *) VARDATA(new_t), /* destination */
2460-
(void *) VARDATA_ANY(t), /* source */
2459+
memcpy(VARDATA(new_t), /* destination */
2460+
VARDATA_ANY(t), /* source */
24612461
VARSIZE_ANY_EXHDR(t)); /* how many bytes */
24622462
PG_RETURN_TEXT_P(new_t);
24632463
}

src/backend/access/brin/brin_minmax_multi.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,7 @@ range_deduplicate_values(Ranges *range)
543543
*/
544544
qsort_arg(&range->values[start],
545545
range->nvalues, sizeof(Datum),
546-
compare_values, (void *) &cxt);
546+
compare_values, &cxt);
547547

548548
n = 1;
549549
for (i = 1; i < range->nvalues; i++)
@@ -1197,7 +1197,7 @@ sort_expanded_ranges(FmgrInfo *cmp, Oid colloid,
11971197
* some of the points) and do merge sort.
11981198
*/
11991199
qsort_arg(eranges, neranges, sizeof(ExpandedRange),
1200-
compare_expanded_ranges, (void *) &cxt);
1200+
compare_expanded_ranges, &cxt);
12011201

12021202
/*
12031203
* Deduplicate the ranges - simply compare each range to the preceding
@@ -1535,7 +1535,7 @@ reduce_expanded_ranges(ExpandedRange *eranges, int neranges,
15351535
* sorted result.
15361536
*/
15371537
qsort_arg(values, nvalues, sizeof(Datum),
1538-
compare_values, (void *) &cxt);
1538+
compare_values, &cxt);
15391539

15401540
/* We have nvalues boundary values, which means nvalues/2 ranges. */
15411541
for (i = 0; i < (nvalues / 2); i++)

src/backend/access/gin/ginutil.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,7 @@ ginExtractEntries(GinState *ginstate, OffsetNumber attnum,
560560
arg.collation = ginstate->supportCollation[attnum - 1];
561561
arg.haveDups = false;
562562
qsort_arg(keydata, *nentries, sizeof(keyEntryData),
563-
cmpEntries, (void *) &arg);
563+
cmpEntries, &arg);
564564

565565
if (arg.haveDups)
566566
{

src/backend/access/gist/gistproc.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ gist_box_union(PG_FUNCTION_ARGS)
173173
numranges = entryvec->n;
174174
pageunion = (BOX *) palloc(sizeof(BOX));
175175
cur = DatumGetBoxP(entryvec->vector[0].key);
176-
memcpy((void *) pageunion, (void *) cur, sizeof(BOX));
176+
memcpy(pageunion, cur, sizeof(BOX));
177177

178178
for (i = 1; i < numranges; i++)
179179
{
@@ -1043,7 +1043,7 @@ gist_poly_compress(PG_FUNCTION_ARGS)
10431043
BOX *r;
10441044

10451045
r = (BOX *) palloc(sizeof(BOX));
1046-
memcpy((void *) r, (void *) &(in->boundbox), sizeof(BOX));
1046+
memcpy(r, &(in->boundbox), sizeof(BOX));
10471047

10481048
retval = (GISTENTRY *) palloc(sizeof(GISTENTRY));
10491049
gistentryinit(*retval, PointerGetDatum(r),

src/backend/access/gist/gistutil.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ gistextractpage(Page page, int *len /* out */ )
113113
IndexTuple *
114114
gistjoinvector(IndexTuple *itvec, int *len, IndexTuple *additvec, int addlen)
115115
{
116-
itvec = (IndexTuple *) repalloc((void *) itvec, sizeof(IndexTuple) * ((*len) + addlen));
116+
itvec = (IndexTuple *) repalloc(itvec, sizeof(IndexTuple) * ((*len) + addlen));
117117
memmove(&itvec[*len], additvec, sizeof(IndexTuple) * addlen);
118118
*len += addlen;
119119
return itvec;

src/backend/access/nbtree/nbtutils.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -488,8 +488,8 @@ _bt_sort_array_elements(IndexScanDesc scan, ScanKey skey,
488488
fmgr_info(cmp_proc, &cxt.flinfo);
489489
cxt.collation = skey->sk_collation;
490490
cxt.reverse = reverse;
491-
qsort_arg((void *) elems, nelems, sizeof(Datum),
492-
_bt_compare_array_elements, (void *) &cxt);
491+
qsort_arg(elems, nelems, sizeof(Datum),
492+
_bt_compare_array_elements, &cxt);
493493

494494
/* Now scan the sorted elements and remove duplicates */
495495
return qunique_arg(elems, nelems, sizeof(Datum),

0 commit comments

Comments
 (0)