Thread
-
[PATCH v1 2/2] Use sizeof(*var) for type safe allocation formulas
Bertrand Drouvot <bertranddrouvot.pg@gmail.com> — 2025-12-11T09:50:08Z
It makes the code more maintainable (type changes automatically update allocation) and less error prone (as seen recently in 3f83de20ba2 and 06761b6096b). --- contrib/btree_gist/btree_utils_num.c | 2 +- contrib/btree_gist/btree_utils_var.c | 4 +- contrib/file_fdw/file_fdw.c | 4 +- contrib/hstore/hstore_gin.c | 4 +- contrib/hstore/hstore_io.c | 16 +- contrib/hstore/hstore_op.c | 14 +- contrib/hstore_plperl/hstore_plperl.c | 2 +- contrib/oid2name/oid2name.c | 10 +- contrib/pageinspect/btreefuncs.c | 2 +- contrib/pageinspect/ginfuncs.c | 2 +- contrib/pg_logicalinspect/pg_logicalinspect.c | 4 +- .../pg_stat_statements/pg_stat_statements.c | 2 +- contrib/pg_trgm/trgm_gist.c | 2 +- contrib/pg_trgm/trgm_regexp.c | 4 +- contrib/pgcrypto/pgp-armor.c | 4 +- contrib/pgrowlocks/pgrowlocks.c | 8 +- contrib/postgres_fdw/postgres_fdw.c | 8 +- contrib/seg/seg.c | 6 +- contrib/spi/autoinc.c | 6 +- contrib/spi/refint.c | 8 +- contrib/tablefunc/tablefunc.c | 8 +- contrib/xml2/xpath.c | 4 +- src/backend/access/brin/brin_minmax_multi.c | 4 +- src/backend/access/common/printtup.c | 2 +- src/backend/access/common/reloptions.c | 4 +- src/backend/access/common/tupdesc.c | 4 +- src/backend/access/gin/gindatapage.c | 4 +- src/backend/access/gin/ginget.c | 8 +- src/backend/access/gin/gininsert.c | 2 +- src/backend/access/gin/ginpostinglist.c | 2 +- src/backend/access/gin/ginscan.c | 4 +- src/backend/access/gin/ginutil.c | 4 +- src/backend/access/gist/gistget.c | 4 +- src/backend/access/gist/gistproc.c | 10 +- src/backend/access/gist/gistscan.c | 6 +- src/backend/access/gist/gistsplit.c | 12 +- src/backend/access/gist/gistxlog.c | 2 +- src/backend/access/heap/heapam.c | 4 +- src/backend/access/heap/vacuumlazy.c | 2 +- src/backend/access/nbtree/nbtinsert.c | 4 +- src/backend/access/nbtree/nbtpreprocesskeys.c | 10 +- src/backend/access/transam/multixact.c | 2 +- src/backend/access/transam/twophase.c | 2 +- src/backend/access/transam/xact.c | 2 +- src/backend/backup/basebackup_incremental.c | 2 +- src/backend/catalog/aclchk.c | 2 +- src/backend/catalog/dependency.c | 2 +- src/backend/catalog/heap.c | 2 +- src/backend/catalog/namespace.c | 2 +- src/backend/catalog/pg_constraint.c | 6 +- src/backend/catalog/pg_inherits.c | 2 +- src/backend/catalog/pg_shdepend.c | 2 +- src/backend/commands/alter.c | 18 +- src/backend/commands/analyze.c | 44 ++--- src/backend/commands/async.c | 4 +- src/backend/commands/collationcmds.c | 2 +- src/backend/commands/copyfrom.c | 18 +- src/backend/commands/copyto.c | 4 +- src/backend/commands/dbcommands.c | 2 +- src/backend/commands/explain.c | 6 +- src/backend/commands/explain_dr.c | 2 +- src/backend/commands/explain_state.c | 2 +- src/backend/commands/extension.c | 2 +- src/backend/commands/functioncmds.c | 14 +- src/backend/commands/policy.c | 2 +- src/backend/commands/subscriptioncmds.c | 6 +- src/backend/commands/tablecmds.c | 4 +- src/backend/commands/tablespace.c | 2 +- src/backend/commands/trigger.c | 14 +- src/backend/commands/vacuum.c | 2 +- src/backend/executor/execExprInterp.c | 12 +- src/backend/executor/execGrouping.c | 6 +- src/backend/executor/execJunk.c | 4 +- src/backend/executor/execParallel.c | 2 +- src/backend/executor/execSRF.c | 4 +- src/backend/executor/execTuples.c | 10 +- src/backend/executor/execUtils.c | 4 +- src/backend/executor/functions.c | 2 +- src/backend/executor/instrument.c | 2 +- src/backend/executor/nodeAgg.c | 18 +- src/backend/executor/nodeAppend.c | 6 +- src/backend/executor/nodeBitmapAnd.c | 2 +- src/backend/executor/nodeBitmapOr.c | 2 +- src/backend/executor/nodeGatherMerge.c | 2 +- src/backend/executor/nodeIncrementalSort.c | 2 +- src/backend/executor/nodeIndexscan.c | 16 +- src/backend/executor/nodeMemoize.c | 6 +- src/backend/executor/nodeModifyTable.c | 2 +- src/backend/executor/nodeSubplan.c | 14 +- src/backend/executor/nodeTidscan.c | 2 +- src/backend/executor/nodeValuesscan.c | 4 +- src/backend/jit/llvm/llvmjit_expr.c | 2 +- src/backend/lib/bipartite_match.c | 8 +- src/backend/lib/knapsack.c | 4 +- src/backend/libpq/auth.c | 2 +- src/backend/libpq/hba.c | 4 +- src/backend/nodes/queryjumblefuncs.c | 2 +- src/backend/nodes/readfuncs.c | 2 +- src/backend/optimizer/path/allpaths.c | 4 +- src/backend/optimizer/path/equivclass.c | 2 +- src/backend/optimizer/path/pathkeys.c | 4 +- src/backend/optimizer/plan/createplan.c | 46 ++--- src/backend/optimizer/plan/planner.c | 22 +-- src/backend/optimizer/prep/prepjointree.c | 10 +- src/backend/optimizer/util/appendinfo.c | 2 +- src/backend/optimizer/util/clauses.c | 4 +- src/backend/parser/analyze.c | 4 +- src/backend/parser/parse_clause.c | 2 +- src/backend/parser/parse_cte.c | 2 +- src/backend/parser/parse_relation.c | 4 +- src/backend/partitioning/partbounds.c | 20 +-- src/backend/partitioning/partdesc.c | 10 +- src/backend/partitioning/partprune.c | 10 +- src/backend/port/posix_sema.c | 2 +- src/backend/port/sysv_sema.c | 2 +- src/backend/port/win32_sema.c | 2 +- src/backend/postmaster/autovacuum.c | 2 +- src/backend/postmaster/checkpointer.c | 2 +- src/backend/postmaster/pmchild.c | 2 +- src/backend/postmaster/postmaster.c | 2 +- src/backend/regex/regc_pg_locale.c | 2 +- src/backend/replication/logical/proto.c | 2 +- .../replication/logical/reorderbuffer.c | 2 +- src/backend/replication/logical/snapbuild.c | 2 +- src/backend/replication/logical/tablesync.c | 4 +- src/backend/replication/logical/worker.c | 8 +- src/backend/replication/pgoutput/pgoutput.c | 2 +- src/backend/rewrite/rewriteHandler.c | 4 +- src/backend/statistics/extended_stats.c | 10 +- src/backend/statistics/mcv.c | 4 +- src/backend/statistics/mvdistinct.c | 2 +- src/backend/storage/file/fd.c | 6 +- src/backend/storage/ipc/procarray.c | 10 +- src/backend/storage/lmgr/deadlock.c | 16 +- src/backend/storage/lmgr/lock.c | 2 +- src/backend/tcop/fastpath.c | 2 +- src/backend/tsearch/wparser_def.c | 2 +- src/backend/utils/activity/pgstat_xact.c | 2 +- src/backend/utils/adt/acl.c | 2 +- src/backend/utils/adt/array_typanalyze.c | 4 +- src/backend/utils/adt/arrayfuncs.c | 20 +-- src/backend/utils/adt/arrayutils.c | 2 +- src/backend/utils/adt/enum.c | 2 +- src/backend/utils/adt/formatting.c | 8 +- src/backend/utils/adt/jsonfuncs.c | 8 +- src/backend/utils/adt/levenshtein.c | 4 +- src/backend/utils/adt/lockfuncs.c | 6 +- src/backend/utils/adt/multirangetypes.c | 10 +- src/backend/utils/adt/name.c | 2 +- src/backend/utils/adt/numeric.c | 8 +- src/backend/utils/adt/oracle_compat.c | 4 +- src/backend/utils/adt/orderedsetaggs.c | 20 +-- src/backend/utils/adt/pg_ndistinct.c | 2 +- src/backend/utils/adt/rangetypes_typanalyze.c | 4 +- src/backend/utils/adt/rowtypes.c | 32 ++-- src/backend/utils/adt/ruleutils.c | 20 +-- src/backend/utils/adt/selfuncs.c | 4 +- src/backend/utils/adt/tsquery_cleanup.c | 2 +- src/backend/utils/adt/tsquery_rewrite.c | 2 +- src/backend/utils/adt/tsvector_op.c | 10 +- src/backend/utils/adt/varlena.c | 6 +- src/backend/utils/adt/xml.c | 4 +- src/backend/utils/cache/catcache.c | 2 +- src/backend/utils/cache/inval.c | 2 +- src/backend/utils/cache/lsyscache.c | 2 +- src/backend/utils/cache/relcache.c | 4 +- src/backend/utils/cache/typcache.c | 2 +- src/backend/utils/fmgr/funcapi.c | 22 +-- src/backend/utils/misc/ps_status.c | 4 +- src/backend/utils/sort/logtape.c | 2 +- src/backend/utils/sort/tuplesort.c | 8 +- src/backend/utils/sort/tuplestore.c | 4 +- src/backend/utils/time/snapmgr.c | 4 +- src/bin/initdb/initdb.c | 4 +- src/bin/pg_amcheck/pg_amcheck.c | 6 +- src/bin/pg_basebackup/pg_basebackup.c | 4 +- src/bin/pg_basebackup/walmethods.c | 12 +- src/bin/pg_combinebackup/load_manifest.c | 2 +- src/bin/pg_combinebackup/pg_combinebackup.c | 6 +- src/bin/pg_combinebackup/reconstruct.c | 10 +- src/bin/pg_combinebackup/write_manifest.c | 2 +- src/bin/pg_ctl/pg_ctl.c | 4 +- src/bin/pg_dump/compress_gzip.c | 2 +- src/bin/pg_dump/compress_io.c | 4 +- src/bin/pg_dump/compress_none.c | 2 +- src/bin/pg_dump/dumputils.c | 6 +- src/bin/pg_dump/parallel.c | 10 +- src/bin/pg_dump/pg_backup_archiver.c | 30 ++-- src/bin/pg_dump/pg_backup_custom.c | 6 +- src/bin/pg_dump/pg_backup_directory.c | 6 +- src/bin/pg_dump/pg_dump.c | 166 +++++++++--------- src/bin/pg_dump/pg_dump_sort.c | 12 +- src/bin/pg_dump/pg_dumpall.c | 2 +- src/bin/pg_rewind/datapagemap.c | 2 +- src/bin/pg_rewind/libpq_source.c | 2 +- src/bin/pg_rewind/local_source.c | 2 +- src/bin/pg_rewind/pg_rewind.c | 2 +- src/bin/pg_rewind/timeline.c | 2 +- src/bin/pg_upgrade/check.c | 4 +- src/bin/pg_upgrade/function.c | 4 +- src/bin/pg_upgrade/info.c | 10 +- src/bin/pg_upgrade/parallel.c | 12 +- src/bin/pg_upgrade/tablespace.c | 4 +- src/bin/pg_upgrade/task.c | 4 +- src/bin/pg_verifybackup/astreamer_verify.c | 2 +- src/bin/pg_verifybackup/pg_verifybackup.c | 8 +- src/bin/pgbench/pgbench.c | 14 +- src/bin/psql/command.c | 2 +- src/bin/psql/copy.c | 2 +- src/bin/psql/crosstabview.c | 10 +- src/bin/psql/describe.c | 2 +- src/bin/psql/tab-complete.in.c | 4 +- src/bin/scripts/reindexdb.c | 6 +- src/bin/scripts/vacuuming.c | 2 +- src/common/blkreftable.c | 2 +- src/fe_utils/conditional.c | 2 +- src/fe_utils/print.c | 4 +- src/fe_utils/simple_list.c | 4 +- src/interfaces/ecpg/ecpglib/misc.c | 2 +- src/interfaces/libpq/fe-auth-scram.c | 2 +- src/interfaces/libpq/fe-auth.c | 2 +- src/interfaces/libpq/fe-connect.c | 6 +- src/interfaces/libpq/fe-exec.c | 6 +- src/interfaces/libpq/fe-lobj.c | 2 +- src/interfaces/libpq/fe-print.c | 2 +- src/interfaces/libpq/fe-protocol3.c | 4 +- src/interfaces/libpq/libpq-events.c | 2 +- src/pl/plperl/plperl.c | 22 +-- src/pl/plpython/plpy_cursorobject.c | 4 +- src/pl/plpython/plpy_exec.c | 6 +- src/pl/plpython/plpy_spi.c | 4 +- src/pl/tcl/pltcl.c | 14 +- src/port/dirent.c | 2 +- src/timezone/localtime.c | 2 +- 234 files changed, 755 insertions(+), 755 deletions(-) 7.6% contrib/ 6.4% src/backend/access/ 10.0% src/backend/commands/ 8.4% src/backend/executor/ 4.7% src/backend/optimizer/plan/ 12.3% src/backend/utils/adt/ 3.7% src/backend/utils/ 14.3% src/backend/ 17.0% src/bin/pg_dump/ 9.5% src/bin/ 3.0% src/pl/ diff --git a/contrib/btree_gist/btree_utils_num.c b/contrib/btree_gist/btree_utils_num.c index 51c8836f27a..946a1bc2326 100644 --- a/contrib/btree_gist/btree_utils_num.c +++ b/contrib/btree_gist/btree_utils_num.c @@ -344,7 +344,7 @@ gbt_num_picksplit(const GistEntryVector *entryvec, GIST_SPLITVEC *v, Nsrt *arr; int nbytes; - arr = (Nsrt *) palloc((maxoff + 1) * sizeof(Nsrt)); + arr = (Nsrt *) palloc((maxoff + 1) * sizeof(*arr)); nbytes = (maxoff + 2) * sizeof(OffsetNumber); v->spl_left = (OffsetNumber *) palloc(nbytes); v->spl_right = (OffsetNumber *) palloc(nbytes); diff --git a/contrib/btree_gist/btree_utils_var.c b/contrib/btree_gist/btree_utils_var.c index c2d192d424e..0b16584aeae 100644 --- a/contrib/btree_gist/btree_utils_var.c +++ b/contrib/btree_gist/btree_utils_var.c @@ -467,7 +467,7 @@ gbt_var_picksplit(const GistEntryVector *entryvec, GIST_SPLITVEC *v, GBT_VARKEY **sv = NULL; gbt_vsrt_arg varg; - arr = (Vsrt *) palloc((maxoff + 1) * sizeof(Vsrt)); + arr = (Vsrt *) palloc((maxoff + 1) * sizeof(*arr)); nbytes = (maxoff + 2) * sizeof(OffsetNumber); v->spl_left = (OffsetNumber *) palloc(nbytes); v->spl_right = (OffsetNumber *) palloc(nbytes); @@ -476,7 +476,7 @@ gbt_var_picksplit(const GistEntryVector *entryvec, GIST_SPLITVEC *v, v->spl_nleft = 0; v->spl_nright = 0; - sv = palloc(sizeof(GBT_VARKEY *) * (maxoff + 1)); + sv = palloc(sizeof(*sv) * (maxoff + 1)); /* Sort entries */ diff --git a/contrib/file_fdw/file_fdw.c b/contrib/file_fdw/file_fdw.c index e9cda3c47d1..dd85f097112 100644 --- a/contrib/file_fdw/file_fdw.c +++ b/contrib/file_fdw/file_fdw.c @@ -1206,8 +1206,8 @@ file_acquire_sample_rows(Relation onerel, int elevel, Assert(targrows > 0); tupDesc = RelationGetDescr(onerel); - values = (Datum *) palloc(tupDesc->natts * sizeof(Datum)); - nulls = (bool *) palloc(tupDesc->natts * sizeof(bool)); + values = (Datum *) palloc(tupDesc->natts * sizeof(*values)); + nulls = (bool *) palloc(tupDesc->natts * sizeof(*nulls)); /* Fetch options of foreign table */ fileGetOptions(RelationGetRelid(onerel), &filename, &is_program, &options); diff --git a/contrib/hstore/hstore_gin.c b/contrib/hstore/hstore_gin.c index 2e5fa115924..be3734b5520 100644 --- a/contrib/hstore/hstore_gin.c +++ b/contrib/hstore/hstore_gin.c @@ -103,7 +103,7 @@ gin_extract_hstore_query(PG_FUNCTION_ARGS) text *item; *nentries = 1; - entries = (Datum *) palloc(sizeof(Datum)); + entries = (Datum *) palloc(sizeof(*entries)); item = makeitem(VARDATA_ANY(query), VARSIZE_ANY_EXHDR(query), KEYFLAG); entries[0] = PointerGetDatum(item); } @@ -120,7 +120,7 @@ gin_extract_hstore_query(PG_FUNCTION_ARGS) deconstruct_array_builtin(query, TEXTOID, &key_datums, &key_nulls, &key_count); - entries = (Datum *) palloc(sizeof(Datum) * key_count); + entries = (Datum *) palloc(sizeof(*entries) * key_count); for (i = 0, j = 0; i < key_count; ++i) { diff --git a/contrib/hstore/hstore_io.c b/contrib/hstore/hstore_io.c index 34e3918811c..acff50c029c 100644 --- a/contrib/hstore/hstore_io.c +++ b/contrib/hstore/hstore_io.c @@ -522,7 +522,7 @@ hstore_recv(PG_FUNCTION_ARGS) (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED), errmsg("number of pairs (%d) exceeds the maximum allowed (%d)", pcount, (int) (MaxAllocSize / sizeof(Pairs))))); - pairs = palloc(pcount * sizeof(Pairs)); + pairs = palloc(pcount * sizeof(*pairs)); for (i = 0; i < pcount; ++i) { @@ -673,7 +673,7 @@ hstore_from_arrays(PG_FUNCTION_ARGS) Assert(key_count == value_count); } - pairs = palloc(key_count * sizeof(Pairs)); + pairs = palloc(key_count * sizeof(*pairs)); for (i = 0; i < key_count; ++i) { @@ -767,7 +767,7 @@ hstore_from_array(PG_FUNCTION_ARGS) errmsg("number of pairs (%d) exceeds the maximum allowed (%d)", count, (int) (MaxAllocSize / sizeof(Pairs))))); - pairs = palloc(count * sizeof(Pairs)); + pairs = palloc(count * sizeof(*pairs)); for (i = 0; i < count; ++i) { @@ -908,7 +908,7 @@ hstore_from_record(PG_FUNCTION_ARGS) } Assert(ncolumns <= MaxTupleAttributeNumber); /* thus, no overflow */ - pairs = palloc(ncolumns * sizeof(Pairs)); + pairs = palloc(ncolumns * sizeof(*pairs)); if (rec) { @@ -918,8 +918,8 @@ hstore_from_record(PG_FUNCTION_ARGS) tuple.t_tableOid = InvalidOid; tuple.t_data = rec; - values = (Datum *) palloc(ncolumns * sizeof(Datum)); - nulls = (bool *) palloc(ncolumns * sizeof(bool)); + values = (Datum *) palloc(ncolumns * sizeof(*values)); + nulls = (bool *) palloc(ncolumns * sizeof(*nulls)); /* Break down the tuple into fields */ heap_deform_tuple(&tuple, tupdesc, values, nulls); @@ -1101,8 +1101,8 @@ hstore_populate_record(PG_FUNCTION_ARGS) my_extra->ncolumns = ncolumns; } - values = (Datum *) palloc(ncolumns * sizeof(Datum)); - nulls = (bool *) palloc(ncolumns * sizeof(bool)); + values = (Datum *) palloc(ncolumns * sizeof(*values)); + nulls = (bool *) palloc(ncolumns * sizeof(*nulls)); if (rec) { diff --git a/contrib/hstore/hstore_op.c b/contrib/hstore/hstore_op.c index bcba75f9258..19ee61dedf9 100644 --- a/contrib/hstore/hstore_op.c +++ b/contrib/hstore/hstore_op.c @@ -101,7 +101,7 @@ hstoreArrayToPairs(ArrayType *a, int *npairs) errmsg("number of pairs (%d) exceeds the maximum allowed (%d)", key_count, (int) (MaxAllocSize / sizeof(Pairs))))); - key_pairs = palloc(sizeof(Pairs) * key_count); + key_pairs = palloc(sizeof(*key_pairs) * key_count); for (i = 0, j = 0; i < key_count; i++) { @@ -588,8 +588,8 @@ hstore_slice_to_array(PG_FUNCTION_ARGS) PG_RETURN_POINTER(aout); } - out_datums = palloc(sizeof(Datum) * key_count); - out_nulls = palloc(sizeof(bool) * key_count); + out_datums = palloc(sizeof(*out_datums) * key_count); + out_nulls = palloc(sizeof(*out_nulls) * key_count); for (i = 0; i < key_count; ++i) { @@ -649,7 +649,7 @@ hstore_slice_to_hstore(PG_FUNCTION_ARGS) } /* hstoreArrayToPairs() checked overflow */ - out_pairs = palloc(sizeof(Pairs) * nkeys); + out_pairs = palloc(sizeof(*out_pairs) * nkeys); bufsiz = 0; /* @@ -705,7 +705,7 @@ hstore_akeys(PG_FUNCTION_ARGS) PG_RETURN_POINTER(a); } - d = (Datum *) palloc(sizeof(Datum) * count); + d = (Datum *) palloc(sizeof(*d) * count); for (i = 0; i < count; ++i) { @@ -741,8 +741,8 @@ hstore_avals(PG_FUNCTION_ARGS) PG_RETURN_POINTER(a); } - d = (Datum *) palloc(sizeof(Datum) * count); - nulls = (bool *) palloc(sizeof(bool) * count); + d = (Datum *) palloc(sizeof(*d) * count); + nulls = (bool *) palloc(sizeof(*nulls) * count); for (i = 0; i < count; ++i) { diff --git a/contrib/hstore_plperl/hstore_plperl.c b/contrib/hstore_plperl/hstore_plperl.c index 31393b4fa50..ebef6422d77 100644 --- a/contrib/hstore_plperl/hstore_plperl.c +++ b/contrib/hstore_plperl/hstore_plperl.c @@ -121,7 +121,7 @@ plperl_to_hstore(PG_FUNCTION_ARGS) pcount = hv_iterinit(hv); - pairs = palloc(pcount * sizeof(Pairs)); + pairs = palloc(pcount * sizeof(*pairs)); i = 0; while ((he = hv_iternext(hv))) diff --git a/contrib/oid2name/oid2name.c b/contrib/oid2name/oid2name.c index 51802907138..2b155648d9f 100644 --- a/contrib/oid2name/oid2name.c +++ b/contrib/oid2name/oid2name.c @@ -400,7 +400,7 @@ sql_exec(PGconn *conn, const char *todo, bool quiet) nfields = PQnfields(res); /* for each field, get the needed width */ - length = (int *) pg_malloc(sizeof(int) * nfields); + length = (int *) pg_malloc(sizeof(*length) * nfields); for (j = 0; j < nfields; j++) length[j] = strlen(PQfname(res, j)); @@ -585,11 +585,11 @@ main(int argc, char **argv) struct options *my_opts; PGconn *pgconn; - my_opts = (struct options *) pg_malloc(sizeof(struct options)); + my_opts = (struct options *) pg_malloc(sizeof(*my_opts)); - my_opts->oids = (eary *) pg_malloc(sizeof(eary)); - my_opts->tables = (eary *) pg_malloc(sizeof(eary)); - my_opts->filenumbers = (eary *) pg_malloc(sizeof(eary)); + my_opts->oids = (eary *) pg_malloc(sizeof(*my_opts->oids)); + my_opts->tables = (eary *) pg_malloc(sizeof(*my_opts->tables)); + my_opts->filenumbers = (eary *) pg_malloc(sizeof(*my_opts->filenumbers)); my_opts->oids->num = my_opts->oids->alloc = 0; my_opts->tables->num = my_opts->tables->alloc = 0; diff --git a/contrib/pageinspect/btreefuncs.c b/contrib/pageinspect/btreefuncs.c index 62c905c6e7c..ac9a3f947cf 100644 --- a/contrib/pageinspect/btreefuncs.c +++ b/contrib/pageinspect/btreefuncs.c @@ -597,7 +597,7 @@ bt_page_print_tuples(ua_page_items *uargs) tids = BTreeTupleGetPosting(itup); nposting = BTreeTupleGetNPosting(itup); - tids_datum = (Datum *) palloc(nposting * sizeof(Datum)); + tids_datum = (Datum *) palloc(nposting * sizeof(*tids_datum)); for (int i = 0; i < nposting; i++) tids_datum[i] = ItemPointerGetDatum(&tids[i]); values[j++] = PointerGetDatum(construct_array_builtin(tids_datum, nposting, TIDOID)); diff --git a/contrib/pageinspect/ginfuncs.c b/contrib/pageinspect/ginfuncs.c index f6168d8e895..b242596c2c7 100644 --- a/contrib/pageinspect/ginfuncs.c +++ b/contrib/pageinspect/ginfuncs.c @@ -262,7 +262,7 @@ gin_leafpage_items(PG_FUNCTION_ARGS) /* build an array of decoded item pointers */ tids = ginPostingListDecode(cur, &ndecoded); - tids_datum = (Datum *) palloc(ndecoded * sizeof(Datum)); + tids_datum = (Datum *) palloc(ndecoded * sizeof(*tids_datum)); for (i = 0; i < ndecoded; i++) tids_datum[i] = ItemPointerGetDatum(&tids[i]); values[2] = PointerGetDatum(construct_array_builtin(tids_datum, ndecoded, TIDOID)); diff --git a/contrib/pg_logicalinspect/pg_logicalinspect.c b/contrib/pg_logicalinspect/pg_logicalinspect.c index 50e805d3195..2c6c9a0d69f 100644 --- a/contrib/pg_logicalinspect/pg_logicalinspect.c +++ b/contrib/pg_logicalinspect/pg_logicalinspect.c @@ -168,7 +168,7 @@ pg_get_logical_snapshot_info(PG_FUNCTION_ARGS) { Datum *arrayelems; - arrayelems = (Datum *) palloc(ondisk.builder.committed.xcnt * sizeof(Datum)); + arrayelems = (Datum *) palloc(ondisk.builder.committed.xcnt * sizeof(*arrayelems)); for (int j = 0; j < ondisk.builder.committed.xcnt; j++) arrayelems[j] = TransactionIdGetDatum(ondisk.builder.committed.xip[j]); @@ -185,7 +185,7 @@ pg_get_logical_snapshot_info(PG_FUNCTION_ARGS) { Datum *arrayelems; - arrayelems = (Datum *) palloc(ondisk.builder.catchange.xcnt * sizeof(Datum)); + arrayelems = (Datum *) palloc(ondisk.builder.catchange.xcnt * sizeof(*arrayelems)); for (int j = 0; j < ondisk.builder.catchange.xcnt; j++) arrayelems[j] = TransactionIdGetDatum(ondisk.builder.catchange.xip[j]); diff --git a/contrib/pg_stat_statements/pg_stat_statements.c b/contrib/pg_stat_statements/pg_stat_statements.c index 39208f80b5b..2af6ea863b2 100644 --- a/contrib/pg_stat_statements/pg_stat_statements.c +++ b/contrib/pg_stat_statements/pg_stat_statements.c @@ -2194,7 +2194,7 @@ entry_dealloc(void) * cur_median_usage includes the entries we're about to zap. */ - entries = palloc(hash_get_num_entries(pgss_hash) * sizeof(pgssEntry *)); + entries = palloc(hash_get_num_entries(pgss_hash) * sizeof(*entries)); i = 0; tottextlen = 0; diff --git a/contrib/pg_trgm/trgm_gist.c b/contrib/pg_trgm/trgm_gist.c index 5c7deb103a6..dab1c8cdd32 100644 --- a/contrib/pg_trgm/trgm_gist.c +++ b/contrib/pg_trgm/trgm_gist.c @@ -423,7 +423,7 @@ gtrgm_consistent(PG_FUNCTION_ARGS) * So we can apply trigramsMatchGraph despite uncertainty, * and that usefully improves the quality of the search. */ - check = (bool *) palloc(len * sizeof(bool)); + check = (bool *) palloc(len * sizeof(*check)); for (k = 0; k < len; k++) { CPTRGM(&tmp, ptr + k); diff --git a/contrib/pg_trgm/trgm_regexp.c b/contrib/pg_trgm/trgm_regexp.c index 1a76794c422..50fd6284318 100644 --- a/contrib/pg_trgm/trgm_regexp.c +++ b/contrib/pg_trgm/trgm_regexp.c @@ -728,7 +728,7 @@ RE_compile(regex_t *regex, text *text_re, int cflags, Oid collation) char errMsg[100]; /* Convert pattern string to wide characters */ - pattern = (pg_wchar *) palloc((text_re_len + 1) * sizeof(pg_wchar)); + pattern = (pg_wchar *) palloc((text_re_len + 1) * sizeof(*pattern)); pattern_len = pg_mb2wchar_with_len(text_re_val, pattern, text_re_len); @@ -769,7 +769,7 @@ getColorInfo(regex_t *regex, TrgmNFA *trgmNFA) trgmNFA->ncolors = colorsCount; trgmNFA->colorInfo = (TrgmColorInfo *) - palloc0(colorsCount * sizeof(TrgmColorInfo)); + palloc0(colorsCount * sizeof(*trgmNFA->colorInfo)); /* * Loop over colors, filling TrgmColorInfo about each. Note we include diff --git a/contrib/pgcrypto/pgp-armor.c b/contrib/pgcrypto/pgp-armor.c index bfc90af063d..196a40a8255 100644 --- a/contrib/pgcrypto/pgp-armor.c +++ b/contrib/pgcrypto/pgp-armor.c @@ -441,8 +441,8 @@ pgp_extract_armor_headers(const uint8 *src, unsigned len, buf[armor_len] = '\0'; /* Allocate return arrays */ - *keys = (char **) palloc(hdrlines * sizeof(char *)); - *values = (char **) palloc(hdrlines * sizeof(char *)); + *keys = (char **) palloc(hdrlines * sizeof(**keys)); + *values = (char **) palloc(hdrlines * sizeof(**values)); /* * Split the header lines at newlines and ": " separators, and collect diff --git a/contrib/pgrowlocks/pgrowlocks.c b/contrib/pgrowlocks/pgrowlocks.c index f88269332b6..1db925fbddc 100644 --- a/contrib/pgrowlocks/pgrowlocks.c +++ b/contrib/pgrowlocks/pgrowlocks.c @@ -119,7 +119,7 @@ pgrowlocks(PG_FUNCTION_ARGS) attinmeta = TupleDescGetAttInMetadata(rsinfo->setDesc); - values = (char **) palloc(rsinfo->setDesc->natts * sizeof(char *)); + values = (char **) palloc(rsinfo->setDesc->natts * sizeof(*values)); while ((tuple = heap_getnext(scan, ForwardScanDirection)) != NULL) { @@ -144,7 +144,7 @@ pgrowlocks(PG_FUNCTION_ARGS) values[Atnum_tid] = DatumGetCString(DirectFunctionCall1(tidout, PointerGetDatum(&tuple->t_self))); - values[Atnum_xmax] = palloc(NCHARS * sizeof(char)); + values[Atnum_xmax] = palloc(NCHARS * sizeof(*values[Atnum_xmax])); snprintf(values[Atnum_xmax], NCHARS, "%u", xmax); if (infomask & HEAP_XMAX_IS_MULTI) { @@ -226,7 +226,7 @@ pgrowlocks(PG_FUNCTION_ARGS) { values[Atnum_ismulti] = pstrdup("false"); - values[Atnum_xids] = palloc(NCHARS * sizeof(char)); + values[Atnum_xids] = palloc(NCHARS * sizeof(*values[Atnum_xids])); snprintf(values[Atnum_xids], NCHARS, "{%u}", xmax); values[Atnum_modes] = palloc(NCHARS); @@ -256,7 +256,7 @@ pgrowlocks(PG_FUNCTION_ARGS) snprintf(values[Atnum_modes], NCHARS, "{No Key Update}"); } - values[Atnum_pids] = palloc(NCHARS * sizeof(char)); + values[Atnum_pids] = palloc(NCHARS * sizeof(*values[Atnum_pids])); snprintf(values[Atnum_pids], NCHARS, "{%d}", BackendXidGetPid(xmax)); } diff --git a/contrib/postgres_fdw/postgres_fdw.c b/contrib/postgres_fdw/postgres_fdw.c index 5e178c21b39..60c0544d3b8 100644 --- a/contrib/postgres_fdw/postgres_fdw.c +++ b/contrib/postgres_fdw/postgres_fdw.c @@ -3844,7 +3844,7 @@ fetch_more_data(ForeignScanState *node) /* Convert the data into HeapTuples */ numrows = PQntuples(res); - fsstate->tuples = (HeapTuple *) palloc0(numrows * sizeof(HeapTuple)); + fsstate->tuples = (HeapTuple *) palloc0(numrows * sizeof(*fsstate->tuples)); fsstate->num_tuples = numrows; fsstate->next_tuple = 0; @@ -4650,7 +4650,7 @@ init_returning_filter(PgFdwDirectModifyState *dmstate, * Also get the indexes of the entries for ctid and oid if any. */ dmstate->attnoMap = (AttrNumber *) - palloc0(resultTupType->natts * sizeof(AttrNumber)); + palloc0(resultTupType->natts * sizeof(*dmstate->attnoMap)); dmstate->ctidAttno = dmstate->oidAttno = 0; @@ -7528,8 +7528,8 @@ make_tuple_from_result_row(PGresult *res, tupdesc = fsstate->ss.ss_ScanTupleSlot->tts_tupleDescriptor; } - values = (Datum *) palloc0(tupdesc->natts * sizeof(Datum)); - nulls = (bool *) palloc(tupdesc->natts * sizeof(bool)); + values = (Datum *) palloc0(tupdesc->natts * sizeof(*values)); + nulls = (bool *) palloc(tupdesc->natts * sizeof(*nulls)); /* Initialize to nulls for any columns not present in result */ memset(nulls, true, tupdesc->natts * sizeof(bool)); diff --git a/contrib/seg/seg.c b/contrib/seg/seg.c index 2d3a048c73e..16077811d21 100644 --- a/contrib/seg/seg.c +++ b/contrib/seg/seg.c @@ -345,7 +345,7 @@ gseg_picksplit(PG_FUNCTION_ARGS) * Prepare the auxiliary array and sort it. */ sort_items = (gseg_picksplit_item *) - palloc(maxoff * sizeof(gseg_picksplit_item)); + palloc(maxoff * sizeof(*sort_items)); for (i = 1; i <= maxoff; i++) { seg = DatumGetSegP(entryvec->vector[i].key); @@ -360,8 +360,8 @@ gseg_picksplit(PG_FUNCTION_ARGS) /* sort items below "firstright" will go into the left side */ firstright = maxoff / 2; - v->spl_left = (OffsetNumber *) palloc(maxoff * sizeof(OffsetNumber)); - v->spl_right = (OffsetNumber *) palloc(maxoff * sizeof(OffsetNumber)); + v->spl_left = (OffsetNumber *) palloc(maxoff * sizeof(*v->spl_left)); + v->spl_right = (OffsetNumber *) palloc(maxoff * sizeof(*v->spl_right)); left = v->spl_left; v->spl_nleft = 0; right = v->spl_right; diff --git a/contrib/spi/autoinc.c b/contrib/spi/autoinc.c index b5609f20251..672a0ed3589 100644 --- a/contrib/spi/autoinc.c +++ b/contrib/spi/autoinc.c @@ -67,9 +67,9 @@ autoinc(PG_FUNCTION_ARGS) args = trigger->tgargs; tupdesc = rel->rd_att; - chattrs = (int *) palloc(nargs / 2 * sizeof(int)); - newvals = (Datum *) palloc(nargs / 2 * sizeof(Datum)); - newnulls = (bool *) palloc(nargs / 2 * sizeof(bool)); + chattrs = (int *) palloc(nargs / 2 * sizeof(*chattrs)); + newvals = (Datum *) palloc(nargs / 2 * sizeof(*newvals)); + newnulls = (bool *) palloc(nargs / 2 * sizeof(*newnulls)); for (i = 0; i < nargs;) { diff --git a/contrib/spi/refint.c b/contrib/spi/refint.c index fbbd558ca1e..7dc787bd0e4 100644 --- a/contrib/spi/refint.c +++ b/contrib/spi/refint.c @@ -121,7 +121,7 @@ check_primary_key(PG_FUNCTION_ARGS) * We use SPI plan preparation feature, so allocate space to place key * values. */ - kvals = (Datum *) palloc(nkeys * sizeof(Datum)); + kvals = (Datum *) palloc(nkeys * sizeof(*kvals)); /* * Construct ident string as TriggerName $ TriggeredRelationId and try to @@ -132,7 +132,7 @@ check_primary_key(PG_FUNCTION_ARGS) /* if there is no plan then allocate argtypes for preparation */ if (plan->nplans <= 0) - argtypes = (Oid *) palloc(nkeys * sizeof(Oid)); + argtypes = (Oid *) palloc(nkeys * sizeof(*argtypes)); /* For each column in key ... */ for (i = 0; i < nkeys; i++) @@ -343,7 +343,7 @@ check_foreign_key(PG_FUNCTION_ARGS) * We use SPI plan preparation feature, so allocate space to place key * values. */ - kvals = (Datum *) palloc(nkeys * sizeof(Datum)); + kvals = (Datum *) palloc(nkeys * sizeof(*kvals)); /* * Construct ident string as TriggerName $ TriggeredRelationId $ @@ -354,7 +354,7 @@ check_foreign_key(PG_FUNCTION_ARGS) /* if there is no plan(s) then allocate argtypes for preparation */ if (plan->nplans <= 0) - argtypes = (Oid *) palloc(nkeys * sizeof(Oid)); + argtypes = (Oid *) palloc(nkeys * sizeof(*argtypes)); /* * else - check that we have exactly nrefs plan(s) ready diff --git a/contrib/tablefunc/tablefunc.c b/contrib/tablefunc/tablefunc.c index c40fd36dc96..62588cfc4ba 100644 --- a/contrib/tablefunc/tablefunc.c +++ b/contrib/tablefunc/tablefunc.c @@ -485,7 +485,7 @@ crosstab(PG_FUNCTION_ARGS) char **values; /* allocate and zero space */ - values = (char **) palloc0((1 + num_categories) * sizeof(char *)); + values = (char **) palloc0((1 + num_categories) * sizeof(*values)); /* * now loop through the sql results and assign each value in sequence @@ -862,7 +862,7 @@ get_crosstab_tuplestore(char *sql, result_ncols, tupdesc->natts))); /* allocate space and make sure it's clear */ - values = (char **) palloc0(result_ncols * sizeof(char *)); + values = (char **) palloc0(result_ncols * sizeof(*values)); for (i = 0; i < proc; i++) { @@ -1245,9 +1245,9 @@ build_tuplestore_recursively(char *key_fld, } if (show_branch) - values = (char **) palloc((CONNECTBY_NCOLS + serial_column) * sizeof(char *)); + values = (char **) palloc((CONNECTBY_NCOLS + serial_column) * sizeof(*values)); else - values = (char **) palloc((CONNECTBY_NCOLS_NOBRANCH + serial_column) * sizeof(char *)); + values = (char **) palloc((CONNECTBY_NCOLS_NOBRANCH + serial_column) * sizeof(*values)); /* First time through, do a little setup */ if (level == 0) diff --git a/contrib/xml2/xpath.c b/contrib/xml2/xpath.c index 662d7d02f27..3e631431d10 100644 --- a/contrib/xml2/xpath.c +++ b/contrib/xml2/xpath.c @@ -651,8 +651,8 @@ xpath_table(PG_FUNCTION_ARGS) attinmeta = TupleDescGetAttInMetadata(rsinfo->setDesc); - values = (char **) palloc(rsinfo->setDesc->natts * sizeof(char *)); - xpaths = (xmlChar **) palloc(rsinfo->setDesc->natts * sizeof(xmlChar *)); + values = (char **) palloc(rsinfo->setDesc->natts * sizeof(*values)); + xpaths = (xmlChar **) palloc(rsinfo->setDesc->natts * sizeof(*xpaths)); /* * Split XPaths. xpathset is a writable CString. diff --git a/src/backend/access/brin/brin_minmax_multi.c b/src/backend/access/brin/brin_minmax_multi.c index 0298a9da8ba..e496e98b06d 100644 --- a/src/backend/access/brin/brin_minmax_multi.c +++ b/src/backend/access/brin/brin_minmax_multi.c @@ -1392,7 +1392,7 @@ build_expanded_ranges(FmgrInfo *cmp, Oid colloid, Ranges *ranges, /* both ranges and points are expanded into a separate element */ neranges = ranges->nranges + ranges->nvalues; - eranges = (ExpandedRange *) palloc0(neranges * sizeof(ExpandedRange)); + eranges = (ExpandedRange *) palloc0(neranges * sizeof(*eranges)); /* fill the expanded ranges */ fill_expanded_ranges(eranges, neranges, ranges); @@ -2785,7 +2785,7 @@ brin_minmax_multi_union(PG_FUNCTION_ARGS) oldctx = MemoryContextSwitchTo(ctx); /* allocate and fill */ - eranges = (ExpandedRange *) palloc0(neranges * sizeof(ExpandedRange)); + eranges = (ExpandedRange *) palloc0(neranges * sizeof(*eranges)); /* fill the expanded ranges with entries for the first range */ fill_expanded_ranges(eranges, ranges_a->nranges + ranges_a->nvalues, diff --git a/src/backend/access/common/printtup.c b/src/backend/access/common/printtup.c index 47b2b2d2335..83c8a7234c9 100644 --- a/src/backend/access/common/printtup.c +++ b/src/backend/access/common/printtup.c @@ -264,7 +264,7 @@ printtup_prepare_info(DR_printtup *myState, TupleDesc typeinfo, int numAttrs) return; myState->myinfo = (PrinttupAttrInfo *) - palloc0(numAttrs * sizeof(PrinttupAttrInfo)); + palloc0(numAttrs * sizeof(*myState->myinfo)); for (i = 0; i < numAttrs; i++) { diff --git a/src/backend/access/common/reloptions.c b/src/backend/access/common/reloptions.c index 31926d8a368..032f5f2beaf 100644 --- a/src/backend/access/common/reloptions.c +++ b/src/backend/access/common/reloptions.c @@ -730,7 +730,7 @@ add_reloption(relopt_gen *newoption) if (max_custom_options == 0) { max_custom_options = 8; - custom_options = palloc(max_custom_options * sizeof(relopt_gen *)); + custom_options = palloc(max_custom_options * sizeof(*custom_options)); } else { @@ -1544,7 +1544,7 @@ parseRelOptions(Datum options, bool validate, relopt_kind kind, if (numoptions > 0) { - reloptions = palloc(numoptions * sizeof(relopt_value)); + reloptions = palloc(numoptions * sizeof(*reloptions)); for (i = 0, j = 0; relOpts[i]; i++) { diff --git a/src/backend/access/common/tupdesc.c b/src/backend/access/common/tupdesc.c index bcd1ddcc68b..1a224491255 100644 --- a/src/backend/access/common/tupdesc.c +++ b/src/backend/access/common/tupdesc.c @@ -369,7 +369,7 @@ CreateTupleDescCopyConstr(TupleDesc tupdesc) if ((cpy->num_defval = constr->num_defval) > 0) { - cpy->defval = (AttrDefault *) palloc(cpy->num_defval * sizeof(AttrDefault)); + cpy->defval = (AttrDefault *) palloc(cpy->num_defval * sizeof(*cpy->defval)); memcpy(cpy->defval, constr->defval, cpy->num_defval * sizeof(AttrDefault)); for (i = cpy->num_defval - 1; i >= 0; i--) cpy->defval[i].adbin = pstrdup(constr->defval[i].adbin); @@ -394,7 +394,7 @@ CreateTupleDescCopyConstr(TupleDesc tupdesc) if ((cpy->num_check = constr->num_check) > 0) { - cpy->check = (ConstrCheck *) palloc(cpy->num_check * sizeof(ConstrCheck)); + cpy->check = (ConstrCheck *) palloc(cpy->num_check * sizeof(*cpy->check)); memcpy(cpy->check, constr->check, cpy->num_check * sizeof(ConstrCheck)); for (i = cpy->num_check - 1; i >= 0; i--) { diff --git a/src/backend/access/gin/gindatapage.c b/src/backend/access/gin/gindatapage.c index 0140bd4904b..82941bcdd32 100644 --- a/src/backend/access/gin/gindatapage.c +++ b/src/backend/access/gin/gindatapage.c @@ -168,7 +168,7 @@ GinDataLeafPageGetItems(Page page, int *nitems, ItemPointerData advancePast) { ItemPointer tmp = dataLeafPageGetUncompressed(page, nitems); - result = palloc((*nitems) * sizeof(ItemPointerData)); + result = palloc((*nitems) * sizeof(*result)); memcpy(result, tmp, (*nitems) * sizeof(ItemPointerData)); } @@ -1418,7 +1418,7 @@ disassembleLeaf(Page page) seginfo->action = GIN_SEGMENT_REPLACE; seginfo->seg = NULL; - seginfo->items = palloc(nuncompressed * sizeof(ItemPointerData)); + seginfo->items = palloc(nuncompressed * sizeof(*seginfo->items)); memcpy(seginfo->items, uncompressed, nuncompressed * sizeof(ItemPointerData)); seginfo->nitems = nuncompressed; diff --git a/src/backend/access/gin/ginget.c b/src/backend/access/gin/ginget.c index b3e2e9d5f6e..e9457753b90 100644 --- a/src/backend/access/gin/ginget.c +++ b/src/backend/access/gin/ginget.c @@ -544,7 +544,7 @@ startScanKey(GinState *ginstate, GinScanOpaque so, GinScanKey key) key->nrequired = 0; key->nadditional = key->nentries; - key->additionalEntries = palloc(key->nadditional * sizeof(GinScanEntry)); + key->additionalEntries = palloc(key->nadditional * sizeof(*key->additionalEntries)); for (i = 0; i < key->nadditional; i++) key->additionalEntries[i] = key->scanEntry[i]; } @@ -577,8 +577,8 @@ startScanKey(GinState *ginstate, GinScanOpaque so, GinScanKey key) key->nrequired = i + 1; key->nadditional = key->nentries - key->nrequired; - key->requiredEntries = palloc(key->nrequired * sizeof(GinScanEntry)); - key->additionalEntries = palloc(key->nadditional * sizeof(GinScanEntry)); + key->requiredEntries = palloc(key->nrequired * sizeof(*key->requiredEntries)); + key->additionalEntries = palloc(key->nadditional * sizeof(*key->additionalEntries)); j = 0; for (i = 0; i < key->nrequired; i++) @@ -595,7 +595,7 @@ startScanKey(GinState *ginstate, GinScanOpaque so, GinScanKey key) key->nrequired = 1; key->nadditional = 0; - key->requiredEntries = palloc(1 * sizeof(GinScanEntry)); + key->requiredEntries = palloc(1 * sizeof(*key->requiredEntries)); key->requiredEntries[0] = key->scanEntry[0]; } MemoryContextSwitchTo(oldCtx); diff --git a/src/backend/access/gin/gininsert.c b/src/backend/access/gin/gininsert.c index df30dcc0228..579d5d282c3 100644 --- a/src/backend/access/gin/gininsert.c +++ b/src/backend/access/gin/gininsert.c @@ -1517,7 +1517,7 @@ GinBufferStoreTuple(GinBuffer *buffer, GinTuple *tup) * still pass 0 as number of elements in that array though. */ if (buffer->items == NULL) - buffer->items = palloc((buffer->nitems + tup->nitems) * sizeof(ItemPointerData)); + buffer->items = palloc((buffer->nitems + tup->nitems) * sizeof(*buffer->items)); else buffer->items = repalloc(buffer->items, (buffer->nitems + tup->nitems) * sizeof(ItemPointerData)); diff --git a/src/backend/access/gin/ginpostinglist.c b/src/backend/access/gin/ginpostinglist.c index 1bf061803da..99c2f03f779 100644 --- a/src/backend/access/gin/ginpostinglist.c +++ b/src/backend/access/gin/ginpostinglist.c @@ -308,7 +308,7 @@ ginPostingListDecodeAllSegments(GinPostingList *segment, int len, int *ndecoded_ * Guess an initial size of the array. */ nallocated = segment->nbytes * 2 + 1; - result = palloc(nallocated * sizeof(ItemPointerData)); + result = palloc(nallocated * sizeof(*result)); ndecoded = 0; while ((char *) segment < endseg) diff --git a/src/backend/access/gin/ginscan.c b/src/backend/access/gin/ginscan.c index 2ca635909f9..032a6c0fa02 100644 --- a/src/backend/access/gin/ginscan.c +++ b/src/backend/access/gin/ginscan.c @@ -289,7 +289,7 @@ ginNewScanKey(IndexScanDesc scan) so->totalentries = 0; so->allocentries = 32; so->entries = (GinScanEntry *) - palloc(so->allocentries * sizeof(GinScanEntry)); + palloc(so->allocentries * sizeof(*so->entries)); so->isVoidRes = false; @@ -357,7 +357,7 @@ ginNewScanKey(IndexScanDesc scan) * didn't create a nullFlags array, we assume everything is non-null. * While at it, detect whether any null keys are present. */ - categories = (GinNullCategory *) palloc0(nQueryValues * sizeof(GinNullCategory)); + categories = (GinNullCategory *) palloc0(nQueryValues * sizeof(*categories)); if (nullFlags) { int32 j; diff --git a/src/backend/access/gin/ginutil.c b/src/backend/access/gin/ginutil.c index 605f80aad39..60018006565 100644 --- a/src/backend/access/gin/ginutil.c +++ b/src/backend/access/gin/ginutil.c @@ -534,7 +534,7 @@ ginExtractEntries(GinState *ginstate, OffsetNumber attnum, * assuming that everything's non-null. */ if (nullFlags == NULL) - nullFlags = (bool *) palloc0(*nentries * sizeof(bool)); + nullFlags = (bool *) palloc0(*nentries * sizeof(*nullFlags)); /* * If there's more than one key, sort and unique-ify. @@ -596,7 +596,7 @@ ginExtractEntries(GinState *ginstate, OffsetNumber attnum, /* * Create GinNullCategory representation from nullFlags. */ - *categories = (GinNullCategory *) palloc0(*nentries * sizeof(GinNullCategory)); + *categories = (GinNullCategory *) palloc0(*nentries * sizeof(**categories)); for (i = 0; i < *nentries; i++) (*categories)[i] = (nullFlags[i] ? GIN_CAT_NULL_KEY : GIN_CAT_NORM_KEY); diff --git a/src/backend/access/gist/gistget.c b/src/backend/access/gist/gistget.c index 9ba45acfff3..c1ab8a83971 100644 --- a/src/backend/access/gist/gistget.c +++ b/src/backend/access/gist/gistget.c @@ -661,7 +661,7 @@ gistgettuple(IndexScanDesc scan, ScanDirection dir) so->killedItems = (OffsetNumber *) palloc(MaxIndexTuplesPerPage - * sizeof(OffsetNumber)); + * sizeof(*so->killedItems)); MemoryContextSwitchTo(oldCxt); } @@ -698,7 +698,7 @@ gistgettuple(IndexScanDesc scan, ScanDirection dir) so->killedItems = (OffsetNumber *) palloc(MaxIndexTuplesPerPage - * sizeof(OffsetNumber)); + * sizeof(*so->killedItems)); MemoryContextSwitchTo(oldCxt); } diff --git a/src/backend/access/gist/gistproc.c b/src/backend/access/gist/gistproc.c index 9ac06504be1..96ba21d22a9 100644 --- a/src/backend/access/gist/gistproc.c +++ b/src/backend/access/gist/gistproc.c @@ -515,8 +515,8 @@ gist_box_picksplit(PG_FUNCTION_ARGS) nentries = context.entriesCount = maxoff - FirstOffsetNumber + 1; /* Allocate arrays for intervals along axes */ - intervalsLower = (SplitInterval *) palloc(nentries * sizeof(SplitInterval)); - intervalsUpper = (SplitInterval *) palloc(nentries * sizeof(SplitInterval)); + intervalsLower = (SplitInterval *) palloc(nentries * sizeof(*intervalsLower)); + intervalsUpper = (SplitInterval *) palloc(nentries * sizeof(*intervalsUpper)); /* * Calculate the overall minimum bounding box over all the entries. @@ -692,8 +692,8 @@ gist_box_picksplit(PG_FUNCTION_ARGS) */ /* Allocate vectors for results */ - v->spl_left = (OffsetNumber *) palloc(nentries * sizeof(OffsetNumber)); - v->spl_right = (OffsetNumber *) palloc(nentries * sizeof(OffsetNumber)); + v->spl_left = (OffsetNumber *) palloc(nentries * sizeof(*v->spl_left)); + v->spl_right = (OffsetNumber *) palloc(nentries * sizeof(*v->spl_right)); v->spl_nleft = 0; v->spl_nright = 0; @@ -706,7 +706,7 @@ gist_box_picksplit(PG_FUNCTION_ARGS) * either group without affecting overlap along selected axis. */ commonEntriesCount = 0; - commonEntries = (CommonEntry *) palloc(nentries * sizeof(CommonEntry)); + commonEntries = (CommonEntry *) palloc(nentries * sizeof(*commonEntries)); /* Helper macros to place an entry in the left or right group */ #define PLACE_LEFT(box, off) \ diff --git a/src/backend/access/gist/gistscan.c b/src/backend/access/gist/gistscan.c index 01b8ff0b6fa..804d62847ff 100644 --- a/src/backend/access/gist/gistscan.c +++ b/src/backend/access/gist/gistscan.c @@ -228,7 +228,7 @@ gistrescan(IndexScanDesc scan, ScanKey key, int nkeys, */ if (!first_time) { - fn_extras = (void **) palloc(scan->numberOfKeys * sizeof(void *)); + fn_extras = (void **) palloc(scan->numberOfKeys * sizeof(*fn_extras)); for (i = 0; i < scan->numberOfKeys; i++) fn_extras[i] = scan->keyData[i].sk_func.fn_extra; } @@ -283,14 +283,14 @@ gistrescan(IndexScanDesc scan, ScanKey key, int nkeys, /* As above, preserve fn_extra if not first time through */ if (!first_time) { - fn_extras = (void **) palloc(scan->numberOfOrderBys * sizeof(void *)); + fn_extras = (void **) palloc(scan->numberOfOrderBys * sizeof(*fn_extras)); for (i = 0; i < scan->numberOfOrderBys; i++) fn_extras[i] = scan->orderByData[i].sk_func.fn_extra; } memcpy(scan->orderByData, orderbys, scan->numberOfOrderBys * sizeof(ScanKeyData)); - so->orderByTypes = (Oid *) palloc(scan->numberOfOrderBys * sizeof(Oid)); + so->orderByTypes = (Oid *) palloc(scan->numberOfOrderBys * sizeof(*so->orderByTypes)); /* * Modify the order-by key so that the Distance method is called for diff --git a/src/backend/access/gist/gistsplit.c b/src/backend/access/gist/gistsplit.c index 21fea505d9c..95d3e8dc17d 100644 --- a/src/backend/access/gist/gistsplit.c +++ b/src/backend/access/gist/gistsplit.c @@ -587,8 +587,8 @@ gistSplitHalf(GIST_SPLITVEC *v, int len) int i; v->spl_nright = v->spl_nleft = 0; - v->spl_left = (OffsetNumber *) palloc(len * sizeof(OffsetNumber)); - v->spl_right = (OffsetNumber *) palloc(len * sizeof(OffsetNumber)); + v->spl_left = (OffsetNumber *) palloc(len * sizeof(*v->spl_left)); + v->spl_right = (OffsetNumber *) palloc(len * sizeof(*v->spl_right)); for (i = 1; i <= len; i++) if (i < len / 2) v->spl_right[v->spl_nright++] = i; @@ -632,7 +632,7 @@ gistSplitByKey(Relation r, Page page, IndexTuple *itup, int len, /* note that entryvec->vector[0] goes unused in this code */ entryvec = palloc(GEVHDRSZ + (len + 1) * sizeof(GISTENTRY)); entryvec->n = len + 1; - offNullTuples = (OffsetNumber *) palloc(len * sizeof(OffsetNumber)); + offNullTuples = (OffsetNumber *) palloc(len * sizeof(*offNullTuples)); for (i = 1; i <= len; i++) { @@ -674,7 +674,7 @@ gistSplitByKey(Relation r, Page page, IndexTuple *itup, int len, v->splitVector.spl_nright = nOffNullTuples; v->spl_risnull[attno] = true; - v->splitVector.spl_left = (OffsetNumber *) palloc(len * sizeof(OffsetNumber)); + v->splitVector.spl_left = (OffsetNumber *) palloc(len * sizeof(*v->splitVector.spl_left)); v->splitVector.spl_nleft = 0; for (i = 1; i <= len; i++) if (j < v->splitVector.spl_nright && offNullTuples[j] == i) @@ -716,8 +716,8 @@ gistSplitByKey(Relation r, Page page, IndexTuple *itup, int len, * Form an array of just the don't-care tuples to pass to a * recursive invocation of this function for the next column. */ - IndexTuple *newitup = (IndexTuple *) palloc(len * sizeof(IndexTuple)); - OffsetNumber *map = (OffsetNumber *) palloc(len * sizeof(OffsetNumber)); + IndexTuple *newitup = (IndexTuple *) palloc(len * sizeof(*newitup)); + OffsetNumber *map = (OffsetNumber *) palloc(len * sizeof(*map)); int newlen = 0; GIST_SPLITVEC backupSplit; diff --git a/src/backend/access/gist/gistxlog.c b/src/backend/access/gist/gistxlog.c index 6484ca5e2ca..615eeb7ca7b 100644 --- a/src/backend/access/gist/gistxlog.c +++ b/src/backend/access/gist/gistxlog.c @@ -228,7 +228,7 @@ decodePageSplitRecord(char *begin, int len, int *n) memcpy(n, begin, sizeof(int)); ptr = begin + sizeof(int); - tuples = palloc(*n * sizeof(IndexTuple)); + tuples = palloc(*n * sizeof(*tuples)); for (i = 0; i < *n; i++) { diff --git a/src/backend/access/heap/heapam.c b/src/backend/access/heap/heapam.c index 225f9829f22..840e2c8392a 100644 --- a/src/backend/access/heap/heapam.c +++ b/src/backend/access/heap/heapam.c @@ -2399,7 +2399,7 @@ heap_multi_insert(Relation relation, TupleTableSlot **slots, int ntuples, HEAP_DEFAULT_FILLFACTOR); /* Toast and set header data in all the slots */ - heaptuples = palloc(ntuples * sizeof(HeapTuple)); + heaptuples = palloc(ntuples * sizeof(*heaptuples)); for (i = 0; i < ntuples; i++) { HeapTuple tuple; @@ -8784,7 +8784,7 @@ bottomup_sort_and_shrink(TM_IndexDeleteOp *delstate) /* Sort groups and rearrange caller's deltids array */ qsort(blockgroups, nblockgroups, sizeof(IndexDeleteCounts), bottomup_sort_and_shrink_cmp); - reordereddeltids = palloc(delstate->ndeltids * sizeof(TM_IndexDelete)); + reordereddeltids = palloc(delstate->ndeltids * sizeof(*reordereddeltids)); nblockgroups = Min(BOTTOMUP_MAX_NBLOCKS, nblockgroups); /* Determine number of favorable blocks at the start of final deltids */ diff --git a/src/backend/access/heap/vacuumlazy.c b/src/backend/access/heap/vacuumlazy.c index e8c99c3773d..2f01b6caaa0 100644 --- a/src/backend/access/heap/vacuumlazy.c +++ b/src/backend/access/heap/vacuumlazy.c @@ -763,7 +763,7 @@ heap_vacuum_rel(Relation rel, const VacuumParams params, vacrel->new_rel_tuples = 0; vacrel->new_live_tuples = 0; vacrel->indstats = (IndexBulkDeleteResult **) - palloc0(vacrel->nindexes * sizeof(IndexBulkDeleteResult *)); + palloc0(vacrel->nindexes * sizeof(*vacrel->indstats)); /* Initialize remaining counters (be tidy) */ vacrel->num_index_scans = 0; diff --git a/src/backend/access/nbtree/nbtinsert.c b/src/backend/access/nbtree/nbtinsert.c index 031eb76ba8c..0f28d9e3680 100644 --- a/src/backend/access/nbtree/nbtinsert.c +++ b/src/backend/access/nbtree/nbtinsert.c @@ -2842,8 +2842,8 @@ _bt_simpledel_pass(Relation rel, Buffer buffer, Relation heapRel, delstate.bottomup = false; delstate.bottomupfreespace = 0; delstate.ndeltids = 0; - delstate.deltids = palloc(MaxTIDsPerBTreePage * sizeof(TM_IndexDelete)); - delstate.status = palloc(MaxTIDsPerBTreePage * sizeof(TM_IndexStatus)); + delstate.deltids = palloc(MaxTIDsPerBTreePage * sizeof(*delstate.deltids)); + delstate.status = palloc(MaxTIDsPerBTreePage * sizeof(*delstate.status)); for (offnum = minoff; offnum <= maxoff; diff --git a/src/backend/access/nbtree/nbtpreprocesskeys.c b/src/backend/access/nbtree/nbtpreprocesskeys.c index 5b251c5058d..d00b6c62316 100644 --- a/src/backend/access/nbtree/nbtpreprocesskeys.c +++ b/src/backend/access/nbtree/nbtpreprocesskeys.c @@ -1568,7 +1568,7 @@ _bt_unmark_keys(IndexScanDesc scan, int *keyDataMap) * Any requiredness markings that we might leave on later keys/attributes * are predicated on there being required = keys on all prior columns. */ - unmarkikey = palloc0(so->numberOfKeys * sizeof(bool)); + unmarkikey = palloc0(so->numberOfKeys * sizeof(*unmarkikey)); nunmark = 0; /* Set things up for first key's attribute */ @@ -1659,8 +1659,8 @@ _bt_unmark_keys(IndexScanDesc scan, int *keyDataMap) nkept = 0; if (so->numArrayKeys) { - unmarkOrderProcs = palloc(nunmark * sizeof(FmgrInfo)); - keepOrderProcs = palloc((so->numberOfKeys - nunmark) * sizeof(FmgrInfo)); + unmarkOrderProcs = palloc(nunmark * sizeof(*unmarkOrderProcs)); + keepOrderProcs = palloc((so->numberOfKeys - nunmark) * sizeof(*keepOrderProcs)); } /* @@ -1893,10 +1893,10 @@ _bt_preprocess_array_keys(IndexScanDesc scan, int *new_numberOfKeys) arrayKeyData = (ScanKey) palloc(numArrayKeyData * sizeof(ScanKeyData)); /* Allocate space for per-array data in the workspace context */ - so->arrayKeys = (BTArrayKeyInfo *) palloc(numArrayKeys * sizeof(BTArrayKeyInfo)); + so->arrayKeys = (BTArrayKeyInfo *) palloc(numArrayKeys * sizeof(*so->arrayKeys)); /* Allocate space for ORDER procs used to help _bt_checkkeys */ - so->orderProcs = (FmgrInfo *) palloc(numArrayKeyData * sizeof(FmgrInfo)); + so->orderProcs = (FmgrInfo *) palloc(numArrayKeyData * sizeof(*so->orderProcs)); numArrayKeys = 0; numArrayKeyData = 0; diff --git a/src/backend/access/transam/multixact.c b/src/backend/access/transam/multixact.c index 8ba2f4529dc..25fd7e9e40a 100644 --- a/src/backend/access/transam/multixact.c +++ b/src/backend/access/transam/multixact.c @@ -1309,7 +1309,7 @@ GetMultiXactIdMembers(MultiXactId multi, MultiXactMember **members, length = nextMXOffset - offset; /* read the members */ - ptr = (MultiXactMember *) palloc(length * sizeof(MultiXactMember)); + ptr = (MultiXactMember *) palloc(length * sizeof(*ptr)); prev_pageno = -1; for (int i = 0; i < length; i++, offset++) { diff --git a/src/backend/access/transam/twophase.c b/src/backend/access/transam/twophase.c index ec4e3628bd5..3e492b807f0 100644 --- a/src/backend/access/transam/twophase.c +++ b/src/backend/access/transam/twophase.c @@ -2004,7 +2004,7 @@ PrescanPreparedTransactions(TransactionId **xids_p, int *nxids_p) if (nxids == 0) { allocsize = 10; - xids = palloc(allocsize * sizeof(TransactionId)); + xids = palloc(allocsize * sizeof(*xids)); } else { diff --git a/src/backend/access/transam/xact.c b/src/backend/access/transam/xact.c index b69d452551a..b7442939f8b 100644 --- a/src/backend/access/transam/xact.c +++ b/src/backend/access/transam/xact.c @@ -5599,7 +5599,7 @@ SerializeTransactionState(Size maxsize, char *start_address) <= maxsize); /* Copy them to our scratch space. */ - workspace = palloc(nxids * sizeof(TransactionId)); + workspace = palloc(nxids * sizeof(*workspace)); for (s = CurrentTransactionState; s != NULL; s = s->parent) { if (FullTransactionIdIsValid(s->fullTransactionId)) diff --git a/src/backend/backup/basebackup_incremental.c b/src/backend/backup/basebackup_incremental.c index 7678e4f6ec3..4c1656a5925 100644 --- a/src/backend/backup/basebackup_incremental.c +++ b/src/backend/backup/basebackup_incremental.c @@ -311,7 +311,7 @@ PrepareForIncrementalBackup(IncrementalBackupInfo *ib, * to the beginning. */ expectedTLEs = readTimeLineHistory(backup_state->starttli); - tlep = palloc0(num_wal_ranges * sizeof(TimeLineHistoryEntry *)); + tlep = palloc0(num_wal_ranges * sizeof(*tlep)); for (i = 0; i < num_wal_ranges; ++i) { backup_wal_range *range = list_nth(ib->manifest_wal_ranges, i); diff --git a/src/backend/catalog/aclchk.c b/src/backend/catalog/aclchk.c index 5b410ff14c9..51dad280fc7 100644 --- a/src/backend/catalog/aclchk.c +++ b/src/backend/catalog/aclchk.c @@ -1900,7 +1900,7 @@ ExecGrant_Relation(InternalGrant *istmt) * corresponds to FirstLowInvalidHeapAttributeNumber. */ num_col_privileges = pg_class_tuple->relnatts - FirstLowInvalidHeapAttributeNumber + 1; - col_privileges = (AclMode *) palloc0(num_col_privileges * sizeof(AclMode)); + col_privileges = (AclMode *) palloc0(num_col_privileges * sizeof(*col_privileges)); have_col_privileges = false; /* diff --git a/src/backend/catalog/dependency.c b/src/backend/catalog/dependency.c index 838ed26d6b9..a9767485bb4 100644 --- a/src/backend/catalog/dependency.c +++ b/src/backend/catalog/dependency.c @@ -2691,7 +2691,7 @@ add_exact_object_address_extra(const ObjectAddress *object, /* allocate extra space if first time */ if (!addrs->extras) addrs->extras = (ObjectAddressExtra *) - palloc(addrs->maxrefs * sizeof(ObjectAddressExtra)); + palloc(addrs->maxrefs * sizeof(*addrs->extras)); /* enlarge array if needed */ if (addrs->numrefs >= addrs->maxrefs) diff --git a/src/backend/catalog/heap.c b/src/backend/catalog/heap.c index 265cc3e5fbf..509d610522c 100644 --- a/src/backend/catalog/heap.c +++ b/src/backend/catalog/heap.c @@ -2174,7 +2174,7 @@ StoreRelCheck(Relation rel, const char *ccname, Node *expr, ListCell *vl; int i = 0; - attNos = (int16 *) palloc(keycount * sizeof(int16)); + attNos = (int16 *) palloc(keycount * sizeof(*attNos)); foreach(vl, varList) { Var *var = (Var *) lfirst(vl); diff --git a/src/backend/catalog/namespace.c b/src/backend/catalog/namespace.c index c94089caa58..95e28f73920 100644 --- a/src/backend/catalog/namespace.c +++ b/src/backend/catalog/namespace.c @@ -1648,7 +1648,7 @@ MatchNamedCall(HeapTuple proctup, int nargs, List *argnames, Assert(include_out_arguments ? (pronargs == pronallargs) : (pronargs <= pronallargs)); /* initialize state for matching */ - *argnumbers = (int *) palloc(pronargs * sizeof(int)); + *argnumbers = (int *) palloc(pronargs * sizeof(**argnumbers)); memset(arggiven, false, pronargs * sizeof(bool)); /* there are numposargs positional args before the named args */ diff --git a/src/backend/catalog/pg_constraint.c b/src/backend/catalog/pg_constraint.c index 43b4507d86e..59c4392ec12 100644 --- a/src/backend/catalog/pg_constraint.c +++ b/src/backend/catalog/pg_constraint.c @@ -118,7 +118,7 @@ CreateConstraintEntry(const char *constraintName, { Datum *conkey; - conkey = (Datum *) palloc(constraintNKeys * sizeof(Datum)); + conkey = (Datum *) palloc(constraintNKeys * sizeof(*conkey)); for (i = 0; i < constraintNKeys; i++) conkey[i] = Int16GetDatum(constraintKey[i]); conkeyArray = construct_array_builtin(conkey, constraintNKeys, INT2OID); @@ -131,7 +131,7 @@ CreateConstraintEntry(const char *constraintName, Datum *fkdatums; int nkeys = Max(foreignNKeys, numFkDeleteSetCols); - fkdatums = (Datum *) palloc(nkeys * sizeof(Datum)); + fkdatums = (Datum *) palloc(nkeys * sizeof(*fkdatums)); for (i = 0; i < foreignNKeys; i++) fkdatums[i] = Int16GetDatum(foreignKey[i]); confkeyArray = construct_array_builtin(fkdatums, foreignNKeys, INT2OID); @@ -167,7 +167,7 @@ CreateConstraintEntry(const char *constraintName, { Datum *opdatums; - opdatums = (Datum *) palloc(constraintNKeys * sizeof(Datum)); + opdatums = (Datum *) palloc(constraintNKeys * sizeof(*opdatums)); for (i = 0; i < constraintNKeys; i++) opdatums[i] = ObjectIdGetDatum(exclOp[i]); conexclopArray = construct_array_builtin(opdatums, constraintNKeys, OIDOID); diff --git a/src/backend/catalog/pg_inherits.c b/src/backend/catalog/pg_inherits.c index 929bb53b620..63f9e5c2a6d 100644 --- a/src/backend/catalog/pg_inherits.c +++ b/src/backend/catalog/pg_inherits.c @@ -105,7 +105,7 @@ find_inheritance_children_extended(Oid parentrelId, bool omit_detached, * Scan pg_inherits and build a working array of subclass OIDs. */ maxoids = 32; - oidarr = (Oid *) palloc(maxoids * sizeof(Oid)); + oidarr = (Oid *) palloc(maxoids * sizeof(*oidarr)); numoids = 0; relation = table_open(InheritsRelationId, AccessShareLock); diff --git a/src/backend/catalog/pg_shdepend.c b/src/backend/catalog/pg_shdepend.c index fe4e4536676..25dfab1f4b7 100644 --- a/src/backend/catalog/pg_shdepend.c +++ b/src/backend/catalog/pg_shdepend.c @@ -717,7 +717,7 @@ checkSharedDependencies(Oid classId, Oid objectId, allocedobjects = 128; /* arbitrary initial array size */ objects = (ShDependObjectInfo *) - palloc(allocedobjects * sizeof(ShDependObjectInfo)); + palloc(allocedobjects * sizeof(*objects)); numobjects = 0; initStringInfo(&descs); initStringInfo(&alldescs); diff --git a/src/backend/commands/alter.c b/src/backend/commands/alter.c index cb75e11fced..2aa1940fdd9 100644 --- a/src/backend/commands/alter.c +++ b/src/backend/commands/alter.c @@ -324,9 +324,9 @@ AlterObjectRename_internal(Relation rel, Oid objectId, const char *new_name) } /* Build modified tuple */ - values = palloc0(RelationGetNumberOfAttributes(rel) * sizeof(Datum)); - nulls = palloc0(RelationGetNumberOfAttributes(rel) * sizeof(bool)); - replaces = palloc0(RelationGetNumberOfAttributes(rel) * sizeof(bool)); + values = palloc0(RelationGetNumberOfAttributes(rel) * sizeof(*values)); + nulls = palloc0(RelationGetNumberOfAttributes(rel) * sizeof(*nulls)); + replaces = palloc0(RelationGetNumberOfAttributes(rel) * sizeof(*replaces)); namestrcpy(&nameattrdata, new_name); values[Anum_name - 1] = NameGetDatum(&nameattrdata); replaces[Anum_name - 1] = true; @@ -802,9 +802,9 @@ AlterObjectNamespace_internal(Relation rel, Oid objid, Oid nspOid) nspOid); /* Build modified tuple */ - values = palloc0(RelationGetNumberOfAttributes(rel) * sizeof(Datum)); - nulls = palloc0(RelationGetNumberOfAttributes(rel) * sizeof(bool)); - replaces = palloc0(RelationGetNumberOfAttributes(rel) * sizeof(bool)); + values = palloc0(RelationGetNumberOfAttributes(rel) * sizeof(*values)); + nulls = palloc0(RelationGetNumberOfAttributes(rel) * sizeof(*nulls)); + replaces = palloc0(RelationGetNumberOfAttributes(rel) * sizeof(*replaces)); values[Anum_namespace - 1] = ObjectIdGetDatum(nspOid); replaces[Anum_namespace - 1] = true; newtup = heap_modify_tuple(tup, RelationGetDescr(rel), @@ -1012,9 +1012,9 @@ AlterObjectOwner_internal(Oid classId, Oid objectId, Oid new_ownerId) /* Build a modified tuple */ nattrs = RelationGetNumberOfAttributes(rel); - values = palloc0(nattrs * sizeof(Datum)); - nulls = palloc0(nattrs * sizeof(bool)); - replaces = palloc0(nattrs * sizeof(bool)); + values = palloc0(nattrs * sizeof(*values)); + nulls = palloc0(nattrs * sizeof(*nulls)); + replaces = palloc0(nattrs * sizeof(*replaces)); values[Anum_owner - 1] = ObjectIdGetDatum(new_ownerId); replaces[Anum_owner - 1] = true; diff --git a/src/backend/commands/analyze.c b/src/backend/commands/analyze.c index 5e2a7a8234e..ca1bf9b6557 100644 --- a/src/backend/commands/analyze.c +++ b/src/backend/commands/analyze.c @@ -380,7 +380,7 @@ do_analyze_rel(Relation onerel, const VacuumParams params, ListCell *le; vacattrstats = (VacAttrStats **) palloc(list_length(va_cols) * - sizeof(VacAttrStats *)); + sizeof(*vacattrstats)); tcnt = 0; foreach(le, va_cols) { @@ -409,7 +409,7 @@ do_analyze_rel(Relation onerel, const VacuumParams params, { attr_cnt = onerel->rd_att->natts; vacattrstats = (VacAttrStats **) - palloc(attr_cnt * sizeof(VacAttrStats *)); + palloc(attr_cnt * sizeof(*vacattrstats)); tcnt = 0; for (i = 1; i <= attr_cnt; i++) { @@ -452,7 +452,7 @@ do_analyze_rel(Relation onerel, const VacuumParams params, indexdata = NULL; if (nindexes > 0) { - indexdata = (AnlIndexData *) palloc0(nindexes * sizeof(AnlIndexData)); + indexdata = (AnlIndexData *) palloc0(nindexes * sizeof(*indexdata)); for (ind = 0; ind < nindexes; ind++) { AnlIndexData *thisdata = &indexdata[ind]; @@ -465,7 +465,7 @@ do_analyze_rel(Relation onerel, const VacuumParams params, ListCell *indexpr_item = list_head(indexInfo->ii_Expressions); thisdata->vacattrstats = (VacAttrStats **) - palloc(indexInfo->ii_NumIndexAttrs * sizeof(VacAttrStats *)); + palloc(indexInfo->ii_NumIndexAttrs * sizeof(*thisdata->vacattrstats)); tcnt = 0; for (i = 0; i < indexInfo->ii_NumIndexAttrs; i++) { @@ -528,7 +528,7 @@ do_analyze_rel(Relation onerel, const VacuumParams params, /* * Acquire the sample rows */ - rows = (HeapTuple *) palloc(targrows * sizeof(HeapTuple)); + rows = (HeapTuple *) palloc(targrows * sizeof(*rows)); pgstat_progress_update_param(PROGRESS_ANALYZE_PHASE, inh ? PROGRESS_ANALYZE_PHASE_ACQUIRE_SAMPLE_ROWS_INH : PROGRESS_ANALYZE_PHASE_ACQUIRE_SAMPLE_ROWS); @@ -923,8 +923,8 @@ compute_index_stats(Relation onerel, double totalrows, predicate = ExecPrepareQual(indexInfo->ii_Predicate, estate); /* Compute and save index expression values */ - exprvals = (Datum *) palloc(numrows * attr_cnt * sizeof(Datum)); - exprnulls = (bool *) palloc(numrows * attr_cnt * sizeof(bool)); + exprvals = (Datum *) palloc(numrows * attr_cnt * sizeof(*exprvals)); + exprnulls = (bool *) palloc(numrows * attr_cnt * sizeof(*exprnulls)); numindexrows = 0; tcnt = 0; for (rowno = 0; rowno < numrows; rowno++) @@ -1443,10 +1443,10 @@ acquire_inherited_sample_rows(Relation onerel, int elevel, * Identify acquirefuncs to use, and count blocks in all the relations. * The result could overflow BlockNumber, so we use double arithmetic. */ - rels = (Relation *) palloc(list_length(tableOIDs) * sizeof(Relation)); + rels = (Relation *) palloc(list_length(tableOIDs) * sizeof(*rels)); acquirefuncs = (AcquireSampleRowsFunc *) - palloc(list_length(tableOIDs) * sizeof(AcquireSampleRowsFunc)); - relblocks = (double *) palloc(list_length(tableOIDs) * sizeof(double)); + palloc(list_length(tableOIDs) * sizeof(*acquirefuncs)); + relblocks = (double *) palloc(list_length(tableOIDs) * sizeof(*relblocks)); totalblocks = 0; nrels = 0; has_child = false; @@ -1721,7 +1721,7 @@ update_attstats(Oid relid, bool inh, int natts, VacAttrStats **vacattrstats) if (stats->stanumbers[k] != NULL) { int nnum = stats->numnumbers[k]; - Datum *numdatums = (Datum *) palloc(nnum * sizeof(Datum)); + Datum *numdatums = (Datum *) palloc(nnum * sizeof(*numdatums)); ArrayType *arry; for (n = 0; n < nnum; n++) @@ -2093,7 +2093,7 @@ compute_distinct_stats(VacAttrStatsP stats, track_max = 2 * num_mcv; if (track_max < 10) track_max = 10; - track = (TrackItem *) palloc(track_max * sizeof(TrackItem)); + track = (TrackItem *) palloc(track_max * sizeof(*track)); track_cnt = 0; fmgr_info(mystats->eqfunc, &f_cmpeq); @@ -2330,7 +2330,7 @@ compute_distinct_stats(VacAttrStatsP stats, if (num_mcv > 0) { - mcv_counts = (int *) palloc(num_mcv * sizeof(int)); + mcv_counts = (int *) palloc(num_mcv * sizeof(*mcv_counts)); for (i = 0; i < num_mcv; i++) mcv_counts[i] = track[i].count; @@ -2350,8 +2350,8 @@ compute_distinct_stats(VacAttrStatsP stats, /* Must copy the target values into anl_context */ old_context = MemoryContextSwitchTo(stats->anl_context); - mcv_values = (Datum *) palloc(num_mcv * sizeof(Datum)); - mcv_freqs = (float4 *) palloc(num_mcv * sizeof(float4)); + mcv_values = (Datum *) palloc(num_mcv * sizeof(*mcv_values)); + mcv_freqs = (float4 *) palloc(num_mcv * sizeof(*mcv_freqs)); for (i = 0; i < num_mcv; i++) { mcv_values[i] = datumCopy(track[i].value, @@ -2429,9 +2429,9 @@ compute_scalar_stats(VacAttrStatsP stats, int num_bins = stats->attstattarget; StdAnalyzeData *mystats = (StdAnalyzeData *) stats->extra_data; - values = (ScalarItem *) palloc(samplerows * sizeof(ScalarItem)); - tupnoLink = (int *) palloc(samplerows * sizeof(int)); - track = (ScalarMCVItem *) palloc(num_mcv * sizeof(ScalarMCVItem)); + values = (ScalarItem *) palloc(samplerows * sizeof(*values)); + tupnoLink = (int *) palloc(samplerows * sizeof(*tupnoLink)); + track = (ScalarMCVItem *) palloc(num_mcv * sizeof(*track)); memset(&ssup, 0, sizeof(ssup)); ssup.ssup_cxt = CurrentMemoryContext; @@ -2695,7 +2695,7 @@ compute_scalar_stats(VacAttrStatsP stats, if (num_mcv > 0) { - mcv_counts = (int *) palloc(num_mcv * sizeof(int)); + mcv_counts = (int *) palloc(num_mcv * sizeof(*mcv_counts)); for (i = 0; i < num_mcv; i++) mcv_counts[i] = track[i].count; @@ -2715,8 +2715,8 @@ compute_scalar_stats(VacAttrStatsP stats, /* Must copy the target values into anl_context */ old_context = MemoryContextSwitchTo(stats->anl_context); - mcv_values = (Datum *) palloc(num_mcv * sizeof(Datum)); - mcv_freqs = (float4 *) palloc(num_mcv * sizeof(float4)); + mcv_values = (Datum *) palloc(num_mcv * sizeof(*mcv_values)); + mcv_freqs = (float4 *) palloc(num_mcv * sizeof(*mcv_freqs)); for (i = 0; i < num_mcv; i++) { mcv_values[i] = datumCopy(values[track[i].first].value, @@ -2810,7 +2810,7 @@ compute_scalar_stats(VacAttrStatsP stats, /* Must copy the target values into anl_context */ old_context = MemoryContextSwitchTo(stats->anl_context); - hist_values = (Datum *) palloc(num_hist * sizeof(Datum)); + hist_values = (Datum *) palloc(num_hist * sizeof(*hist_values)); /* * The object of this loop is to copy the first and last values[] diff --git a/src/backend/commands/async.c b/src/backend/commands/async.c index eb86402cae4..b37d3789bd8 100644 --- a/src/backend/commands/async.c +++ b/src/backend/commands/async.c @@ -1592,8 +1592,8 @@ SignalBackends(void) * XXX in principle these pallocs could fail, which would be bad. Maybe * preallocate the arrays? They're not that large, though. */ - pids = (int32 *) palloc(MaxBackends * sizeof(int32)); - procnos = (ProcNumber *) palloc(MaxBackends * sizeof(ProcNumber)); + pids = (int32 *) palloc(MaxBackends * sizeof(*pids)); + procnos = (ProcNumber *) palloc(MaxBackends * sizeof(*procnos)); count = 0; LWLockAcquire(NotifyQueueLock, LW_EXCLUSIVE); diff --git a/src/backend/commands/collationcmds.c b/src/backend/commands/collationcmds.c index 8acbfbbeda0..333c6d99180 100644 --- a/src/backend/commands/collationcmds.c +++ b/src/backend/commands/collationcmds.c @@ -862,7 +862,7 @@ pg_import_system_collations(PG_FUNCTION_ARGS) /* expansible array of aliases */ maxaliases = 100; - aliases = (CollAliasData *) palloc(maxaliases * sizeof(CollAliasData)); + aliases = (CollAliasData *) palloc(maxaliases * sizeof(*aliases)); naliases = 0; locale_a_handle = OpenPipeStream("locale -a", "r"); diff --git a/src/backend/commands/copyfrom.c b/src/backend/commands/copyfrom.c index 2ae3d2ba86e..dbd2b537422 100644 --- a/src/backend/commands/copyfrom.c +++ b/src/backend/commands/copyfrom.c @@ -192,7 +192,7 @@ CopyFromTextLikeStart(CopyFromState cstate, TupleDesc tupDesc) */ attr_count = list_length(cstate->attnumlist); cstate->max_fields = attr_count; - cstate->raw_fields = (char **) palloc(attr_count * sizeof(char *)); + cstate->raw_fields = (char **) palloc(attr_count * sizeof(*cstate->raw_fields)); } /* @@ -1589,7 +1589,7 @@ BeginCopyFrom(ParseState *pstate, num_phys_attrs = tupDesc->natts; /* Convert FORCE_NOT_NULL name list to per-column flags, check validity */ - cstate->opts.force_notnull_flags = (bool *) palloc0(num_phys_attrs * sizeof(bool)); + cstate->opts.force_notnull_flags = (bool *) palloc0(num_phys_attrs * sizeof(*cstate->opts.force_notnull_flags)); if (cstate->opts.force_notnull_all) MemSet(cstate->opts.force_notnull_flags, true, num_phys_attrs * sizeof(bool)); else if (cstate->opts.force_notnull) @@ -1632,7 +1632,7 @@ BeginCopyFrom(ParseState *pstate, cstate->escontext = NULL; /* Convert FORCE_NULL name list to per-column flags, check validity */ - cstate->opts.force_null_flags = (bool *) palloc0(num_phys_attrs * sizeof(bool)); + cstate->opts.force_null_flags = (bool *) palloc0(num_phys_attrs * sizeof(*cstate->opts.force_null_flags)); if (cstate->opts.force_null_all) MemSet(cstate->opts.force_null_flags, true, num_phys_attrs * sizeof(bool)); else if (cstate->opts.force_null) @@ -1663,7 +1663,7 @@ BeginCopyFrom(ParseState *pstate, List *attnums; ListCell *cur; - cstate->convert_select_flags = (bool *) palloc0(num_phys_attrs * sizeof(bool)); + cstate->convert_select_flags = (bool *) palloc0(num_phys_attrs * sizeof(*cstate->convert_select_flags)); attnums = CopyGetAttnums(tupDesc, cstate->rel, cstate->opts.convert_select); @@ -1749,10 +1749,10 @@ BeginCopyFrom(ParseState *pstate, * the input function), and info about defaults and constraints. (Which * input function we use depends on text/binary format choice.) */ - in_functions = (FmgrInfo *) palloc(num_phys_attrs * sizeof(FmgrInfo)); - typioparams = (Oid *) palloc(num_phys_attrs * sizeof(Oid)); - defmap = (int *) palloc(num_phys_attrs * sizeof(int)); - defexprs = (ExprState **) palloc(num_phys_attrs * sizeof(ExprState *)); + in_functions = (FmgrInfo *) palloc(num_phys_attrs * sizeof(*in_functions)); + typioparams = (Oid *) palloc(num_phys_attrs * sizeof(*typioparams)); + defmap = (int *) palloc(num_phys_attrs * sizeof(*defmap)); + defexprs = (ExprState **) palloc(num_phys_attrs * sizeof(*defexprs)); for (int attnum = 1; attnum <= num_phys_attrs; attnum++) { @@ -1818,7 +1818,7 @@ BeginCopyFrom(ParseState *pstate, } } - cstate->defaults = (bool *) palloc0(tupDesc->natts * sizeof(bool)); + cstate->defaults = (bool *) palloc0(tupDesc->natts * sizeof(*cstate->defaults)); /* initialize progress */ pgstat_progress_start_command(PROGRESS_COMMAND_COPY, diff --git a/src/backend/commands/copyto.c b/src/backend/commands/copyto.c index dae91630ac3..a5597dd22f4 100644 --- a/src/backend/commands/copyto.c +++ b/src/backend/commands/copyto.c @@ -891,7 +891,7 @@ BeginCopyTo(ParseState *pstate, num_phys_attrs = tupDesc->natts; /* Convert FORCE_QUOTE name list to per-column flags, check validity */ - cstate->opts.force_quote_flags = (bool *) palloc0(num_phys_attrs * sizeof(bool)); + cstate->opts.force_quote_flags = (bool *) palloc0(num_phys_attrs * sizeof(*cstate->opts.force_quote_flags)); if (cstate->opts.force_quote_all) { MemSet(cstate->opts.force_quote_flags, true, num_phys_attrs * sizeof(bool)); @@ -1081,7 +1081,7 @@ DoCopyTo(CopyToState cstate) cstate->fe_msgbuf = makeStringInfo(); /* Get info about the columns we need to process. */ - cstate->out_functions = (FmgrInfo *) palloc(num_phys_attrs * sizeof(FmgrInfo)); + cstate->out_functions = (FmgrInfo *) palloc(num_phys_attrs * sizeof(*cstate->out_functions)); foreach(cur, cstate->attnumlist) { int attnum = lfirst_int(cur); diff --git a/src/backend/commands/dbcommands.c b/src/backend/commands/dbcommands.c index d1f3be89b35..1794b3b0d67 100644 --- a/src/backend/commands/dbcommands.c +++ b/src/backend/commands/dbcommands.c @@ -3052,7 +3052,7 @@ remove_dbtablespaces(Oid db_id) return; } - tablespace_ids = (Oid *) palloc(ntblspc * sizeof(Oid)); + tablespace_ids = (Oid *) palloc(ntblspc * sizeof(*tablespace_ids)); i = 0; foreach(cell, ltblspc) tablespace_ids[i++] = lfirst_oid(cell); diff --git a/src/backend/commands/explain.c b/src/backend/commands/explain.c index 5a6390631eb..ca1d5db1f5d 100644 --- a/src/backend/commands/explain.c +++ b/src/backend/commands/explain.c @@ -4982,10 +4982,10 @@ ExplainCreateWorkersState(int num_workers) wstate = palloc_object(ExplainWorkersState); wstate->num_workers = num_workers; - wstate->worker_inited = (bool *) palloc0(num_workers * sizeof(bool)); + wstate->worker_inited = (bool *) palloc0(num_workers * sizeof(*wstate->worker_inited)); wstate->worker_str = (StringInfoData *) - palloc0(num_workers * sizeof(StringInfoData)); - wstate->worker_state_save = (int *) palloc(num_workers * sizeof(int)); + palloc0(num_workers * sizeof(*wstate->worker_str)); + wstate->worker_state_save = (int *) palloc(num_workers * sizeof(*wstate->worker_state_save)); return wstate; } diff --git a/src/backend/commands/explain_dr.c b/src/backend/commands/explain_dr.c index 5833aa80fb5..78f6dbb20ba 100644 --- a/src/backend/commands/explain_dr.c +++ b/src/backend/commands/explain_dr.c @@ -63,7 +63,7 @@ serialize_prepare_info(SerializeDestReceiver *receiver, if (nattrs <= 0) return; - receiver->finfos = (FmgrInfo *) palloc0(nattrs * sizeof(FmgrInfo)); + receiver->finfos = (FmgrInfo *) palloc0(nattrs * sizeof(*receiver->finfos)); for (int i = 0; i < nattrs; i++) { diff --git a/src/backend/commands/explain_state.c b/src/backend/commands/explain_state.c index a6623f8fa52..7261c960d05 100644 --- a/src/backend/commands/explain_state.c +++ b/src/backend/commands/explain_state.c @@ -285,7 +285,7 @@ SetExplainExtensionState(ExplainState *es, int extension_id, void *opaque) es->extension_state_allocated = Max(16, pg_nextpower2_32(extension_id + 1)); es->extension_state = - palloc0(es->extension_state_allocated * sizeof(void *)); + palloc0(es->extension_state_allocated * sizeof(*es->extension_state)); } /* If there's an array but it's currently full, expand it. */ diff --git a/src/backend/commands/extension.c b/src/backend/commands/extension.c index c43b74e319e..97dfe551064 100644 --- a/src/backend/commands/extension.c +++ b/src/backend/commands/extension.c @@ -2557,7 +2557,7 @@ convert_requires_to_datum(List *requires) ListCell *lc; ndatums = list_length(requires); - datums = (Datum *) palloc(ndatums * sizeof(Datum)); + datums = (Datum *) palloc(ndatums * sizeof(*datums)); ndatums = 0; foreach(lc, requires) { diff --git a/src/backend/commands/functioncmds.c b/src/backend/commands/functioncmds.c index 8a435cd93db..41f4ade0e1b 100644 --- a/src/backend/commands/functioncmds.c +++ b/src/backend/commands/functioncmds.c @@ -212,10 +212,10 @@ interpret_function_parameter_list(ParseState *pstate, *variadicArgType = InvalidOid; /* default result */ *requiredResultType = InvalidOid; /* default result */ - inTypes = (Oid *) palloc(parameterCount * sizeof(Oid)); - allTypes = (Datum *) palloc(parameterCount * sizeof(Datum)); - paramModes = (Datum *) palloc(parameterCount * sizeof(Datum)); - paramNames = (Datum *) palloc0(parameterCount * sizeof(Datum)); + inTypes = (Oid *) palloc(parameterCount * sizeof(*inTypes)); + allTypes = (Datum *) palloc(parameterCount * sizeof(*allTypes)); + paramModes = (Datum *) palloc(parameterCount * sizeof(*paramModes)); + paramNames = (Datum *) palloc0(parameterCount * sizeof(*paramNames)); *parameterDefaults = NIL; /* Scan the list and extract data into work arrays */ @@ -917,8 +917,8 @@ interpret_AS_clause(Oid languageOid, const char *languageName, pinfo->fname = funcname; pinfo->nargs = list_length(parameterTypes); - pinfo->argtypes = (Oid *) palloc(pinfo->nargs * sizeof(Oid)); - pinfo->argnames = (char **) palloc(pinfo->nargs * sizeof(char *)); + pinfo->argtypes = (Oid *) palloc(pinfo->nargs * sizeof(*pinfo->argtypes)); + pinfo->argnames = (char **) palloc(pinfo->nargs * sizeof(*pinfo->argnames)); for (int i = 0; i < list_length(parameterTypes); i++) { char *s = strVal(list_nth(inParameterNames, i)); @@ -1226,7 +1226,7 @@ CreateFunction(ParseState *pstate, CreateFunctionStmt *stmt) Datum *arr; int i; - arr = palloc(list_length(trftypes_list) * sizeof(Datum)); + arr = palloc(list_length(trftypes_list) * sizeof(*arr)); i = 0; foreach(lc, trftypes_list) arr[i++] = ObjectIdGetDatum(lfirst_oid(lc)); diff --git a/src/backend/commands/policy.c b/src/backend/commands/policy.c index 5bd5f8c9968..f55c915545c 100644 --- a/src/backend/commands/policy.c +++ b/src/backend/commands/policy.c @@ -151,7 +151,7 @@ policy_role_list_to_array(List *roles, int *num_roles) } *num_roles = list_length(roles); - role_oids = (Datum *) palloc(*num_roles * sizeof(Datum)); + role_oids = (Datum *) palloc(*num_roles * sizeof(*role_oids)); foreach(cell, roles) { diff --git a/src/backend/commands/subscriptioncmds.c b/src/backend/commands/subscriptioncmds.c index abbcaff0838..12e6130d87b 100644 --- a/src/backend/commands/subscriptioncmds.c +++ b/src/backend/commands/subscriptioncmds.c @@ -975,8 +975,8 @@ AlterSubscription_refresh(Subscription *sub, bool copy_data, * allocate separate arrays for table OIDs and sequence OIDs based on * the total number of relations (subrel_count). */ - subrel_local_oids = palloc(subrel_count * sizeof(Oid)); - subseq_local_oids = palloc(subrel_count * sizeof(Oid)); + subrel_local_oids = palloc(subrel_count * sizeof(*subrel_local_oids)); + subseq_local_oids = palloc(subrel_count * sizeof(*subseq_local_oids)); foreach(lc, subrel_states) { SubscriptionRelState *relstate = (SubscriptionRelState *) lfirst(lc); @@ -1008,7 +1008,7 @@ AlterSubscription_refresh(Subscription *sub, bool copy_data, * step. */ off = 0; - pubrel_local_oids = palloc(list_length(pubrels) * sizeof(Oid)); + pubrel_local_oids = palloc(list_length(pubrels) * sizeof(*pubrel_local_oids)); foreach_ptr(PublicationRelKind, pubrelinfo, pubrels) { diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 1c9ef53be20..94669e72329 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -2090,7 +2090,7 @@ ExecuteTruncateGuts(List *explicit_rels, */ estate = CreateExecutorState(); resultRelInfos = (ResultRelInfo *) - palloc(list_length(rels) * sizeof(ResultRelInfo)); + palloc(list_length(rels) * sizeof(*resultRelInfos)); resultRelInfo = resultRelInfos; foreach(cell, rels) { @@ -2297,7 +2297,7 @@ ExecuteTruncateGuts(List *explicit_rels, /* should only get here if wal_level >= logical */ Assert(XLogLogicalInfoActive()); - logrelids = palloc(list_length(relids_logged) * sizeof(Oid)); + logrelids = palloc(list_length(relids_logged) * sizeof(*logrelids)); foreach(cell, relids_logged) logrelids[i++] = lfirst_oid(cell); diff --git a/src/backend/commands/tablespace.c b/src/backend/commands/tablespace.c index df31eace47a..77d81098162 100644 --- a/src/backend/commands/tablespace.c +++ b/src/backend/commands/tablespace.c @@ -1227,7 +1227,7 @@ check_temp_tablespaces(char **newval, void **extra, GucSource source) ListCell *l; /* temporary workspace until we are done verifying the list */ - tblSpcs = (Oid *) palloc(list_length(namelist) * sizeof(Oid)); + tblSpcs = (Oid *) palloc(list_length(namelist) * sizeof(*tblSpcs)); numSpcs = 0; foreach(l, namelist) { diff --git a/src/backend/commands/trigger.c b/src/backend/commands/trigger.c index 12c97f2c023..35868e10e31 100644 --- a/src/backend/commands/trigger.c +++ b/src/backend/commands/trigger.c @@ -932,7 +932,7 @@ CreateTriggerFiringOn(CreateTrigStmt *stmt, const char *queryString, ListCell *cell; int i = 0; - columns = (int16 *) palloc(ncolumns * sizeof(int16)); + columns = (int16 *) palloc(ncolumns * sizeof(*columns)); foreach(cell, stmt->columns) { char *name = strVal(lfirst(cell)); @@ -1876,7 +1876,7 @@ RelationBuildTriggers(Relation relation) * necessary) */ maxtrigs = 16; - triggers = (Trigger *) palloc(maxtrigs * sizeof(Trigger)); + triggers = (Trigger *) palloc(maxtrigs * sizeof(*triggers)); numtrigs = 0; /* @@ -1926,7 +1926,7 @@ RelationBuildTriggers(Relation relation) build->tgnattr = pg_trigger->tgattr.dim1; if (build->tgnattr > 0) { - build->tgattr = (int16 *) palloc(build->tgnattr * sizeof(int16)); + build->tgattr = (int16 *) palloc(build->tgnattr * sizeof(*build->tgattr)); memcpy(build->tgattr, &(pg_trigger->tgattr.values), build->tgnattr * sizeof(int16)); } @@ -1944,7 +1944,7 @@ RelationBuildTriggers(Relation relation) elog(ERROR, "tgargs is null in trigger for relation \"%s\"", RelationGetRelationName(relation)); p = (char *) VARDATA_ANY(val); - build->tgargs = (char **) palloc(build->tgnargs * sizeof(char *)); + build->tgargs = (char **) palloc(build->tgnargs * sizeof(*build->tgargs)); for (i = 0; i < build->tgnargs; i++) { build->tgargs[i] = pstrdup(p); @@ -2099,7 +2099,7 @@ CopyTriggerDesc(TriggerDesc *trigdesc) newdesc = palloc_object(TriggerDesc); memcpy(newdesc, trigdesc, sizeof(TriggerDesc)); - trigger = (Trigger *) palloc(trigdesc->numtriggers * sizeof(Trigger)); + trigger = (Trigger *) palloc(trigdesc->numtriggers * sizeof(*trigger)); memcpy(trigger, trigdesc->triggers, trigdesc->numtriggers * sizeof(Trigger)); newdesc->triggers = trigger; @@ -2111,7 +2111,7 @@ CopyTriggerDesc(TriggerDesc *trigdesc) { int16 *newattr; - newattr = (int16 *) palloc(trigger->tgnattr * sizeof(int16)); + newattr = (int16 *) palloc(trigger->tgnattr * sizeof(*newattr)); memcpy(newattr, trigger->tgattr, trigger->tgnattr * sizeof(int16)); trigger->tgattr = newattr; @@ -2121,7 +2121,7 @@ CopyTriggerDesc(TriggerDesc *trigdesc) char **newargs; int16 j; - newargs = (char **) palloc(trigger->tgnargs * sizeof(char *)); + newargs = (char **) palloc(trigger->tgnargs * sizeof(*newargs)); for (j = 0; j < trigger->tgnargs; j++) newargs[j] = pstrdup(trigger->tgargs[j]); trigger->tgargs = newargs; diff --git a/src/backend/commands/vacuum.c b/src/backend/commands/vacuum.c index 0528d1b6ecb..d70afb71c9c 100644 --- a/src/backend/commands/vacuum.c +++ b/src/backend/commands/vacuum.c @@ -2374,7 +2374,7 @@ vac_open_indexes(Relation relation, LOCKMODE lockmode, i = list_length(indexoidlist); if (i > 0) - *Irel = (Relation *) palloc(i * sizeof(Relation)); + *Irel = (Relation *) palloc(i * sizeof(**Irel)); else *Irel = NULL; diff --git a/src/backend/executor/execExprInterp.c b/src/backend/executor/execExprInterp.c index 5e7bd933afc..9f77179e86e 100644 --- a/src/backend/executor/execExprInterp.c +++ b/src/backend/executor/execExprInterp.c @@ -3447,10 +3447,10 @@ ExecEvalArrayExpr(ExprState *state, ExprEvalStep *op) char *dat; int iitem; - subdata = (char **) palloc(nelems * sizeof(char *)); - subbitmaps = (bits8 **) palloc(nelems * sizeof(bits8 *)); - subbytes = (int *) palloc(nelems * sizeof(int)); - subnitems = (int *) palloc(nelems * sizeof(int)); + subdata = (char **) palloc(nelems * sizeof(*subdata)); + subbitmaps = (bits8 **) palloc(nelems * sizeof(*subbitmaps)); + subbytes = (int *) palloc(nelems * sizeof(*subbytes)); + subnitems = (int *) palloc(nelems * sizeof(*subnitems)); /* loop through and get data area from each element */ for (int elemoff = 0; elemoff < nelems; elemoff++) @@ -3501,9 +3501,9 @@ ExecEvalArrayExpr(ExprState *state, ExprEvalStep *op) errmsg("number of array dimensions (%d) exceeds the maximum allowed (%d)", ndims, MAXDIM))); - elem_dims = (int *) palloc(elem_ndims * sizeof(int)); + elem_dims = (int *) palloc(elem_ndims * sizeof(*elem_dims)); memcpy(elem_dims, ARR_DIMS(array), elem_ndims * sizeof(int)); - elem_lbs = (int *) palloc(elem_ndims * sizeof(int)); + elem_lbs = (int *) palloc(elem_ndims * sizeof(*elem_lbs)); memcpy(elem_lbs, ARR_LBOUND(array), elem_ndims * sizeof(int)); firstone = false; diff --git a/src/backend/executor/execGrouping.c b/src/backend/executor/execGrouping.c index 8eb4c25e1cb..1f98f53b669 100644 --- a/src/backend/executor/execGrouping.c +++ b/src/backend/executor/execGrouping.c @@ -72,7 +72,7 @@ execTuplesMatchPrepare(TupleDesc desc, if (numCols == 0) return NULL; - eqFunctions = (Oid *) palloc(numCols * sizeof(Oid)); + eqFunctions = (Oid *) palloc(numCols * sizeof(*eqFunctions)); /* lookup equality functions */ for (i = 0; i < numCols; i++) @@ -104,8 +104,8 @@ execTuplesHashPrepare(int numCols, { int i; - *eqFuncOids = (Oid *) palloc(numCols * sizeof(Oid)); - *hashFunctions = (FmgrInfo *) palloc(numCols * sizeof(FmgrInfo)); + *eqFuncOids = (Oid *) palloc(numCols * sizeof(**eqFuncOids)); + *hashFunctions = (FmgrInfo *) palloc(numCols * sizeof(**hashFunctions)); for (i = 0; i < numCols; i++) { diff --git a/src/backend/executor/execJunk.c b/src/backend/executor/execJunk.c index 3f196de1ad2..cd1d6a84587 100644 --- a/src/backend/executor/execJunk.c +++ b/src/backend/executor/execJunk.c @@ -93,7 +93,7 @@ ExecInitJunkFilter(List *targetList, TupleTableSlot *slot) AttrNumber cleanResno; ListCell *t; - cleanMap = (AttrNumber *) palloc(cleanLength * sizeof(AttrNumber)); + cleanMap = (AttrNumber *) palloc(cleanLength * sizeof(*cleanMap)); cleanResno = 0; foreach(t, targetList) { @@ -165,7 +165,7 @@ ExecInitJunkFilterConversion(List *targetList, cleanLength = cleanTupType->natts; if (cleanLength > 0) { - cleanMap = (AttrNumber *) palloc0(cleanLength * sizeof(AttrNumber)); + cleanMap = (AttrNumber *) palloc0(cleanLength * sizeof(*cleanMap)); t = list_head(targetList); for (i = 0; i < cleanLength; i++) { diff --git a/src/backend/executor/execParallel.c b/src/backend/executor/execParallel.c index 26200c5a3d6..67f7924508c 100644 --- a/src/backend/executor/execParallel.c +++ b/src/backend/executor/execParallel.c @@ -568,7 +568,7 @@ ExecParallelSetupTupleQueues(ParallelContext *pcxt, bool reinitialize) /* Allocate memory for shared memory queue handles. */ responseq = (shm_mq_handle **) - palloc(pcxt->nworkers * sizeof(shm_mq_handle *)); + palloc(pcxt->nworkers * sizeof(*responseq)); /* * If not reinitializing, allocate space from the DSM for the queues; diff --git a/src/backend/executor/execSRF.c b/src/backend/executor/execSRF.c index a03fe780a02..8b0b8fd0264 100644 --- a/src/backend/executor/execSRF.c +++ b/src/backend/executor/execSRF.c @@ -337,7 +337,7 @@ ExecMakeTableFunctionResult(SetExprState *setexpr, int natts = expectedDesc->natts; bool *nullflags; - nullflags = (bool *) palloc(natts * sizeof(bool)); + nullflags = (bool *) palloc(natts * sizeof(*nullflags)); memset(nullflags, true, natts * sizeof(bool)); tuplestore_putvalues(tupstore, expectedDesc, NULL, nullflags); } @@ -405,7 +405,7 @@ no_function_result: int natts = expectedDesc->natts; bool *nullflags; - nullflags = (bool *) palloc(natts * sizeof(bool)); + nullflags = (bool *) palloc(natts * sizeof(*nullflags)); memset(nullflags, true, natts * sizeof(bool)); tuplestore_putvalues(tupstore, expectedDesc, NULL, nullflags); } diff --git a/src/backend/executor/execTuples.c b/src/backend/executor/execTuples.c index b0dc2cfa66f..d8e86d3735a 100644 --- a/src/backend/executor/execTuples.c +++ b/src/backend/executor/execTuples.c @@ -2291,9 +2291,9 @@ TupleDescGetAttInMetadata(TupleDesc tupdesc) /* * Gather info needed later to call the "in" function for each attribute */ - attinfuncinfo = (FmgrInfo *) palloc0(natts * sizeof(FmgrInfo)); - attioparams = (Oid *) palloc0(natts * sizeof(Oid)); - atttypmods = (int32 *) palloc0(natts * sizeof(int32)); + attinfuncinfo = (FmgrInfo *) palloc0(natts * sizeof(*attinfuncinfo)); + attioparams = (Oid *) palloc0(natts * sizeof(*attioparams)); + atttypmods = (int32 *) palloc0(natts * sizeof(*atttypmods)); for (i = 0; i < natts; i++) { @@ -2330,8 +2330,8 @@ BuildTupleFromCStrings(AttInMetadata *attinmeta, char **values) int i; HeapTuple tuple; - dvalues = (Datum *) palloc(natts * sizeof(Datum)); - nulls = (bool *) palloc(natts * sizeof(bool)); + dvalues = (Datum *) palloc(natts * sizeof(*dvalues)); + nulls = (bool *) palloc(natts * sizeof(*nulls)); /* * Call the "in" function for each non-dropped attribute, even for nulls, diff --git a/src/backend/executor/execUtils.c b/src/backend/executor/execUtils.c index fdc65c2b42b..9489bb73882 100644 --- a/src/backend/executor/execUtils.c +++ b/src/backend/executor/execUtils.c @@ -797,7 +797,7 @@ ExecInitRangeTable(EState *estate, List *rangeTable, List *permInfos, * and stored here as needed. */ estate->es_relations = (Relation *) - palloc0(estate->es_range_table_size * sizeof(Relation)); + palloc0(estate->es_range_table_size * sizeof(*estate->es_relations)); /* * es_result_relations and es_rowmarks are also parallel to @@ -891,7 +891,7 @@ ExecInitResultRelation(EState *estate, ResultRelInfo *resultRelInfo, if (estate->es_result_relations == NULL) estate->es_result_relations = (ResultRelInfo **) - palloc0(estate->es_range_table_size * sizeof(ResultRelInfo *)); + palloc0(estate->es_range_table_size * sizeof(*estate->es_result_relations)); estate->es_result_relations[rti - 1] = resultRelInfo; /* diff --git a/src/backend/executor/functions.c b/src/backend/executor/functions.c index d9cc723daa0..53d1fcfabdb 100644 --- a/src/backend/executor/functions.c +++ b/src/backend/executor/functions.c @@ -274,7 +274,7 @@ prepare_sql_fn_parse_info(HeapTuple procedureTuple, Oid *argOidVect; int argnum; - argOidVect = (Oid *) palloc(nargs * sizeof(Oid)); + argOidVect = (Oid *) palloc(nargs * sizeof(*argOidVect)); memcpy(argOidVect, procedureStruct->proargtypes.values, nargs * sizeof(Oid)); diff --git a/src/backend/executor/instrument.c b/src/backend/executor/instrument.c index 9e11c662a7c..e9eddf7448c 100644 --- a/src/backend/executor/instrument.c +++ b/src/backend/executor/instrument.c @@ -33,7 +33,7 @@ InstrAlloc(int n, int instrument_options, bool async_mode) Instrumentation *instr; /* initialize all fields to zeroes, then modify as needed */ - instr = palloc0(n * sizeof(Instrumentation)); + instr = palloc0(n * sizeof(*instr)); if (instrument_options & (INSTRUMENT_BUFFERS | INSTRUMENT_TIMER | INSTRUMENT_WAL)) { bool need_buffers = (instrument_options & INSTRUMENT_BUFFERS) != 0; diff --git a/src/backend/executor/nodeAgg.c b/src/backend/executor/nodeAgg.c index a18556f62ec..f3a02a14a6d 100644 --- a/src/backend/executor/nodeAgg.c +++ b/src/backend/executor/nodeAgg.c @@ -1632,9 +1632,9 @@ find_hash_columns(AggState *aggstate) maxCols = bms_num_members(colnos) + perhash->numCols; perhash->hashGrpColIdxInput = - palloc(maxCols * sizeof(AttrNumber)); + palloc(maxCols * sizeof(*perhash->hashGrpColIdxInput)); perhash->hashGrpColIdxHash = - palloc(perhash->numCols * sizeof(AttrNumber)); + palloc(perhash->numCols * sizeof(*perhash->hashGrpColIdxHash)); /* Add all the grouping columns to colnos */ for (i = 0; i < perhash->numCols; i++) @@ -3558,8 +3558,8 @@ ExecInitAgg(Agg *node, EState *estate, int eflags) if (num_sets) { - phasedata->gset_lengths = palloc(num_sets * sizeof(int)); - phasedata->grouped_cols = palloc(num_sets * sizeof(Bitmapset *)); + phasedata->gset_lengths = palloc(num_sets * sizeof(*phasedata->gset_lengths)); + phasedata->grouped_cols = palloc(num_sets * sizeof(*phasedata->grouped_cols)); i = 0; foreach(l, aggnode->groupingSets) @@ -4317,13 +4317,13 @@ build_pertrans_for_aggref(AggStatePerTrans pertrans, /* Extract the sort information for use later */ pertrans->sortColIdx = - (AttrNumber *) palloc(numSortCols * sizeof(AttrNumber)); + (AttrNumber *) palloc(numSortCols * sizeof(*pertrans->sortColIdx)); pertrans->sortOperators = - (Oid *) palloc(numSortCols * sizeof(Oid)); + (Oid *) palloc(numSortCols * sizeof(*pertrans->sortOperators)); pertrans->sortCollations = - (Oid *) palloc(numSortCols * sizeof(Oid)); + (Oid *) palloc(numSortCols * sizeof(*pertrans->sortCollations)); pertrans->sortNullsFirst = - (bool *) palloc(numSortCols * sizeof(bool)); + (bool *) palloc(numSortCols * sizeof(*pertrans->sortNullsFirst)); i = 0; foreach(lc, sortlist) @@ -4350,7 +4350,7 @@ build_pertrans_for_aggref(AggStatePerTrans pertrans, Assert(numArguments > 0); Assert(list_length(aggref->aggdistinct) == numDistinctCols); - ops = palloc(numDistinctCols * sizeof(Oid)); + ops = palloc(numDistinctCols * sizeof(*ops)); i = 0; foreach(lc, aggref->aggdistinct) diff --git a/src/backend/executor/nodeAppend.c b/src/backend/executor/nodeAppend.c index 77c4dd9e4b1..e071a9a93b6 100644 --- a/src/backend/executor/nodeAppend.c +++ b/src/backend/executor/nodeAppend.c @@ -179,7 +179,7 @@ ExecInitAppend(Append *node, EState *estate, int eflags) } appendplanstates = (PlanState **) palloc(nplans * - sizeof(PlanState *)); + sizeof(*appendplanstates)); /* * call ExecInitNode on each of the valid plans to be executed and save @@ -256,7 +256,7 @@ ExecInitAppend(Append *node, EState *estate, int eflags) if (nasyncplans > 0) { appendstate->as_asyncrequests = (AsyncRequest **) - palloc0(nplans * sizeof(AsyncRequest *)); + palloc0(nplans * sizeof(*appendstate->as_asyncrequests)); i = -1; while ((i = bms_next_member(asyncplans, i)) >= 0) @@ -275,7 +275,7 @@ ExecInitAppend(Append *node, EState *estate, int eflags) } appendstate->as_asyncresults = (TupleTableSlot **) - palloc0(nasyncplans * sizeof(TupleTableSlot *)); + palloc0(nasyncplans * sizeof(*appendstate->as_asyncresults)); if (appendstate->as_valid_subplans_identified) classify_matching_subplans(appendstate); diff --git a/src/backend/executor/nodeBitmapAnd.c b/src/backend/executor/nodeBitmapAnd.c index 939907b6fcd..c28d402b7cf 100644 --- a/src/backend/executor/nodeBitmapAnd.c +++ b/src/backend/executor/nodeBitmapAnd.c @@ -69,7 +69,7 @@ ExecInitBitmapAnd(BitmapAnd *node, EState *estate, int eflags) */ nplans = list_length(node->bitmapplans); - bitmapplanstates = (PlanState **) palloc0(nplans * sizeof(PlanState *)); + bitmapplanstates = (PlanState **) palloc0(nplans * sizeof(*bitmapplanstates)); /* * create new BitmapAndState for our BitmapAnd node diff --git a/src/backend/executor/nodeBitmapOr.c b/src/backend/executor/nodeBitmapOr.c index 231760ec93d..bff717aaa64 100644 --- a/src/backend/executor/nodeBitmapOr.c +++ b/src/backend/executor/nodeBitmapOr.c @@ -70,7 +70,7 @@ ExecInitBitmapOr(BitmapOr *node, EState *estate, int eflags) */ nplans = list_length(node->bitmapplans); - bitmapplanstates = (PlanState **) palloc0(nplans * sizeof(PlanState *)); + bitmapplanstates = (PlanState **) palloc0(nplans * sizeof(*bitmapplanstates)); /* * create new BitmapOrState for our BitmapOr node diff --git a/src/backend/executor/nodeGatherMerge.c b/src/backend/executor/nodeGatherMerge.c index c04522fea4d..754a6abf959 100644 --- a/src/backend/executor/nodeGatherMerge.c +++ b/src/backend/executor/nodeGatherMerge.c @@ -408,7 +408,7 @@ gather_merge_setup(GatherMergeState *gm_state) * case the extra array entries go unused. */ gm_state->gm_slots = (TupleTableSlot **) - palloc0((nreaders + 1) * sizeof(TupleTableSlot *)); + palloc0((nreaders + 1) * sizeof(*gm_state->gm_slots)); /* Allocate the tuple slot and tuple array for each worker */ gm_state->gm_tuple_buffers = (GMReaderTupleBuffer *) diff --git a/src/backend/executor/nodeIncrementalSort.c b/src/backend/executor/nodeIncrementalSort.c index 975b0397e7a..6117b979d39 100644 --- a/src/backend/executor/nodeIncrementalSort.c +++ b/src/backend/executor/nodeIncrementalSort.c @@ -167,7 +167,7 @@ preparePresortedCols(IncrementalSortState *node) node->presorted_keys = (PresortedKeyData *) palloc(plannode->nPresortedCols * - sizeof(PresortedKeyData)); + sizeof(*node->presorted_keys)); /* Pre-cache comparison functions for each pre-sorted key. */ for (int i = 0; i < plannode->nPresortedCols; i++) diff --git a/src/backend/executor/nodeIndexscan.c b/src/backend/executor/nodeIndexscan.c index 72b135e5dcf..baa92b515c9 100644 --- a/src/backend/executor/nodeIndexscan.c +++ b/src/backend/executor/nodeIndexscan.c @@ -1027,9 +1027,9 @@ ExecInitIndexScan(IndexScan *node, EState *estate, int eflags) indexstate->iss_SortSupport = (SortSupportData *) palloc0(numOrderByKeys * sizeof(SortSupportData)); indexstate->iss_OrderByTypByVals = (bool *) - palloc(numOrderByKeys * sizeof(bool)); + palloc(numOrderByKeys * sizeof(*indexstate->iss_OrderByTypByVals)); indexstate->iss_OrderByTypLens = (int16 *) - palloc(numOrderByKeys * sizeof(int16)); + palloc(numOrderByKeys * sizeof(*indexstate->iss_OrderByTypLens)); i = 0; forboth(lco, node->indexorderbyops, lcx, node->indexorderbyorig) { @@ -1058,9 +1058,9 @@ ExecInitIndexScan(IndexScan *node, EState *estate, int eflags) /* allocate arrays to hold the re-calculated distances */ indexstate->iss_OrderByValues = (Datum *) - palloc(numOrderByKeys * sizeof(Datum)); + palloc(numOrderByKeys * sizeof(*indexstate->iss_OrderByValues)); indexstate->iss_OrderByNulls = (bool *) - palloc(numOrderByKeys * sizeof(bool)); + palloc(numOrderByKeys * sizeof(*indexstate->iss_OrderByNulls)); /* and initialize the reorder queue */ indexstate->iss_ReorderQueue = pairingheap_allocate(reorderqueue_cmp, @@ -1185,7 +1185,7 @@ ExecIndexBuildScanKeys(PlanState *planstate, Relation index, /* Allocate array_keys as large as it could possibly need to be */ array_keys = (IndexArrayKeyInfo *) - palloc0(n_scan_keys * sizeof(IndexArrayKeyInfo)); + palloc0(n_scan_keys * sizeof(*array_keys)); n_array_keys = 0; /* @@ -1276,7 +1276,7 @@ ExecIndexBuildScanKeys(PlanState *planstate, Relation index, { max_runtime_keys = 8; runtime_keys = (IndexRuntimeKeyInfo *) - palloc(max_runtime_keys * sizeof(IndexRuntimeKeyInfo)); + palloc(max_runtime_keys * sizeof(*runtime_keys)); } else { @@ -1400,7 +1400,7 @@ ExecIndexBuildScanKeys(PlanState *planstate, Relation index, { max_runtime_keys = 8; runtime_keys = (IndexRuntimeKeyInfo *) - palloc(max_runtime_keys * sizeof(IndexRuntimeKeyInfo)); + palloc(max_runtime_keys * sizeof(*runtime_keys)); } else { @@ -1518,7 +1518,7 @@ ExecIndexBuildScanKeys(PlanState *planstate, Relation index, { max_runtime_keys = 8; runtime_keys = (IndexRuntimeKeyInfo *) - palloc(max_runtime_keys * sizeof(IndexRuntimeKeyInfo)); + palloc(max_runtime_keys * sizeof(*runtime_keys)); } else { diff --git a/src/backend/executor/nodeMemoize.c b/src/backend/executor/nodeMemoize.c index 7444391e8a1..f5d719f9dea 100644 --- a/src/backend/executor/nodeMemoize.c +++ b/src/backend/executor/nodeMemoize.c @@ -1001,12 +1001,12 @@ ExecInitMemoize(Memoize *node, EState *estate, int eflags) mstate->probeslot = MakeSingleTupleTableSlot(mstate->hashkeydesc, &TTSOpsVirtual); - mstate->param_exprs = (ExprState **) palloc(nkeys * sizeof(ExprState *)); + mstate->param_exprs = (ExprState **) palloc(nkeys * sizeof(*mstate->param_exprs)); mstate->collations = node->collations; /* Just point directly to the plan * data */ - mstate->hashfunctions = (FmgrInfo *) palloc(nkeys * sizeof(FmgrInfo)); + mstate->hashfunctions = (FmgrInfo *) palloc(nkeys * sizeof(*mstate->hashfunctions)); - eqfuncoids = palloc(nkeys * sizeof(Oid)); + eqfuncoids = palloc(nkeys * sizeof(*eqfuncoids)); for (i = 0; i < nkeys; i++) { diff --git a/src/backend/executor/nodeModifyTable.c b/src/backend/executor/nodeModifyTable.c index 874b71e6608..702efd6c84d 100644 --- a/src/backend/executor/nodeModifyTable.c +++ b/src/backend/executor/nodeModifyTable.c @@ -462,7 +462,7 @@ ExecInitGenerated(ResultRelInfo *resultRelInfo, */ oldContext = MemoryContextSwitchTo(estate->es_query_cxt); - ri_GeneratedExprs = (ExprState **) palloc0(natts * sizeof(ExprState *)); + ri_GeneratedExprs = (ExprState **) palloc0(natts * sizeof(*ri_GeneratedExprs)); ri_NumGeneratedNeeded = 0; for (int i = 0; i < natts; i++) diff --git a/src/backend/executor/nodeSubplan.c b/src/backend/executor/nodeSubplan.c index c8b7bd9eb66..66b8a91e161 100644 --- a/src/backend/executor/nodeSubplan.c +++ b/src/backend/executor/nodeSubplan.c @@ -976,14 +976,14 @@ ExecInitSubPlan(SubPlan *subplan, PlanState *parent) lefttlist = righttlist = NIL; sstate->numCols = ncols; - sstate->keyColIdx = (AttrNumber *) palloc(ncols * sizeof(AttrNumber)); - sstate->tab_eq_funcoids = (Oid *) palloc(ncols * sizeof(Oid)); - sstate->tab_collations = (Oid *) palloc(ncols * sizeof(Oid)); - sstate->tab_hash_funcs = (FmgrInfo *) palloc(ncols * sizeof(FmgrInfo)); - lhs_hash_funcs = (FmgrInfo *) palloc(ncols * sizeof(FmgrInfo)); - sstate->cur_eq_funcs = (FmgrInfo *) palloc(ncols * sizeof(FmgrInfo)); + sstate->keyColIdx = (AttrNumber *) palloc(ncols * sizeof(*sstate->keyColIdx)); + sstate->tab_eq_funcoids = (Oid *) palloc(ncols * sizeof(*sstate->tab_eq_funcoids)); + sstate->tab_collations = (Oid *) palloc(ncols * sizeof(*sstate->tab_collations)); + sstate->tab_hash_funcs = (FmgrInfo *) palloc(ncols * sizeof(*sstate->tab_hash_funcs)); + lhs_hash_funcs = (FmgrInfo *) palloc(ncols * sizeof(*lhs_hash_funcs)); + sstate->cur_eq_funcs = (FmgrInfo *) palloc(ncols * sizeof(*sstate->cur_eq_funcs)); /* we'll need the cross-type equality fns below, but not in sstate */ - cross_eq_funcoids = (Oid *) palloc(ncols * sizeof(Oid)); + cross_eq_funcoids = (Oid *) palloc(ncols * sizeof(*cross_eq_funcoids)); i = 1; foreach(l, oplist) diff --git a/src/backend/executor/nodeTidscan.c b/src/backend/executor/nodeTidscan.c index 35fcd5625db..123f60b1f2c 100644 --- a/src/backend/executor/nodeTidscan.c +++ b/src/backend/executor/nodeTidscan.c @@ -158,7 +158,7 @@ TidListEval(TidScanState *tidstate) */ numAllocTids = list_length(tidstate->tss_tidexprs); tidList = (ItemPointerData *) - palloc(numAllocTids * sizeof(ItemPointerData)); + palloc(numAllocTids * sizeof(*tidList)); numTids = 0; foreach(l, tidstate->tss_tidexprs) diff --git a/src/backend/executor/nodeValuesscan.c b/src/backend/executor/nodeValuesscan.c index 8e85a5f2e9a..f6b9cd7dd70 100644 --- a/src/backend/executor/nodeValuesscan.c +++ b/src/backend/executor/nodeValuesscan.c @@ -278,9 +278,9 @@ ExecInitValuesScan(ValuesScan *node, EState *estate, int eflags) * simpler expressions.) */ scanstate->exprlists = (List **) - palloc(scanstate->array_len * sizeof(List *)); + palloc(scanstate->array_len * sizeof(*scanstate->exprlists)); scanstate->exprstatelists = (List **) - palloc0(scanstate->array_len * sizeof(List *)); + palloc0(scanstate->array_len * sizeof(*scanstate->exprstatelists)); i = 0; foreach(vtl, node->values_lists) { diff --git a/src/backend/jit/llvm/llvmjit_expr.c b/src/backend/jit/llvm/llvmjit_expr.c index f9c7f29e728..ebbf5c53db9 100644 --- a/src/backend/jit/llvm/llvmjit_expr.c +++ b/src/backend/jit/llvm/llvmjit_expr.c @@ -699,7 +699,7 @@ llvm_compile_expr(ExprState *state) /* create blocks for checking args, one for each */ b_checkargnulls = (LLVMBasicBlockRef *) - palloc(sizeof(LLVMBasicBlockRef) * op->d.func.nargs); + palloc(sizeof(*b_checkargnulls) * op->d.func.nargs); for (int argno = 0; argno < op->d.func.nargs; argno++) b_checkargnulls[argno] = l_bb_before_v(b_nonull, "b.%d.isnull.%d", opno, diff --git a/src/backend/lib/bipartite_match.c b/src/backend/lib/bipartite_match.c index ed54f190494..8a3a6b8b74a 100644 --- a/src/backend/lib/bipartite_match.c +++ b/src/backend/lib/bipartite_match.c @@ -48,10 +48,10 @@ BipartiteMatch(int u_size, int v_size, short **adjacency) state->v_size = v_size; state->adjacency = adjacency; state->matching = 0; - state->pair_uv = (short *) palloc0((u_size + 1) * sizeof(short)); - state->pair_vu = (short *) palloc0((v_size + 1) * sizeof(short)); - state->distance = (short *) palloc((u_size + 1) * sizeof(short)); - state->queue = (short *) palloc((u_size + 2) * sizeof(short)); + state->pair_uv = (short *) palloc0((u_size + 1) * sizeof(*state->pair_uv)); + state->pair_vu = (short *) palloc0((v_size + 1) * sizeof(*state->pair_vu)); + state->distance = (short *) palloc((u_size + 1) * sizeof(*state->distance)); + state->queue = (short *) palloc((u_size + 2) * sizeof(*state->queue)); while (hk_breadth_search(state)) { diff --git a/src/backend/lib/knapsack.c b/src/backend/lib/knapsack.c index 5b3697a090f..65c876e5136 100644 --- a/src/backend/lib/knapsack.c +++ b/src/backend/lib/knapsack.c @@ -65,8 +65,8 @@ DiscreteKnapsack(int max_weight, int num_items, Assert(max_weight >= 0); Assert(num_items > 0 && item_weights); - values = palloc((1 + max_weight) * sizeof(double)); - sets = palloc((1 + max_weight) * sizeof(Bitmapset *)); + values = palloc((1 + max_weight) * sizeof(*values)); + sets = palloc((1 + max_weight) * sizeof(*sets)); for (i = 0; i <= max_weight; ++i) { diff --git a/src/backend/libpq/auth.c b/src/backend/libpq/auth.c index 8045dbffe04..8a306c1b8f2 100644 --- a/src/backend/libpq/auth.c +++ b/src/backend/libpq/auth.c @@ -1347,7 +1347,7 @@ pg_SSPI_recvauth(Port *port) */ if (sspictx == NULL) { - sspictx = malloc(sizeof(CtxtHandle)); + sspictx = malloc(sizeof(*sspictx)); if (sspictx == NULL) ereport(ERROR, (errmsg("out of memory"))); diff --git a/src/backend/libpq/hba.c b/src/backend/libpq/hba.c index 4c259f58d77..14561450582 100644 --- a/src/backend/libpq/hba.c +++ b/src/backend/libpq/hba.c @@ -310,7 +310,7 @@ regcomp_auth_token(AuthToken *token, char *filename, int line_num, return 0; /* nothing to compile */ token->regex = palloc0_object(regex_t); - wstr = palloc((strlen(token->string + 1) + 1) * sizeof(pg_wchar)); + wstr = palloc((strlen(token->string + 1) + 1) * sizeof(*wstr)); wlen = pg_mb2wchar_with_len(token->string + 1, wstr, strlen(token->string + 1)); @@ -351,7 +351,7 @@ regexec_auth_token(const char *match, AuthToken *token, size_t nmatch, Assert(token->string[0] == '/' && token->regex); - wmatchstr = palloc((strlen(match) + 1) * sizeof(pg_wchar)); + wmatchstr = palloc((strlen(match) + 1) * sizeof(*wmatchstr)); wmatchlen = pg_mb2wchar_with_len(match, wmatchstr, strlen(match)); r = pg_regexec(token->regex, wmatchstr, wmatchlen, 0, NULL, nmatch, pmatch, 0); diff --git a/src/backend/nodes/queryjumblefuncs.c b/src/backend/nodes/queryjumblefuncs.c index ffc230af427..8a594abbb35 100644 --- a/src/backend/nodes/queryjumblefuncs.c +++ b/src/backend/nodes/queryjumblefuncs.c @@ -188,7 +188,7 @@ InitJumble(void) jstate->jumble_len = 0; jstate->clocations_buf_size = 32; jstate->clocations = (LocationLen *) palloc(jstate->clocations_buf_size * - sizeof(LocationLen)); + sizeof(*jstate->clocations)); jstate->clocations_count = 0; jstate->highest_extern_param_id = 0; jstate->pending_nulls = 0; diff --git a/src/backend/nodes/readfuncs.c b/src/backend/nodes/readfuncs.c index 9a8ca27ec10..d961d527be3 100644 --- a/src/backend/nodes/readfuncs.c +++ b/src/backend/nodes/readfuncs.c @@ -670,7 +670,7 @@ fnname(int numCols) \ return NULL; /* it was "<>", so return NULL pointer */ \ if (length != 1 || token[0] != '(') \ elog(ERROR, "unrecognized token: \"%.*s\"", length, token); \ - vals = (datatype *) palloc(numCols * sizeof(datatype)); \ + vals = (datatype *) palloc(numCols * sizeof(*vals)); \ for (int i = 0; i < numCols; i++) \ { \ token = pg_strtok(&length); \ diff --git a/src/backend/optimizer/path/allpaths.c b/src/backend/optimizer/path/allpaths.c index 4c43fd0b19b..4e0a9c44c45 100644 --- a/src/backend/optimizer/path/allpaths.c +++ b/src/backend/optimizer/path/allpaths.c @@ -1063,7 +1063,7 @@ set_append_rel_size(PlannerInfo *root, RelOptInfo *rel, parent_rows = 0; parent_size = 0; nattrs = rel->max_attr - rel->min_attr + 1; - parent_attrsizes = (double *) palloc0(nattrs * sizeof(double)); + parent_attrsizes = (double *) palloc0(nattrs * sizeof(*parent_attrsizes)); foreach(l, root->append_rel_list) { @@ -2651,7 +2651,7 @@ set_subquery_pathlist(PlannerInfo *root, RelOptInfo *rel, */ memset(&safetyInfo, 0, sizeof(safetyInfo)); safetyInfo.unsafeFlags = (unsigned char *) - palloc0((list_length(subquery->targetList) + 1) * sizeof(unsigned char)); + palloc0((list_length(subquery->targetList) + 1) * sizeof(*safetyInfo.unsafeFlags)); /* * If the subquery has the "security_barrier" flag, it means the subquery diff --git a/src/backend/optimizer/path/equivclass.c b/src/backend/optimizer/path/equivclass.c index 441f12f6c50..b846e982494 100644 --- a/src/backend/optimizer/path/equivclass.c +++ b/src/backend/optimizer/path/equivclass.c @@ -1383,7 +1383,7 @@ generate_base_implied_equalities_no_const(PlannerInfo *root, * to the way we build merged ECs. (Use a list-of-lists for each rel.) */ prev_ems = (EquivalenceMember **) - palloc0(root->simple_rel_array_size * sizeof(EquivalenceMember *)); + palloc0(root->simple_rel_array_size * sizeof(*prev_ems)); /* We don't expect any children yet */ Assert(ec->ec_childmembers == NULL); diff --git a/src/backend/optimizer/path/pathkeys.c b/src/backend/optimizer/path/pathkeys.c index 139fa1f875a..78928997e61 100644 --- a/src/backend/optimizer/path/pathkeys.c +++ b/src/backend/optimizer/path/pathkeys.c @@ -1676,8 +1676,8 @@ select_outer_pathkeys_for_merge(PlannerInfo *root, * Make arrays of the ECs used by the mergeclauses (dropping any * duplicates) and their "popularity" scores. */ - ecs = (EquivalenceClass **) palloc(nClauses * sizeof(EquivalenceClass *)); - scores = (int *) palloc(nClauses * sizeof(int)); + ecs = (EquivalenceClass **) palloc(nClauses * sizeof(*ecs)); + scores = (int *) palloc(nClauses * sizeof(*scores)); necs = 0; foreach(lc, mergeclauses) diff --git a/src/backend/optimizer/plan/createplan.c b/src/backend/optimizer/plan/createplan.c index bc417f93840..dfa2963a657 100644 --- a/src/backend/optimizer/plan/createplan.c +++ b/src/backend/optimizer/plan/createplan.c @@ -1728,8 +1728,8 @@ create_memoize_plan(PlannerInfo *root, MemoizePath *best_path, int flags) nkeys = list_length(param_exprs); Assert(nkeys > 0); - operators = palloc(nkeys * sizeof(Oid)); - collations = palloc(nkeys * sizeof(Oid)); + operators = palloc(nkeys * sizeof(*operators)); + collations = palloc(nkeys * sizeof(*collations)); i = 0; forboth(lc, param_exprs, lc2, best_path->hash_operators) @@ -2270,7 +2270,7 @@ create_groupingsets_plan(PlannerInfo *root, GroupingSetsPath *best_path) maxref = gc->tleSortGroupRef; } - grouping_map = (AttrNumber *) palloc0((maxref + 1) * sizeof(AttrNumber)); + grouping_map = (AttrNumber *) palloc0((maxref + 1) * sizeof(*grouping_map)); /* Now look up the column numbers in the child's tlist */ foreach(lc, root->processed_groupClause) @@ -2708,9 +2708,9 @@ create_limit_plan(PlannerInfo *root, LimitPath *best_path, int flags) ListCell *l; numUniqkeys = list_length(parse->sortClause); - uniqColIdx = (AttrNumber *) palloc(numUniqkeys * sizeof(AttrNumber)); - uniqOperators = (Oid *) palloc(numUniqkeys * sizeof(Oid)); - uniqCollations = (Oid *) palloc(numUniqkeys * sizeof(Oid)); + uniqColIdx = (AttrNumber *) palloc(numUniqkeys * sizeof(*uniqColIdx)); + uniqOperators = (Oid *) palloc(numUniqkeys * sizeof(*uniqOperators)); + uniqCollations = (Oid *) palloc(numUniqkeys * sizeof(*uniqCollations)); numUniqkeys = 0; foreach(l, parse->sortClause) @@ -4524,10 +4524,10 @@ create_mergejoin_plan(PlannerInfo *root, */ nClauses = list_length(mergeclauses); Assert(nClauses == list_length(best_path->path_mergeclauses)); - mergefamilies = (Oid *) palloc(nClauses * sizeof(Oid)); - mergecollations = (Oid *) palloc(nClauses * sizeof(Oid)); - mergereversals = (bool *) palloc(nClauses * sizeof(bool)); - mergenullsfirst = (bool *) palloc(nClauses * sizeof(bool)); + mergefamilies = (Oid *) palloc(nClauses * sizeof(*mergefamilies)); + mergecollations = (Oid *) palloc(nClauses * sizeof(*mergecollations)); + mergereversals = (bool *) palloc(nClauses * sizeof(*mergereversals)); + mergenullsfirst = (bool *) palloc(nClauses * sizeof(*mergenullsfirst)); opathkey = NULL; opeclass = NULL; @@ -5277,7 +5277,7 @@ order_qual_clauses(PlannerInfo *root, List *clauses) * Collect the items and costs into an array. This is to avoid repeated * cost_qual_eval work if the inputs aren't RestrictInfos. */ - items = (QualItem *) palloc(nitems * sizeof(QualItem)); + items = (QualItem *) palloc(nitems * sizeof(*items)); i = 0; foreach(lc, clauses) { @@ -6157,10 +6157,10 @@ prepare_sort_from_pathkeys(Plan *lefttree, List *pathkeys, * We will need at most list_length(pathkeys) sort columns; possibly less */ numsortkeys = list_length(pathkeys); - sortColIdx = (AttrNumber *) palloc(numsortkeys * sizeof(AttrNumber)); - sortOperators = (Oid *) palloc(numsortkeys * sizeof(Oid)); - collations = (Oid *) palloc(numsortkeys * sizeof(Oid)); - nullsFirst = (bool *) palloc(numsortkeys * sizeof(bool)); + sortColIdx = (AttrNumber *) palloc(numsortkeys * sizeof(*sortColIdx)); + sortOperators = (Oid *) palloc(numsortkeys * sizeof(*sortOperators)); + collations = (Oid *) palloc(numsortkeys * sizeof(*collations)); + nullsFirst = (bool *) palloc(numsortkeys * sizeof(*nullsFirst)); numsortkeys = 0; @@ -6398,10 +6398,10 @@ make_sort_from_sortclauses(List *sortcls, Plan *lefttree) /* Convert list-ish representation to arrays wanted by executor */ numsortkeys = list_length(sortcls); - sortColIdx = (AttrNumber *) palloc(numsortkeys * sizeof(AttrNumber)); - sortOperators = (Oid *) palloc(numsortkeys * sizeof(Oid)); - collations = (Oid *) palloc(numsortkeys * sizeof(Oid)); - nullsFirst = (bool *) palloc(numsortkeys * sizeof(bool)); + sortColIdx = (AttrNumber *) palloc(numsortkeys * sizeof(*sortColIdx)); + sortOperators = (Oid *) palloc(numsortkeys * sizeof(*sortOperators)); + collations = (Oid *) palloc(numsortkeys * sizeof(*collations)); + nullsFirst = (bool *) palloc(numsortkeys * sizeof(*nullsFirst)); numsortkeys = 0; foreach(l, sortcls) @@ -6449,10 +6449,10 @@ make_sort_from_groupcols(List *groupcls, /* Convert list-ish representation to arrays wanted by executor */ numsortkeys = list_length(groupcls); - sortColIdx = (AttrNumber *) palloc(numsortkeys * sizeof(AttrNumber)); - sortOperators = (Oid *) palloc(numsortkeys * sizeof(Oid)); - collations = (Oid *) palloc(numsortkeys * sizeof(Oid)); - nullsFirst = (bool *) palloc(numsortkeys * sizeof(bool)); + sortColIdx = (AttrNumber *) palloc(numsortkeys * sizeof(*sortColIdx)); + sortOperators = (Oid *) palloc(numsortkeys * sizeof(*sortOperators)); + collations = (Oid *) palloc(numsortkeys * sizeof(*collations)); + nullsFirst = (bool *) palloc(numsortkeys * sizeof(*nullsFirst)); numsortkeys = 0; foreach(l, groupcls) diff --git a/src/backend/optimizer/plan/planner.c b/src/backend/optimizer/plan/planner.c index 8b22c30559b..826be6fcd72 100644 --- a/src/backend/optimizer/plan/planner.c +++ b/src/backend/optimizer/plan/planner.c @@ -2248,7 +2248,7 @@ preprocess_grouping_sets(PlannerInfo *root) } /* Allocate workspace array for remapping */ - gd->tleref_to_colnum_map = (int *) palloc((maxref + 1) * sizeof(int)); + gd->tleref_to_colnum_map = (int *) palloc((maxref + 1) * sizeof(*gd->tleref_to_colnum_map)); /* * If we have any unsortable sets, we must extract them before trying to @@ -3002,10 +3002,10 @@ extract_rollup_sets(List *groupingSets) * to leave 0 free for the NIL node in the graph algorithm. *---------- */ - orig_sets = palloc0((num_sets_raw + 1) * sizeof(List *)); - set_masks = palloc0((num_sets_raw + 1) * sizeof(Bitmapset *)); - adjacency = palloc0((num_sets_raw + 1) * sizeof(short *)); - adjacency_buf = palloc((num_sets_raw + 1) * sizeof(short)); + orig_sets = palloc0((num_sets_raw + 1) * sizeof(*orig_sets)); + set_masks = palloc0((num_sets_raw + 1) * sizeof(*set_masks)); + adjacency = palloc0((num_sets_raw + 1) * sizeof(*adjacency)); + adjacency_buf = palloc((num_sets_raw + 1) * sizeof(*adjacency_buf)); j_size = 0; j = 0; @@ -3067,7 +3067,7 @@ extract_rollup_sets(List *groupingSets) if (n_adj > 0) { adjacency_buf[0] = n_adj; - adjacency[i] = palloc((n_adj + 1) * sizeof(short)); + adjacency[i] = palloc((n_adj + 1) * sizeof(*adjacency[i])); memcpy(adjacency[i], adjacency_buf, (n_adj + 1) * sizeof(short)); } else @@ -3090,7 +3090,7 @@ extract_rollup_sets(List *groupingSets) * pair_vu[v] = u (both will be true, but we check both so that we can do * it in one pass) */ - chains = palloc0((num_sets + 1) * sizeof(int)); + chains = palloc0((num_sets + 1) * sizeof(*chains)); for (i = 1; i <= num_sets; ++i) { @@ -3106,7 +3106,7 @@ extract_rollup_sets(List *groupingSets) } /* build result lists. */ - results = palloc0((num_chains + 1) * sizeof(List *)); + results = palloc0((num_chains + 1) * sizeof(*results)); for (i = 1; i <= num_sets; ++i) { @@ -4397,7 +4397,7 @@ consider_groupingsets_paths(PlannerInfo *root, double scale; int num_rollups = list_length(gd->rollups); int k_capacity; - int *k_weights = palloc(num_rollups * sizeof(int)); + int *k_weights = palloc(num_rollups * sizeof(*k_weights)); Bitmapset *hash_items = NULL; int i; @@ -6448,8 +6448,8 @@ make_sort_input_target(PlannerInfo *root, /* Inspect tlist and collect per-column information */ ncols = list_length(final_target->exprs); - col_is_srf = (bool *) palloc0(ncols * sizeof(bool)); - postpone_col = (bool *) palloc0(ncols * sizeof(bool)); + col_is_srf = (bool *) palloc0(ncols * sizeof(*col_is_srf)); + postpone_col = (bool *) palloc0(ncols * sizeof(*postpone_col)); have_srf = have_volatile = have_expensive = have_srf_sortcols = false; i = 0; diff --git a/src/backend/optimizer/prep/prepjointree.c b/src/backend/optimizer/prep/prepjointree.c index c3b726e93e7..11df46d0b0f 100644 --- a/src/backend/optimizer/prep/prepjointree.c +++ b/src/backend/optimizer/prep/prepjointree.c @@ -552,7 +552,7 @@ expand_virtual_generated_columns(PlannerInfo *root, Query *parse, rvcontext.wrap_option = REPLACE_WRAP_NONE; /* initialize cache array with indexes 0 .. length(tlist) */ rvcontext.rv_cache = palloc0((list_length(tlist) + 1) * - sizeof(Node *)); + sizeof(*rvcontext.rv_cache)); /* * If the query uses grouping sets, we need a PlaceHolderVar for each @@ -1518,7 +1518,7 @@ pull_up_simple_subquery(PlannerInfo *root, Node *jtnode, RangeTblEntry *rte, rvcontext.wrap_option = REPLACE_WRAP_NONE; /* initialize cache array with indexes 0 .. length(tlist) */ rvcontext.rv_cache = palloc0((list_length(subquery->targetList) + 1) * - sizeof(Node *)); + sizeof(*rvcontext.rv_cache)); /* * If the parent query uses grouping sets, we need a PlaceHolderVar for @@ -1841,7 +1841,7 @@ make_setop_translation_list(Query *query, int newvarno, /* (entries for resjunk columns will stay that way) */ appinfo->num_child_cols = list_length(query->targetList); appinfo->parent_colnos = pcolnos = - (AttrNumber *) palloc0(appinfo->num_child_cols * sizeof(AttrNumber)); + (AttrNumber *) palloc0(appinfo->num_child_cols * sizeof(*pcolnos)); foreach(l, query->targetList) { @@ -2059,7 +2059,7 @@ pull_up_simple_values(PlannerInfo *root, Node *jtnode, RangeTblEntry *rte) rvcontext.wrap_option = REPLACE_WRAP_NONE; /* initialize cache array with indexes 0 .. length(tlist) */ rvcontext.rv_cache = palloc0((list_length(tlist) + 1) * - sizeof(Node *)); + sizeof(*rvcontext.rv_cache)); /* * Replace all of the top query's references to the RTE's outputs with @@ -2227,7 +2227,7 @@ pull_up_constant_function(PlannerInfo *root, Node *jtnode, rvcontext.wrap_option = REPLACE_WRAP_NONE; /* initialize cache array with indexes 0 .. length(tlist) */ rvcontext.rv_cache = palloc0((list_length(rvcontext.targetlist) + 1) * - sizeof(Node *)); + sizeof(*rvcontext.rv_cache)); /* * If the parent query uses grouping sets, we need a PlaceHolderVar for diff --git a/src/backend/optimizer/util/appendinfo.c b/src/backend/optimizer/util/appendinfo.c index 271bb4e6828..538ad162544 100644 --- a/src/backend/optimizer/util/appendinfo.c +++ b/src/backend/optimizer/util/appendinfo.c @@ -94,7 +94,7 @@ make_inh_translation_list(Relation oldrelation, Relation newrelation, /* Initialize reverse-translation array with all entries zero */ appinfo->num_child_cols = newnatts; appinfo->parent_colnos = pcolnos = - (AttrNumber *) palloc0(newnatts * sizeof(AttrNumber)); + (AttrNumber *) palloc0(newnatts * sizeof(*pcolnos)); for (old_attno = 0; old_attno < oldnatts; old_attno++) { diff --git a/src/backend/optimizer/util/clauses.c b/src/backend/optimizer/util/clauses.c index ddafc21c819..28f7190b45e 100644 --- a/src/backend/optimizer/util/clauses.c +++ b/src/backend/optimizer/util/clauses.c @@ -243,7 +243,7 @@ find_window_functions(Node *clause, Index maxWinRef) lists->numWindowFuncs = 0; lists->maxWinRef = maxWinRef; - lists->windowFuncs = (List **) palloc0((maxWinRef + 1) * sizeof(List *)); + lists->windowFuncs = (List **) palloc0((maxWinRef + 1) * sizeof(*lists->windowFuncs)); (void) find_window_functions_walker(clause, lists); return lists; } @@ -4981,7 +4981,7 @@ inline_function(Oid funcid, Oid result_type, Oid result_collid, * substitution of the inputs. So start building expression with inputs * substituted. */ - usecounts = (int *) palloc0(funcform->pronargs * sizeof(int)); + usecounts = (int *) palloc0(funcform->pronargs * sizeof(*usecounts)); newexpr = substitute_actual_parameters(newexpr, funcform->pronargs, args, usecounts); diff --git a/src/backend/parser/analyze.c b/src/backend/parser/analyze.c index 92be345d9a8..e7277cd3c13 100644 --- a/src/backend/parser/analyze.c +++ b/src/backend/parser/analyze.c @@ -1615,7 +1615,7 @@ transformValuesClause(ParseState *pstate, SelectStmt *stmt) /* Remember post-transformation length of first sublist */ sublist_length = list_length(sublist); /* and allocate array for per-column lists */ - colexprs = (List **) palloc0(sublist_length * sizeof(List *)); + colexprs = (List **) palloc0(sublist_length * sizeof(*colexprs)); } else if (sublist_length != list_length(sublist)) { @@ -1888,7 +1888,7 @@ transformSetOperationStmt(ParseState *pstate, SelectStmt *stmt) targetvars = NIL; targetnames = NIL; sortnscolumns = (ParseNamespaceColumn *) - palloc0(list_length(sostmt->colTypes) * sizeof(ParseNamespaceColumn)); + palloc0(list_length(sostmt->colTypes) * sizeof(*sortnscolumns)); sortcolindex = 0; forfour(lct, sostmt->colTypes, diff --git a/src/backend/parser/parse_clause.c b/src/backend/parser/parse_clause.c index 944482207f3..7bffdd544df 100644 --- a/src/backend/parser/parse_clause.c +++ b/src/backend/parser/parse_clause.c @@ -1290,7 +1290,7 @@ transformFromClauseItem(ParseState *pstate, Node *n, /* this may be larger than needed, but it's not worth being exact */ res_nscolumns = (ParseNamespaceColumn *) palloc0((list_length(l_colnames) + list_length(r_colnames)) * - sizeof(ParseNamespaceColumn)); + sizeof(*res_nscolumns)); res_colindex = 0; if (j->usingClause) diff --git a/src/backend/parser/parse_cte.c b/src/backend/parser/parse_cte.c index 366fd901d9d..38a4220c011 100644 --- a/src/backend/parser/parse_cte.c +++ b/src/backend/parser/parse_cte.c @@ -166,7 +166,7 @@ transformWithClause(ParseState *pstate, WithClause *withClause) cstate.pstate = pstate; cstate.numitems = list_length(withClause->ctes); - cstate.items = (CteItem *) palloc0(cstate.numitems * sizeof(CteItem)); + cstate.items = (CteItem *) palloc0(cstate.numitems * sizeof(*cstate.items)); i = 0; foreach(lc, withClause->ctes) { diff --git a/src/backend/parser/parse_relation.c b/src/backend/parser/parse_relation.c index dd64f45478a..0c6a3d589ee 100644 --- a/src/backend/parser/parse_relation.c +++ b/src/backend/parser/parse_relation.c @@ -1316,7 +1316,7 @@ buildNSItemFromTupleDesc(RangeTblEntry *rte, Index rtindex, /* extract per-column data from the tupdesc */ nscolumns = (ParseNamespaceColumn *) - palloc0(maxattrs * sizeof(ParseNamespaceColumn)); + palloc0(maxattrs * sizeof(*nscolumns)); for (varattno = 0; varattno < maxattrs; varattno++) { @@ -1382,7 +1382,7 @@ buildNSItemFromLists(RangeTblEntry *rte, Index rtindex, /* extract per-column data from the lists */ nscolumns = (ParseNamespaceColumn *) - palloc0(maxattrs * sizeof(ParseNamespaceColumn)); + palloc0(maxattrs * sizeof(*nscolumns)); varattno = 0; forthree(lct, coltypes, diff --git a/src/backend/partitioning/partbounds.c b/src/backend/partitioning/partbounds.c index 40ac700d529..838624bf668 100644 --- a/src/backend/partitioning/partbounds.c +++ b/src/backend/partitioning/partbounds.c @@ -386,7 +386,7 @@ create_hash_bounds(PartitionBoundSpec **boundspecs, int nparts, boundinfo->kind = NULL; boundinfo->interleaved_parts = NULL; boundinfo->nindexes = greatest_modulus; - boundinfo->indexes = (int *) palloc(greatest_modulus * sizeof(int)); + boundinfo->indexes = (int *) palloc(greatest_modulus * sizeof(*boundinfo->indexes)); for (i = 0; i < greatest_modulus; i++) boundinfo->indexes[i] = -1; @@ -395,7 +395,7 @@ create_hash_bounds(PartitionBoundSpec **boundspecs, int nparts, * arrays, here we just allocate a single array and below we'll just * assign a portion of this array per partition. */ - boundDatums = (Datum *) palloc(nparts * 2 * sizeof(Datum)); + boundDatums = (Datum *) palloc(nparts * 2 * sizeof(*boundDatums)); /* * For hash partitioning, there are as many datums (modulus and remainder @@ -478,7 +478,7 @@ create_list_bounds(PartitionBoundSpec **boundspecs, int nparts, ndatums = get_non_null_list_datum_count(boundspecs, nparts); all_values = (PartitionListValue *) - palloc(ndatums * sizeof(PartitionListValue)); + palloc(ndatums * sizeof(*all_values)); /* Create a unified list of non-null values across all partitions. */ for (j = 0, i = 0; i < nparts; i++) @@ -534,14 +534,14 @@ create_list_bounds(PartitionBoundSpec **boundspecs, int nparts, boundinfo->kind = NULL; boundinfo->interleaved_parts = NULL; boundinfo->nindexes = ndatums; - boundinfo->indexes = (int *) palloc(ndatums * sizeof(int)); + boundinfo->indexes = (int *) palloc(ndatums * sizeof(*boundinfo->indexes)); /* * In the loop below, to save from allocating a series of small datum * arrays, here we just allocate a single array and below we'll just * assign a portion of this array per datum. */ - boundDatums = (Datum *) palloc(ndatums * sizeof(Datum)); + boundDatums = (Datum *) palloc(ndatums * sizeof(*boundDatums)); /* * Copy values. Canonical indexes are values ranging from 0 to (nparts - @@ -735,7 +735,7 @@ create_range_bounds(PartitionBoundSpec **boundspecs, int nparts, /* Save distinct bounds from all_bounds into rbounds. */ rbounds = (PartitionRangeBound **) - palloc(ndatums * sizeof(PartitionRangeBound *)); + palloc(ndatums * sizeof(*rbounds)); k = 0; prev = NULL; for (i = 0; i < ndatums; i++) @@ -816,7 +816,7 @@ create_range_bounds(PartitionBoundSpec **boundspecs, int nparts, * arrays in each loop. */ partnatts = key->partnatts; - boundDatums = (Datum *) palloc(ndatums * partnatts * sizeof(Datum)); + boundDatums = (Datum *) palloc(ndatums * partnatts * sizeof(*boundDatums)); boundKinds = palloc_array(PartitionRangeDatumKind, ndatums * partnatts); for (i = 0; i < ndatums; i++) @@ -1020,7 +1020,7 @@ partition_bounds_copy(PartitionBoundInfo src, Assert(key->strategy == PARTITION_STRATEGY_RANGE); dest->kind = (PartitionRangeDatumKind **) palloc(ndatums * - sizeof(PartitionRangeDatumKind *)); + sizeof(*dest->kind)); /* * In the loop below, to save from allocating a series of small arrays @@ -1028,7 +1028,7 @@ partition_bounds_copy(PartitionBoundInfo src, * here and use a smaller portion of it for each datum. */ boundKinds = (PartitionRangeDatumKind *) palloc(ndatums * partnatts * - sizeof(PartitionRangeDatumKind)); + sizeof(*boundKinds)); for (i = 0; i < ndatums; i++) { @@ -1051,7 +1051,7 @@ partition_bounds_copy(PartitionBoundInfo src, { bool hash_part = (key->strategy == PARTITION_STRATEGY_HASH); int natts = hash_part ? 2 : partnatts; - Datum *boundDatums = palloc(ndatums * natts * sizeof(Datum)); + Datum *boundDatums = palloc(ndatums * natts * sizeof(*boundDatums)); for (i = 0; i < ndatums; i++) { diff --git a/src/backend/partitioning/partdesc.c b/src/backend/partitioning/partdesc.c index 5624f503fec..d128842bab1 100644 --- a/src/backend/partitioning/partdesc.c +++ b/src/backend/partitioning/partdesc.c @@ -171,9 +171,9 @@ retry: /* Allocate working arrays for OIDs, leaf flags, and boundspecs. */ if (nparts > 0) { - oids = (Oid *) palloc(nparts * sizeof(Oid)); - is_leaf = (bool *) palloc(nparts * sizeof(bool)); - boundspecs = palloc(nparts * sizeof(PartitionBoundSpec *)); + oids = (Oid *) palloc(nparts * sizeof(*oids)); + is_leaf = (bool *) palloc(nparts * sizeof(*is_leaf)); + boundspecs = palloc(nparts * sizeof(*boundspecs)); } /* Collect bound spec nodes for each partition. */ @@ -336,8 +336,8 @@ retry: partdesc->last_found_part_index = -1; partdesc->last_found_count = 0; - partdesc->oids = (Oid *) palloc(nparts * sizeof(Oid)); - partdesc->is_leaf = (bool *) palloc(nparts * sizeof(bool)); + partdesc->oids = (Oid *) palloc(nparts * sizeof(*partdesc->oids)); + partdesc->is_leaf = (bool *) palloc(nparts * sizeof(*partdesc->is_leaf)); /* * Assign OIDs from the original array into mapped indexes of the diff --git a/src/backend/partitioning/partprune.c b/src/backend/partitioning/partprune.c index 0227a2c9281..f1aed928388 100644 --- a/src/backend/partitioning/partprune.c +++ b/src/backend/partitioning/partprune.c @@ -653,12 +653,12 @@ make_partitionedrel_pruneinfo(PlannerInfo *root, RelOptInfo *parentrel, * Also construct a Bitmapset of all partitions that are present (that * is, not pruned already). */ - subplan_map = (int *) palloc(nparts * sizeof(int)); + subplan_map = (int *) palloc(nparts * sizeof(*subplan_map)); memset(subplan_map, -1, nparts * sizeof(int)); - subpart_map = (int *) palloc(nparts * sizeof(int)); + subpart_map = (int *) palloc(nparts * sizeof(*subpart_map)); memset(subpart_map, -1, nparts * sizeof(int)); - relid_map = (Oid *) palloc0(nparts * sizeof(Oid)); - leafpart_rti_map = (int *) palloc0(nparts * sizeof(int)); + relid_map = (Oid *) palloc0(nparts * sizeof(*relid_map)); + leafpart_rti_map = (int *) palloc0(nparts * sizeof(*leafpart_rti_map)); present_parts = NULL; i = -1; @@ -867,7 +867,7 @@ get_matching_partitions(PartitionPruneContext *context, List *pruning_steps) * of the last pruning step. */ results = (PruneStepResult **) - palloc0(num_steps * sizeof(PruneStepResult *)); + palloc0(num_steps * sizeof(*results)); foreach(lc, pruning_steps) { PartitionPruneStep *step = lfirst(lc); diff --git a/src/backend/port/posix_sema.c b/src/backend/port/posix_sema.c index d7fb0c0c4da..ca965d51928 100644 --- a/src/backend/port/posix_sema.c +++ b/src/backend/port/posix_sema.c @@ -210,7 +210,7 @@ PGReserveSemaphores(int maxSemas) DataDir))); #ifdef USE_NAMED_POSIX_SEMAPHORES - mySemPointers = (sem_t **) malloc(maxSemas * sizeof(sem_t *)); + mySemPointers = (sem_t **) malloc(maxSemas * sizeof(*mySemPointers)); if (mySemPointers == NULL) elog(PANIC, "out of memory"); #else diff --git a/src/backend/port/sysv_sema.c b/src/backend/port/sysv_sema.c index 9faaeeefc79..b0712f4b720 100644 --- a/src/backend/port/sysv_sema.c +++ b/src/backend/port/sysv_sema.c @@ -350,7 +350,7 @@ PGReserveSemaphores(int maxSemas) maxSemaSets = (maxSemas + SEMAS_PER_SET - 1) / SEMAS_PER_SET; mySemaSets = (IpcSemaphoreId *) - malloc(maxSemaSets * sizeof(IpcSemaphoreId)); + malloc(maxSemaSets * sizeof(*mySemaSets)); if (mySemaSets == NULL) elog(PANIC, "out of memory"); numSemaSets = 0; diff --git a/src/backend/port/win32_sema.c b/src/backend/port/win32_sema.c index 5854ad1f54d..ba2797b4c5c 100644 --- a/src/backend/port/win32_sema.c +++ b/src/backend/port/win32_sema.c @@ -46,7 +46,7 @@ PGSemaphoreShmemSize(int maxSemas) void PGReserveSemaphores(int maxSemas) { - mySemSet = (HANDLE *) malloc(maxSemas * sizeof(HANDLE)); + mySemSet = (HANDLE *) malloc(maxSemas * sizeof(*mySemSet)); if (mySemSet == NULL) elog(PANIC, "out of memory"); numSems = 0; diff --git a/src/backend/postmaster/autovacuum.c b/src/backend/postmaster/autovacuum.c index 1bd3924e35e..3458acbe37c 100644 --- a/src/backend/postmaster/autovacuum.c +++ b/src/backend/postmaster/autovacuum.c @@ -1029,7 +1029,7 @@ rebuild_database_list(Oid newdb) int i; /* put all the hash elements into an array */ - dbary = palloc(nelems * sizeof(avl_dbase)); + dbary = palloc(nelems * sizeof(*dbary)); /* keep Valgrind quiet */ #ifdef USE_VALGRIND avl_dbase_array = dbary; diff --git a/src/backend/postmaster/checkpointer.c b/src/backend/postmaster/checkpointer.c index 7f8cf1fa2ec..2a76bdbe324 100644 --- a/src/backend/postmaster/checkpointer.c +++ b/src/backend/postmaster/checkpointer.c @@ -1466,7 +1466,7 @@ AbsorbSyncRequests(void) if (n > 0) { if (!requests) - requests = (CheckpointerRequest *) palloc(n * sizeof(CheckpointerRequest)); + requests = (CheckpointerRequest *) palloc(n * sizeof(*requests)); for (i = 0; i < n; i++) { diff --git a/src/backend/postmaster/pmchild.c b/src/backend/postmaster/pmchild.c index 584bb58c8ab..893b070686a 100644 --- a/src/backend/postmaster/pmchild.c +++ b/src/backend/postmaster/pmchild.c @@ -137,7 +137,7 @@ InitPostmasterChildSlots(void) num_pmchild_slots += pmchild_pools[i].size; /* Allocate enough slots, and make sure Valgrind doesn't complain */ - slots = palloc(num_pmchild_slots * sizeof(PMChild)); + slots = palloc(num_pmchild_slots * sizeof(*slots)); #ifdef USE_VALGRIND pmchild_array = slots; #endif diff --git a/src/backend/postmaster/postmaster.c b/src/backend/postmaster/postmaster.c index 7dd3a201b1c..9693475e873 100644 --- a/src/backend/postmaster/postmaster.c +++ b/src/backend/postmaster/postmaster.c @@ -1111,7 +1111,7 @@ PostmasterMain(int argc, char *argv[]) * First set up an on_proc_exit function that's charged with closing the * sockets again at postmaster shutdown. */ - ListenSockets = palloc(MAXLISTEN * sizeof(pgsocket)); + ListenSockets = palloc(MAXLISTEN * sizeof(*ListenSockets)); on_proc_exit(CloseServerPorts, 0); if (ListenAddresses) diff --git a/src/backend/regex/regc_pg_locale.c b/src/backend/regex/regc_pg_locale.c index bb0e3f1d139..c80eee4e12c 100644 --- a/src/backend/regex/regc_pg_locale.c +++ b/src/backend/regex/regc_pg_locale.c @@ -283,7 +283,7 @@ regc_ctype_get_cache(regc_wc_probefunc probefunc, int cclasscode) /* * Nope, so initialize some workspace ... */ - pcc = (pg_ctype_cache *) malloc(sizeof(pg_ctype_cache)); + pcc = (pg_ctype_cache *) malloc(sizeof(*pcc)); if (pcc == NULL) return NULL; pcc->probefunc = probefunc; diff --git a/src/backend/replication/logical/proto.c b/src/backend/replication/logical/proto.c index 27ad74fd759..702d73bf530 100644 --- a/src/backend/replication/logical/proto.c +++ b/src/backend/replication/logical/proto.c @@ -870,7 +870,7 @@ logicalrep_read_tuple(StringInfo in, LogicalRepTupleData *tuple) natts = pq_getmsgint(in, 2); /* Allocate space for per-column values; zero out unused StringInfoDatas */ - tuple->colvalues = (StringInfoData *) palloc0(natts * sizeof(StringInfoData)); + tuple->colvalues = (StringInfoData *) palloc0(natts * sizeof(*tuple->colvalues)); tuple->colstatus = palloc_array(char, natts); tuple->ncols = natts; diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index f18c6fb52b5..47db7af9b1e 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2490,7 +2490,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, int nrelations = 0; Relation *relations; - relations = palloc0(nrelids * sizeof(Relation)); + relations = palloc0(nrelids * sizeof(*relations)); for (i = 0; i < nrelids; i++) { Oid relid = change->data.truncate.relids[i]; diff --git a/src/backend/replication/logical/snapbuild.c b/src/backend/replication/logical/snapbuild.c index d6ab1e017eb..a49a8add398 100644 --- a/src/backend/replication/logical/snapbuild.c +++ b/src/backend/replication/logical/snapbuild.c @@ -209,7 +209,7 @@ AllocateSnapshotBuilder(ReorderBuffer *reorder, builder->committed.xcnt = 0; builder->committed.xcnt_space = 128; /* arbitrary number */ builder->committed.xip = - palloc0(builder->committed.xcnt_space * sizeof(TransactionId)); + palloc0(builder->committed.xcnt_space * sizeof(*builder->committed.xip)); builder->committed.includes_all_transactions = true; builder->catchange.xcnt = 0; diff --git a/src/backend/replication/logical/tablesync.c b/src/backend/replication/logical/tablesync.c index 6bb0cbeedad..293e59d2c61 100644 --- a/src/backend/replication/logical/tablesync.c +++ b/src/backend/replication/logical/tablesync.c @@ -901,8 +901,8 @@ fetch_remote_table_info(char *nspname, char *relname, LogicalRepRelation *lrel, nspname, relname, res->err))); /* We don't know the number of rows coming, so allocate enough space. */ - lrel->attnames = palloc0(MaxTupleAttributeNumber * sizeof(char *)); - lrel->atttyps = palloc0(MaxTupleAttributeNumber * sizeof(Oid)); + lrel->attnames = palloc0(MaxTupleAttributeNumber * sizeof(*lrel->attnames)); + lrel->atttyps = palloc0(MaxTupleAttributeNumber * sizeof(*lrel->atttyps)); lrel->attkeys = NULL; /* diff --git a/src/backend/replication/logical/worker.c b/src/backend/replication/logical/worker.c index fc64476a9ef..446c8e3055b 100644 --- a/src/backend/replication/logical/worker.c +++ b/src/backend/replication/logical/worker.c @@ -974,8 +974,8 @@ slot_fill_defaults(LogicalRepRelMapEntry *rel, EState *estate, if (num_phys_attrs == rel->remoterel.natts) return; - defmap = (int *) palloc(num_phys_attrs * sizeof(int)); - defexprs = (ExprState **) palloc(num_phys_attrs * sizeof(ExprState *)); + defmap = (int *) palloc(num_phys_attrs * sizeof(*defmap)); + defexprs = (ExprState **) palloc(num_phys_attrs * sizeof(*defexprs)); Assert(rel->attrmap->maplen == num_phys_attrs); for (attnum = 0; attnum < num_phys_attrs; attnum++) @@ -5265,7 +5265,7 @@ subxact_info_read(Oid subid, TransactionId xid) */ oldctx = MemoryContextSwitchTo(LogicalStreamingContext); subxact_data.subxacts = palloc(subxact_data.nsubxacts_max * - sizeof(SubXactInfo)); + sizeof(*subxact_data.subxacts)); MemoryContextSwitchTo(oldctx); if (len > 0) @@ -5331,7 +5331,7 @@ subxact_info_add(TransactionId xid) * subxact_info_read. */ oldctx = MemoryContextSwitchTo(LogicalStreamingContext); - subxacts = palloc(subxact_data.nsubxacts_max * sizeof(SubXactInfo)); + subxacts = palloc(subxact_data.nsubxacts_max * sizeof(*subxacts)); MemoryContextSwitchTo(oldctx); } else if (subxact_data.nsubxacts == subxact_data.nsubxacts_max) diff --git a/src/backend/replication/pgoutput/pgoutput.c b/src/backend/replication/pgoutput/pgoutput.c index 787998abb8a..c5e3c3ba335 100644 --- a/src/backend/replication/pgoutput/pgoutput.c +++ b/src/backend/replication/pgoutput/pgoutput.c @@ -1667,7 +1667,7 @@ pgoutput_truncate(LogicalDecodingContext *ctx, ReorderBufferTXN *txn, old = MemoryContextSwitchTo(data->context); - relids = palloc0(nrelations * sizeof(Oid)); + relids = palloc0(nrelations * sizeof(*relids)); nrelids = 0; for (i = 0; i < nrelations; i++) diff --git a/src/backend/rewrite/rewriteHandler.c b/src/backend/rewrite/rewriteHandler.c index 688dcd09ca6..350c4fdc305 100644 --- a/src/backend/rewrite/rewriteHandler.c +++ b/src/backend/rewrite/rewriteHandler.c @@ -800,7 +800,7 @@ rewriteTargetListIU(List *targetList, * scan, then appended to the reconstructed tlist. */ numattrs = RelationGetNumberOfAttributes(target_relation); - new_tles = (TargetEntry **) palloc0(numattrs * sizeof(TargetEntry *)); + new_tles = (TargetEntry **) palloc0(numattrs * sizeof(*new_tles)); next_junk_attrno = numattrs + 1; foreach(temp, targetList) @@ -1444,7 +1444,7 @@ rewriteValuesRTE(Query *parsetree, RangeTblEntry *rte, int rti, * columns), and we complain if such a thing does occur. */ numattrs = list_length(linitial(rte->values_lists)); - attrnos = (int *) palloc0(numattrs * sizeof(int)); + attrnos = (int *) palloc0(numattrs * sizeof(*attrnos)); foreach(lc, parsetree->targetList) { diff --git a/src/backend/statistics/extended_stats.c b/src/backend/statistics/extended_stats.c index 19778b773d2..2f6c8fbaabc 100644 --- a/src/backend/statistics/extended_stats.c +++ b/src/backend/statistics/extended_stats.c @@ -698,7 +698,7 @@ lookup_var_attr_stats(Bitmapset *attrs, List *exprs, natts = bms_num_members(attrs) + list_length(exprs); - stats = (VacAttrStats **) palloc(natts * sizeof(VacAttrStats *)); + stats = (VacAttrStats **) palloc(natts * sizeof(*stats)); /* lookup VacAttrStats info for the requested columns (same attnum) */ while ((x = bms_next_member(attrs, x)) >= 0) @@ -2132,8 +2132,8 @@ compute_expr_stats(Relation onerel, AnlExprData *exprdata, int nexprs, econtext->ecxt_scantuple = slot; /* Compute and save expression values */ - exprvals = (Datum *) palloc(numrows * sizeof(Datum)); - exprnulls = (bool *) palloc(numrows * sizeof(bool)); + exprvals = (Datum *) palloc(numrows * sizeof(*exprvals)); + exprnulls = (bool *) palloc(numrows * sizeof(*exprnulls)); tcnt = 0; for (i = 0; i < numrows; i++) @@ -2250,7 +2250,7 @@ build_expr_data(List *exprs, int stattarget) AnlExprData *exprdata; ListCell *lc; - exprdata = (AnlExprData *) palloc0(nexprs * sizeof(AnlExprData)); + exprdata = (AnlExprData *) palloc0(nexprs * sizeof(*exprdata)); idx = 0; foreach(lc, exprs) @@ -2343,7 +2343,7 @@ serialize_expr_stats(AnlExprData *exprdata, int nexprs) if (nnum > 0) { int n; - Datum *numdatums = (Datum *) palloc(nnum * sizeof(Datum)); + Datum *numdatums = (Datum *) palloc(nnum * sizeof(*numdatums)); ArrayType *arry; for (n = 0; n < nnum; n++) diff --git a/src/backend/statistics/mcv.c b/src/backend/statistics/mcv.c index ec650ba029f..6560e83fc91 100644 --- a/src/backend/statistics/mcv.c +++ b/src/backend/statistics/mcv.c @@ -428,7 +428,7 @@ build_distinct_groups(int numrows, SortItem *items, MultiSortSupport mss, j; int ngroups = count_distinct_groups(numrows, items, mss); - SortItem *groups = (SortItem *) palloc(ngroups * sizeof(SortItem)); + SortItem *groups = (SortItem *) palloc(ngroups * sizeof(*groups)); j = 0; groups[0] = items[0]; @@ -1097,7 +1097,7 @@ statext_mcv_deserialize(bytea *data) ptr += (sizeof(Oid) * ndims); /* Now it's safe to access the dimension info. */ - info = palloc(ndims * sizeof(DimensionInfo)); + info = palloc(ndims * sizeof(*info)); memcpy(info, ptr, ndims * sizeof(DimensionInfo)); ptr += (ndims * sizeof(DimensionInfo)); diff --git a/src/backend/statistics/mvdistinct.c b/src/backend/statistics/mvdistinct.c index 58046d2bd62..3705ac18b00 100644 --- a/src/backend/statistics/mvdistinct.c +++ b/src/backend/statistics/mvdistinct.c @@ -310,7 +310,7 @@ statext_ndistinct_deserialize(bytea *data) Assert((item->nattributes >= 2) && (item->nattributes <= STATS_MAX_DIMENSIONS)); item->attributes - = (AttrNumber *) palloc(item->nattributes * sizeof(AttrNumber)); + = (AttrNumber *) palloc(item->nattributes * sizeof(*item->attributes)); memcpy(item->attributes, tmp, sizeof(AttrNumber) * item->nattributes); tmp += sizeof(AttrNumber) * item->nattributes; diff --git a/src/backend/storage/file/fd.c b/src/backend/storage/file/fd.c index e9eaaf9c829..60dc73675f0 100644 --- a/src/backend/storage/file/fd.c +++ b/src/backend/storage/file/fd.c @@ -902,7 +902,7 @@ InitFileAccess(void) Assert(SizeVfdCache == 0); /* call me only once */ /* initialize cache header entry */ - VfdCache = (Vfd *) malloc(sizeof(Vfd)); + VfdCache = (Vfd *) malloc(sizeof(*VfdCache)); if (VfdCache == NULL) ereport(FATAL, (errcode(ERRCODE_OUT_OF_MEMORY), @@ -972,7 +972,7 @@ count_usable_fds(int max_to_probe, int *usable_fds, int *already_open) #endif size = 1024; - fd = (int *) palloc(size * sizeof(int)); + fd = (int *) palloc(size * sizeof(*fd)); #ifdef HAVE_GETRLIMIT getrlimit_status = getrlimit(RLIMIT_NOFILE, &rlim); @@ -2581,7 +2581,7 @@ reserveAllocatedDesc(void) if (allocatedDescs == NULL) { newMax = FD_MINFREE / 3; - newDescs = (AllocateDesc *) malloc(newMax * sizeof(AllocateDesc)); + newDescs = (AllocateDesc *) malloc(newMax * sizeof(*newDescs)); /* Out of memory already? Treat as fatal error. */ if (newDescs == NULL) ereport(ERROR, diff --git a/src/backend/storage/ipc/procarray.c b/src/backend/storage/ipc/procarray.c index f3a1603204e..cf1b0ee45c1 100644 --- a/src/backend/storage/ipc/procarray.c +++ b/src/backend/storage/ipc/procarray.c @@ -1458,7 +1458,7 @@ TransactionIdIsInProgress(TransactionId xid) */ int maxxids = RecoveryInProgress() ? TOTAL_MAX_CACHED_SUBXIDS : arrayP->maxProcs; - xids = (TransactionId *) malloc(maxxids * sizeof(TransactionId)); + xids = (TransactionId *) malloc(maxxids * sizeof(*xids)); if (xids == NULL) ereport(ERROR, (errcode(ERRCODE_OUT_OF_MEMORY), @@ -2158,14 +2158,14 @@ GetSnapshotData(Snapshot snapshot) * we are in recovery, see later comments. */ snapshot->xip = (TransactionId *) - malloc(GetMaxSnapshotXidCount() * sizeof(TransactionId)); + malloc(GetMaxSnapshotXidCount() * sizeof(*snapshot->xip)); if (snapshot->xip == NULL) ereport(ERROR, (errcode(ERRCODE_OUT_OF_MEMORY), errmsg("out of memory"))); Assert(snapshot->subxip == NULL); snapshot->subxip = (TransactionId *) - malloc(GetMaxSnapshotSubxidCount() * sizeof(TransactionId)); + malloc(GetMaxSnapshotSubxidCount() * sizeof(*snapshot->subxip)); if (snapshot->subxip == NULL) ereport(ERROR, (errcode(ERRCODE_OUT_OF_MEMORY), @@ -2668,7 +2668,7 @@ GetRunningTransactionData(void) * First call */ CurrentRunningXacts->xids = (TransactionId *) - malloc(TOTAL_MAX_CACHED_SUBXIDS * sizeof(TransactionId)); + malloc(TOTAL_MAX_CACHED_SUBXIDS * sizeof(*CurrentRunningXacts->xids)); if (CurrentRunningXacts->xids == NULL) ereport(ERROR, (errcode(ERRCODE_OUT_OF_MEMORY), @@ -3389,7 +3389,7 @@ GetConflictingVirtualXIDs(TransactionId limitXmin, Oid dbOid) if (vxids == NULL) { vxids = (VirtualTransactionId *) - malloc(sizeof(VirtualTransactionId) * (arrayP->maxProcs + 1)); + malloc(sizeof(*vxids) * (arrayP->maxProcs + 1)); if (vxids == NULL) ereport(ERROR, (errcode(ERRCODE_OUT_OF_MEMORY), diff --git a/src/backend/storage/lmgr/deadlock.c b/src/backend/storage/lmgr/deadlock.c index c4bfaaa67ac..e3a2d59a9d5 100644 --- a/src/backend/storage/lmgr/deadlock.c +++ b/src/backend/storage/lmgr/deadlock.c @@ -152,16 +152,16 @@ InitDeadLockChecking(void) * FindLockCycle needs at most MaxBackends entries in visitedProcs[] and * deadlockDetails[]. */ - visitedProcs = (PGPROC **) palloc(MaxBackends * sizeof(PGPROC *)); - deadlockDetails = (DEADLOCK_INFO *) palloc(MaxBackends * sizeof(DEADLOCK_INFO)); + visitedProcs = (PGPROC **) palloc(MaxBackends * sizeof(*visitedProcs)); + deadlockDetails = (DEADLOCK_INFO *) palloc(MaxBackends * sizeof(*deadlockDetails)); /* * TopoSort needs to consider at most MaxBackends wait-queue entries, and * it needn't run concurrently with FindLockCycle. */ topoProcs = visitedProcs; /* re-use this space */ - beforeConstraints = (int *) palloc(MaxBackends * sizeof(int)); - afterConstraints = (int *) palloc(MaxBackends * sizeof(int)); + beforeConstraints = (int *) palloc(MaxBackends * sizeof(*beforeConstraints)); + afterConstraints = (int *) palloc(MaxBackends * sizeof(*afterConstraints)); /* * We need to consider rearranging at most MaxBackends/2 wait queues @@ -170,8 +170,8 @@ InitDeadLockChecking(void) * MaxBackends total waiters. */ waitOrders = (WAIT_ORDER *) - palloc((MaxBackends / 2) * sizeof(WAIT_ORDER)); - waitOrderProcs = (PGPROC **) palloc(MaxBackends * sizeof(PGPROC *)); + palloc((MaxBackends / 2) * sizeof(*waitOrders)); + waitOrderProcs = (PGPROC **) palloc(MaxBackends * sizeof(*waitOrderProcs)); /* * Allow at most MaxBackends distinct constraints in a configuration. (Is @@ -182,7 +182,7 @@ InitDeadLockChecking(void) * really big might potentially allow a stack-overflow problem. */ maxCurConstraints = MaxBackends; - curConstraints = (EDGE *) palloc(maxCurConstraints * sizeof(EDGE)); + curConstraints = (EDGE *) palloc(maxCurConstraints * sizeof(*curConstraints)); /* * Allow up to 3*MaxBackends constraints to be saved without having to @@ -196,7 +196,7 @@ InitDeadLockChecking(void) "MAX_BACKENDS_BITS too big for * 4"); maxPossibleConstraints = MaxBackends * 4; possibleConstraints = - (EDGE *) palloc(maxPossibleConstraints * sizeof(EDGE)); + (EDGE *) palloc(maxPossibleConstraints * sizeof(*possibleConstraints)); MemoryContextSwitchTo(oldcxt); } diff --git a/src/backend/storage/lmgr/lock.c b/src/backend/storage/lmgr/lock.c index 9015ba3caf7..48a7c93f180 100644 --- a/src/backend/storage/lmgr/lock.c +++ b/src/backend/storage/lmgr/lock.c @@ -4192,7 +4192,7 @@ GetRunningTransactionLocks(int *nlocks) * Allocating enough space for all locks in the lock table is overkill, * but it's more convenient and faster than having to enlarge the array. */ - accessExclusiveLocks = palloc(els * sizeof(xl_standby_lock)); + accessExclusiveLocks = palloc(els * sizeof(*accessExclusiveLocks)); /* Now scan the tables to copy the data */ hash_seq_init(&seqstat, LockMethodProcLockHash); diff --git a/src/backend/tcop/fastpath.c b/src/backend/tcop/fastpath.c index 62f9ffa0dc0..a1bd7ad3953 100644 --- a/src/backend/tcop/fastpath.c +++ b/src/backend/tcop/fastpath.c @@ -339,7 +339,7 @@ parse_fcall_arguments(StringInfo msgBuf, struct fp_info *fip, numAFormats = pq_getmsgint(msgBuf, 2); if (numAFormats > 0) { - aformats = (int16 *) palloc(numAFormats * sizeof(int16)); + aformats = (int16 *) palloc(numAFormats * sizeof(*aformats)); for (i = 0; i < numAFormats; i++) aformats[i] = pq_getmsgint(msgBuf, 2); } diff --git a/src/backend/tsearch/wparser_def.c b/src/backend/tsearch/wparser_def.c index 9fbeab47545..e04b7f11ace 100644 --- a/src/backend/tsearch/wparser_def.c +++ b/src/backend/tsearch/wparser_def.c @@ -2251,7 +2251,7 @@ mark_hl_fragments(HeadlineParsedText *prs, TSQuery query, List *locations, maxitems; CoverPos *covers; - covers = palloc(maxcovers * sizeof(CoverPos)); + covers = palloc(maxcovers * sizeof(*covers)); /* get all covers */ while (hlCover(prs, query, locations, &nextpos, &p, &q)) diff --git a/src/backend/utils/activity/pgstat_xact.c b/src/backend/utils/activity/pgstat_xact.c index bc9864bd8d9..dac619eaa75 100644 --- a/src/backend/utils/activity/pgstat_xact.c +++ b/src/backend/utils/activity/pgstat_xact.c @@ -286,7 +286,7 @@ pgstat_get_transactional_drops(bool isCommit, xl_xact_stats_item **items) Assert(!isCommit || xact_state->prev == NULL); *items = palloc(dclist_count(&xact_state->pending_drops) - * sizeof(xl_xact_stats_item)); + * sizeof(**items)); dclist_foreach(iter, &xact_state->pending_drops) { diff --git a/src/backend/utils/adt/acl.c b/src/backend/utils/adt/acl.c index 05d48412f82..a603f6a42ae 100644 --- a/src/backend/utils/adt/acl.c +++ b/src/backend/utils/adt/acl.c @@ -1553,7 +1553,7 @@ aclmembers(const Acl *acl, Oid **roleids) check_acl(acl); /* Allocate the worst-case space requirement */ - list = palloc(ACL_NUM(acl) * 2 * sizeof(Oid)); + list = palloc(ACL_NUM(acl) * 2 * sizeof(*list)); acldat = ACL_DAT(acl); /* diff --git a/src/backend/utils/adt/array_typanalyze.c b/src/backend/utils/adt/array_typanalyze.c index 61aedd31ff1..ecc4a4d9e1e 100644 --- a/src/backend/utils/adt/array_typanalyze.c +++ b/src/backend/utils/adt/array_typanalyze.c @@ -549,8 +549,8 @@ compute_array_stats(VacAttrStats *stats, AnalyzeAttrFetchFunc fetchfunc, * through all the values. We also want the frequency of null * elements. Store these three values at the end of mcelem_freqs. */ - mcelem_values = (Datum *) palloc(num_mcelem * sizeof(Datum)); - mcelem_freqs = (float4 *) palloc((num_mcelem + 3) * sizeof(float4)); + mcelem_values = (Datum *) palloc(num_mcelem * sizeof(*mcelem_values)); + mcelem_freqs = (float4 *) palloc((num_mcelem + 3) * sizeof(*mcelem_freqs)); /* * See comments above about use of nonnull_cnt as the divisor for diff --git a/src/backend/utils/adt/arrayfuncs.c b/src/backend/utils/adt/arrayfuncs.c index b67ce57656a..85a3912b295 100644 --- a/src/backend/utils/adt/arrayfuncs.c +++ b/src/backend/utils/adt/arrayfuncs.c @@ -1108,8 +1108,8 @@ array_out(PG_FUNCTION_ARGS) * any overhead such as escaping backslashes), and detect whether each * item needs double quotes. */ - values = (char **) palloc(nitems * sizeof(char *)); - needquotes = (bool *) palloc(nitems * sizeof(bool)); + values = (char **) palloc(nitems * sizeof(*values)); + needquotes = (bool *) palloc(nitems * sizeof(*needquotes)); overall_length = 0; array_iter_setup(&iter, v); @@ -1394,8 +1394,8 @@ array_recv(PG_FUNCTION_ARGS) typalign = my_extra->typalign; typioparam = my_extra->typioparam; - dataPtr = (Datum *) palloc(nitems * sizeof(Datum)); - nullsPtr = (bool *) palloc(nitems * sizeof(bool)); + dataPtr = (Datum *) palloc(nitems * sizeof(*dataPtr)); + nullsPtr = (bool *) palloc(nitems * sizeof(*nullsPtr)); ReadArrayBinary(buf, nitems, &my_extra->proc, typioparam, typmod, typlen, typbyval, typalign, @@ -3272,8 +3272,8 @@ array_map(Datum arrayd, typalign = ret_extra->typalign; /* Allocate temporary arrays for new values */ - values = (Datum *) palloc(nitems * sizeof(Datum)); - nulls = (bool *) palloc(nitems * sizeof(bool)); + values = (Datum *) palloc(nitems * sizeof(*values)); + nulls = (bool *) palloc(nitems * sizeof(*nulls)); /* Loop over source data */ array_iter_setup(&iter, v); @@ -4652,9 +4652,9 @@ array_create_iterator(ArrayType *arr, int slice_ndim, ArrayMetaState *mstate) * Create workspace for building sub-arrays. */ iterator->slice_values = (Datum *) - palloc(iterator->slice_len * sizeof(Datum)); + palloc(iterator->slice_len * sizeof(*iterator->slice_values)); iterator->slice_nulls = (bool *) - palloc(iterator->slice_len * sizeof(bool)); + palloc(iterator->slice_len * sizeof(*iterator->slice_nulls)); } /* @@ -6464,8 +6464,8 @@ array_replace_internal(ArrayType *array, collation, NULL, NULL); /* Allocate temporary arrays for new values */ - values = (Datum *) palloc(nitems * sizeof(Datum)); - nulls = (bool *) palloc(nitems * sizeof(bool)); + values = (Datum *) palloc(nitems * sizeof(*values)); + nulls = (bool *) palloc(nitems * sizeof(*nulls)); /* Loop over source data */ arraydataptr = ARR_DATA_PTR(array); diff --git a/src/backend/utils/adt/arrayutils.c b/src/backend/utils/adt/arrayutils.c index 650bb51d4cd..a4f8dd25b2d 100644 --- a/src/backend/utils/adt/arrayutils.c +++ b/src/backend/utils/adt/arrayutils.c @@ -253,7 +253,7 @@ ArrayGetIntegerTypmods(ArrayType *arr, int *n) deconstruct_array_builtin(arr, CSTRINGOID, &elem_values, NULL, n); - result = (int32 *) palloc(*n * sizeof(int32)); + result = (int32 *) palloc(*n * sizeof(*result)); for (i = 0; i < *n; i++) result[i] = pg_strtoint32(DatumGetCString(elem_values[i])); diff --git a/src/backend/utils/adt/enum.c b/src/backend/utils/adt/enum.c index fcc6981632b..f810d96664d 100644 --- a/src/backend/utils/adt/enum.c +++ b/src/backend/utils/adt/enum.c @@ -572,7 +572,7 @@ enum_range_internal(Oid enumtypoid, Oid lower, Oid upper) enum_scan = systable_beginscan_ordered(enum_rel, enum_idx, NULL, 1, &skey); max = 64; - elems = (Datum *) palloc(max * sizeof(Datum)); + elems = (Datum *) palloc(max * sizeof(*elems)); cnt = 0; left_found = !OidIsValid(lower); diff --git a/src/backend/utils/adt/formatting.c b/src/backend/utils/adt/formatting.c index a4570471bba..7bbdd0014ab 100644 --- a/src/backend/utils/adt/formatting.c +++ b/src/backend/utils/adt/formatting.c @@ -3922,7 +3922,7 @@ datetime_to_char_body(TmToChar *tmtc, const text *fmt, bool is_interval, Oid col */ incache = false; - format = (FormatNode *) palloc((fmt_len + 1) * sizeof(FormatNode)); + format = (FormatNode *) palloc((fmt_len + 1) * sizeof(*format)); parse_format(format, fmt_str, DCH_keywords, DCH_suff, DCH_index, DCH_FLAG, NULL); @@ -4337,7 +4337,7 @@ datetime_format_has_tz(const char *fmt_str) */ incache = false; - format = (FormatNode *) palloc((fmt_len + 1) * sizeof(FormatNode)); + format = (FormatNode *) palloc((fmt_len + 1) * sizeof(*format)); parse_format(format, fmt_str, DCH_keywords, DCH_suff, DCH_index, DCH_FLAG, NULL); @@ -4424,7 +4424,7 @@ do_to_timestamp(const text *date_txt, const text *fmt, Oid collid, bool std, * Allocate new memory if format picture is bigger than static * cache and do not use cache (call parser always) */ - format = (FormatNode *) palloc((fmt_len + 1) * sizeof(FormatNode)); + format = (FormatNode *) palloc((fmt_len + 1) * sizeof(*format)); parse_format(format, fmt_str, DCH_keywords, DCH_suff, DCH_index, DCH_FLAG | (std ? STD_FLAG : 0), NULL); @@ -4960,7 +4960,7 @@ NUM_cache(int len, NUMDesc *Num, const text *pars_str, bool *shouldFree) * Allocate new memory if format picture is bigger than static cache * and do not use cache (call parser always) */ - format = (FormatNode *) palloc((len + 1) * sizeof(FormatNode)); + format = (FormatNode *) palloc((len + 1) * sizeof(*format)); *shouldFree = true; diff --git a/src/backend/utils/adt/jsonfuncs.c b/src/backend/utils/adt/jsonfuncs.c index 980e2882957..35261e3d5cd 100644 --- a/src/backend/utils/adt/jsonfuncs.c +++ b/src/backend/utils/adt/jsonfuncs.c @@ -3552,8 +3552,8 @@ populate_record(TupleDesc tupdesc, record->ncolumns = ncolumns; } - values = (Datum *) palloc(ncolumns * sizeof(Datum)); - nulls = (bool *) palloc(ncolumns * sizeof(bool)); + values = (Datum *) palloc(ncolumns * sizeof(*values)); + nulls = (bool *) palloc(ncolumns * sizeof(*nulls)); if (defaultval) { @@ -3908,7 +3908,7 @@ hash_object_field_end(void *state, char *fname, bool isnull) if (_state->save_json_start != NULL) { int len = _state->lex->prev_token_terminator - _state->save_json_start; - char *val = palloc((len + 1) * sizeof(char)); + char *val = palloc((len + 1) * sizeof(*val)); memcpy(val, _state->save_json_start, len); val[len] = '\0'; @@ -4359,7 +4359,7 @@ populate_recordset_object_field_end(void *state, char *fname, bool isnull) if (_state->save_json_start != NULL) { int len = _state->lex->prev_token_terminator - _state->save_json_start; - char *val = palloc((len + 1) * sizeof(char)); + char *val = palloc((len + 1) * sizeof(*val)); memcpy(val, _state->save_json_start, len); val[len] = '\0'; diff --git a/src/backend/utils/adt/levenshtein.c b/src/backend/utils/adt/levenshtein.c index 15a90f6f50c..b57be9894a8 100644 --- a/src/backend/utils/adt/levenshtein.c +++ b/src/backend/utils/adt/levenshtein.c @@ -195,7 +195,7 @@ varstr_levenshtein(const char *source, int slen, int i; const char *cp = source; - s_char_len = (int *) palloc((m + 1) * sizeof(int)); + s_char_len = (int *) palloc((m + 1) * sizeof(*s_char_len)); for (i = 0; i < m; ++i) { s_char_len[i] = pg_mblen(cp); @@ -209,7 +209,7 @@ varstr_levenshtein(const char *source, int slen, ++n; /* Previous and current rows of notional array. */ - prev = (int *) palloc(2 * m * sizeof(int)); + prev = (int *) palloc(2 * m * sizeof(*prev)); curr = prev + m; /* diff --git a/src/backend/utils/adt/lockfuncs.c b/src/backend/utils/adt/lockfuncs.c index bf38d68aa03..71a03797e60 100644 --- a/src/backend/utils/adt/lockfuncs.c +++ b/src/backend/utils/adt/lockfuncs.c @@ -476,7 +476,7 @@ pg_blocking_pids(PG_FUNCTION_ARGS) lockData = GetBlockerStatusData(blocked_pid); /* We can't need more output entries than there are reported PROCLOCKs */ - arrayelems = (Datum *) palloc(lockData->nlocks * sizeof(Datum)); + arrayelems = (Datum *) palloc(lockData->nlocks * sizeof(*arrayelems)); narrayelems = 0; /* For each blocked proc in the lock group ... */ @@ -578,7 +578,7 @@ pg_safe_snapshot_blocking_pids(PG_FUNCTION_ARGS) Datum *blocker_datums; /* A buffer big enough for any possible blocker list without truncation */ - blockers = (int *) palloc(MaxBackends * sizeof(int)); + blockers = (int *) palloc(MaxBackends * sizeof(*blockers)); /* Collect a snapshot of processes waited for by GetSafeSnapshot */ num_blockers = @@ -589,7 +589,7 @@ pg_safe_snapshot_blocking_pids(PG_FUNCTION_ARGS) { int i; - blocker_datums = (Datum *) palloc(num_blockers * sizeof(Datum)); + blocker_datums = (Datum *) palloc(num_blockers * sizeof(*blocker_datums)); for (i = 0; i < num_blockers; ++i) blocker_datums[i] = Int32GetDatum(blockers[i]); } diff --git a/src/backend/utils/adt/multirangetypes.c b/src/backend/utils/adt/multirangetypes.c index 169acf0ef63..a3b6f686794 100644 --- a/src/backend/utils/adt/multirangetypes.c +++ b/src/backend/utils/adt/multirangetypes.c @@ -1000,7 +1000,7 @@ multirange_constructor2(PG_FUNCTION_ARGS) deconstruct_array(rangeArray, rngtypid, rangetyp->typlen, rangetyp->typbyval, rangetyp->typalign, &elements, &nulls, &range_count); - ranges = palloc0(range_count * sizeof(RangeType *)); + ranges = palloc0(range_count * sizeof(*ranges)); for (i = 0; i < range_count; i++) { if (nulls[i]) @@ -1104,7 +1104,7 @@ multirange_union(PG_FUNCTION_ARGS) multirange_deserialize(typcache->rngtype, mr2, &range_count2, &ranges2); range_count3 = range_count1 + range_count2; - ranges3 = palloc0(range_count3 * sizeof(RangeType *)); + ranges3 = palloc0(range_count3 * sizeof(*ranges3)); memcpy(ranges3, ranges1, range_count1 * sizeof(RangeType *)); memcpy(ranges3 + range_count1, ranges2, range_count2 * sizeof(RangeType *)); PG_RETURN_MULTIRANGE_P(make_multirange(typcache->type_id, typcache->rngtype, @@ -1158,7 +1158,7 @@ multirange_minus_internal(Oid mltrngtypoid, TypeCacheEntry *rangetyp, * Worst case: every range in ranges1 makes a different cut to some range * in ranges2. */ - ranges3 = palloc0((range_count1 + range_count2) * sizeof(RangeType *)); + ranges3 = palloc0((range_count1 + range_count2) * sizeof(*ranges3)); range_count3 = 0; /* @@ -1355,7 +1355,7 @@ multirange_intersect_internal(Oid mltrngtypoid, TypeCacheEntry *rangetyp, * but one extra won't hurt. *----------------------------------------------- */ - ranges3 = palloc0((range_count1 + range_count2) * sizeof(RangeType *)); + ranges3 = palloc0((range_count1 + range_count2) * sizeof(*ranges3)); range_count3 = 0; /* @@ -1468,7 +1468,7 @@ range_agg_finalfn(PG_FUNCTION_ARGS) mltrngtypoid = get_fn_expr_rettype(fcinfo->flinfo); typcache = multirange_get_typcache(fcinfo, mltrngtypoid); - ranges = palloc0(range_count * sizeof(RangeType *)); + ranges = palloc0(range_count * sizeof(*ranges)); for (i = 0; i < range_count; i++) ranges[i] = DatumGetRangeTypeP(state->dvalues[i]); diff --git a/src/backend/utils/adt/name.c b/src/backend/utils/adt/name.c index b2487881d54..95aae677fb3 100644 --- a/src/backend/utils/adt/name.c +++ b/src/backend/utils/adt/name.c @@ -299,7 +299,7 @@ current_schemas(PG_FUNCTION_ARGS) int i; ArrayType *array; - names = (Datum *) palloc(list_length(search_path) * sizeof(Datum)); + names = (Datum *) palloc(list_length(search_path) * sizeof(*names)); i = 0; foreach(l, search_path) { diff --git a/src/backend/utils/adt/numeric.c b/src/backend/utils/adt/numeric.c index 2460698df01..e23c3752303 100644 --- a/src/backend/utils/adt/numeric.c +++ b/src/backend/utils/adt/numeric.c @@ -12016,8 +12016,8 @@ accum_sum_rescale(NumericSumAccum *accum, const NumericVar *val) weightdiff = accum_weight - old_weight; - new_pos_digits = palloc0(accum_ndigits * sizeof(int32)); - new_neg_digits = palloc0(accum_ndigits * sizeof(int32)); + new_pos_digits = palloc0(accum_ndigits * sizeof(*new_pos_digits)); + new_neg_digits = palloc0(accum_ndigits * sizeof(*new_neg_digits)); if (accum->pos_digits) { @@ -12105,8 +12105,8 @@ accum_sum_final(NumericSumAccum *accum, NumericVar *result) static void accum_sum_copy(NumericSumAccum *dst, NumericSumAccum *src) { - dst->pos_digits = palloc(src->ndigits * sizeof(int32)); - dst->neg_digits = palloc(src->ndigits * sizeof(int32)); + dst->pos_digits = palloc(src->ndigits * sizeof(*dst->pos_digits)); + dst->neg_digits = palloc(src->ndigits * sizeof(*dst->neg_digits)); memcpy(dst->pos_digits, src->pos_digits, src->ndigits * sizeof(int32)); memcpy(dst->neg_digits, src->neg_digits, src->ndigits * sizeof(int32)); diff --git a/src/backend/utils/adt/oracle_compat.c b/src/backend/utils/adt/oracle_compat.c index a24a2d208fb..7e138f319bc 100644 --- a/src/backend/utils/adt/oracle_compat.c +++ b/src/backend/utils/adt/oracle_compat.c @@ -422,7 +422,7 @@ dotrim(const char *string, int stringlen, int str_len; stringchars = (const char **) palloc(stringlen * sizeof(char *)); - stringmblen = (int *) palloc(stringlen * sizeof(int)); + stringmblen = (int *) palloc(stringlen * sizeof(*stringmblen)); stringnchars = 0; p = string; len = stringlen; @@ -436,7 +436,7 @@ dotrim(const char *string, int stringlen, } setchars = (const char **) palloc(setlen * sizeof(char *)); - setmblen = (int *) palloc(setlen * sizeof(int)); + setmblen = (int *) palloc(setlen * sizeof(*setmblen)); setnchars = 0; p = set; len = setlen; diff --git a/src/backend/utils/adt/orderedsetaggs.c b/src/backend/utils/adt/orderedsetaggs.c index ac3963fc3e0..ce74bd9c8a7 100644 --- a/src/backend/utils/adt/orderedsetaggs.c +++ b/src/backend/utils/adt/orderedsetaggs.c @@ -173,11 +173,11 @@ ordered_set_startup(FunctionCallInfo fcinfo, bool use_tuples) if (ishypothetical) numSortCols++; /* make space for flag column */ qstate->numSortCols = numSortCols; - qstate->sortColIdx = (AttrNumber *) palloc(numSortCols * sizeof(AttrNumber)); - qstate->sortOperators = (Oid *) palloc(numSortCols * sizeof(Oid)); - qstate->eqOperators = (Oid *) palloc(numSortCols * sizeof(Oid)); - qstate->sortCollations = (Oid *) palloc(numSortCols * sizeof(Oid)); - qstate->sortNullsFirsts = (bool *) palloc(numSortCols * sizeof(bool)); + qstate->sortColIdx = (AttrNumber *) palloc(numSortCols * sizeof(*qstate->sortColIdx)); + qstate->sortOperators = (Oid *) palloc(numSortCols * sizeof(*qstate->sortOperators)); + qstate->eqOperators = (Oid *) palloc(numSortCols * sizeof(*qstate->eqOperators)); + qstate->sortCollations = (Oid *) palloc(numSortCols * sizeof(*qstate->sortCollations)); + qstate->sortNullsFirsts = (bool *) palloc(numSortCols * sizeof(*qstate->sortNullsFirsts)); i = 0; foreach(lc, sortlist) @@ -668,7 +668,7 @@ setup_pct_info(int num_percentiles, struct pct_info *pct_info; int i; - pct_info = (struct pct_info *) palloc(num_percentiles * sizeof(struct pct_info)); + pct_info = (struct pct_info *) palloc(num_percentiles * sizeof(*pct_info)); for (i = 0; i < num_percentiles; i++) { @@ -774,8 +774,8 @@ percentile_disc_multi_final(PG_FUNCTION_ARGS) osastate->number_of_rows, false); - result_datum = (Datum *) palloc(num_percentiles * sizeof(Datum)); - result_isnull = (bool *) palloc(num_percentiles * sizeof(bool)); + result_datum = (Datum *) palloc(num_percentiles * sizeof(*result_datum)); + result_isnull = (bool *) palloc(num_percentiles * sizeof(*result_isnull)); /* * Start by dealing with any nulls in the param array - those are sorted @@ -897,8 +897,8 @@ percentile_cont_multi_final_common(FunctionCallInfo fcinfo, osastate->number_of_rows, true); - result_datum = (Datum *) palloc(num_percentiles * sizeof(Datum)); - result_isnull = (bool *) palloc(num_percentiles * sizeof(bool)); + result_datum = (Datum *) palloc(num_percentiles * sizeof(*result_datum)); + result_isnull = (bool *) palloc(num_percentiles * sizeof(*result_isnull)); /* * Start by dealing with any nulls in the param array - those are sorted diff --git a/src/backend/utils/adt/pg_ndistinct.c b/src/backend/utils/adt/pg_ndistinct.c index 8ff4353c4e7..ca6f1ebb53e 100644 --- a/src/backend/utils/adt/pg_ndistinct.c +++ b/src/backend/utils/adt/pg_ndistinct.c @@ -177,7 +177,7 @@ ndistinct_object_end(void *state) /* Create the MVNDistinctItem */ item = palloc_object(MVNDistinctItem); item->nattributes = natts; - item->attributes = palloc0(natts * sizeof(AttrNumber)); + item->attributes = palloc0(natts * sizeof(*item->attributes)); item->ndistinct = (double) parse->ndistinct; for (int i = 0; i < natts; i++) diff --git a/src/backend/utils/adt/rangetypes_typanalyze.c b/src/backend/utils/adt/rangetypes_typanalyze.c index 45ea6cbc780..ae9ac76d172 100644 --- a/src/backend/utils/adt/rangetypes_typanalyze.c +++ b/src/backend/utils/adt/rangetypes_typanalyze.c @@ -288,7 +288,7 @@ compute_range_stats(VacAttrStats *stats, AnalyzeAttrFetchFunc fetchfunc, if (num_hist > num_bins) num_hist = num_bins + 1; - bound_hist_values = (Datum *) palloc(num_hist * sizeof(Datum)); + bound_hist_values = (Datum *) palloc(num_hist * sizeof(*bound_hist_values)); /* * The object of this loop is to construct ranges from first and @@ -352,7 +352,7 @@ compute_range_stats(VacAttrStats *stats, AnalyzeAttrFetchFunc fetchfunc, if (num_hist > num_bins) num_hist = num_bins + 1; - length_hist_values = (Datum *) palloc(num_hist * sizeof(Datum)); + length_hist_values = (Datum *) palloc(num_hist * sizeof(*length_hist_values)); /* * The object of this loop is to copy the first and last lengths[] diff --git a/src/backend/utils/adt/rowtypes.c b/src/backend/utils/adt/rowtypes.c index 7220995ce21..8954249047b 100644 --- a/src/backend/utils/adt/rowtypes.c +++ b/src/backend/utils/adt/rowtypes.c @@ -901,11 +901,11 @@ record_cmp(FunctionCallInfo fcinfo) } /* Break down the tuples into fields */ - values1 = (Datum *) palloc(ncolumns1 * sizeof(Datum)); - nulls1 = (bool *) palloc(ncolumns1 * sizeof(bool)); + values1 = (Datum *) palloc(ncolumns1 * sizeof(*values1)); + nulls1 = (bool *) palloc(ncolumns1 * sizeof(*nulls1)); heap_deform_tuple(&tuple1, tupdesc1, values1, nulls1); - values2 = (Datum *) palloc(ncolumns2 * sizeof(Datum)); - nulls2 = (bool *) palloc(ncolumns2 * sizeof(bool)); + values2 = (Datum *) palloc(ncolumns2 * sizeof(*values2)); + nulls2 = (bool *) palloc(ncolumns2 * sizeof(*nulls2)); heap_deform_tuple(&tuple2, tupdesc2, values2, nulls2); /* @@ -1145,11 +1145,11 @@ record_eq(PG_FUNCTION_ARGS) } /* Break down the tuples into fields */ - values1 = (Datum *) palloc(ncolumns1 * sizeof(Datum)); - nulls1 = (bool *) palloc(ncolumns1 * sizeof(bool)); + values1 = (Datum *) palloc(ncolumns1 * sizeof(*values1)); + nulls1 = (bool *) palloc(ncolumns1 * sizeof(*nulls1)); heap_deform_tuple(&tuple1, tupdesc1, values1, nulls1); - values2 = (Datum *) palloc(ncolumns2 * sizeof(Datum)); - nulls2 = (bool *) palloc(ncolumns2 * sizeof(bool)); + values2 = (Datum *) palloc(ncolumns2 * sizeof(*values2)); + nulls2 = (bool *) palloc(ncolumns2 * sizeof(*nulls2)); heap_deform_tuple(&tuple2, tupdesc2, values2, nulls2); /* @@ -1425,11 +1425,11 @@ record_image_cmp(FunctionCallInfo fcinfo) } /* Break down the tuples into fields */ - values1 = (Datum *) palloc(ncolumns1 * sizeof(Datum)); - nulls1 = (bool *) palloc(ncolumns1 * sizeof(bool)); + values1 = (Datum *) palloc(ncolumns1 * sizeof(*values1)); + nulls1 = (bool *) palloc(ncolumns1 * sizeof(*nulls1)); heap_deform_tuple(&tuple1, tupdesc1, values1, nulls1); - values2 = (Datum *) palloc(ncolumns2 * sizeof(Datum)); - nulls2 = (bool *) palloc(ncolumns2 * sizeof(bool)); + values2 = (Datum *) palloc(ncolumns2 * sizeof(*values2)); + nulls2 = (bool *) palloc(ncolumns2 * sizeof(*nulls2)); heap_deform_tuple(&tuple2, tupdesc2, values2, nulls2); /* @@ -1671,11 +1671,11 @@ record_image_eq(PG_FUNCTION_ARGS) } /* Break down the tuples into fields */ - values1 = (Datum *) palloc(ncolumns1 * sizeof(Datum)); - nulls1 = (bool *) palloc(ncolumns1 * sizeof(bool)); + values1 = (Datum *) palloc(ncolumns1 * sizeof(*values1)); + nulls1 = (bool *) palloc(ncolumns1 * sizeof(*nulls1)); heap_deform_tuple(&tuple1, tupdesc1, values1, nulls1); - values2 = (Datum *) palloc(ncolumns2 * sizeof(Datum)); - nulls2 = (bool *) palloc(ncolumns2 * sizeof(bool)); + values2 = (Datum *) palloc(ncolumns2 * sizeof(*values2)); + nulls2 = (bool *) palloc(ncolumns2 * sizeof(*nulls2)); heap_deform_tuple(&tuple2, tupdesc2, values2, nulls2); /* diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c index 9f85eb86da1..100fbcf52c3 100644 --- a/src/backend/utils/adt/ruleutils.c +++ b/src/backend/utils/adt/ruleutils.c @@ -2569,7 +2569,7 @@ pg_get_constraintdef_worker(Oid constraintId, bool fullCommand, deconstruct_array_builtin(DatumGetArrayTypeP(val), OIDOID, &elems, NULL, &nElems); - operators = (Oid *) palloc(nElems * sizeof(Oid)); + operators = (Oid *) palloc(nElems * sizeof(*operators)); for (i = 0; i < nElems; i++) operators[i] = DatumGetObjectId(elems[i]); @@ -3771,7 +3771,7 @@ deparse_context_for_plan_tree(PlannedStmt *pstmt, List *rtable_names) ListCell *lc; dpns->appendrels = (AppendRelInfo **) - palloc0((ntables + 1) * sizeof(AppendRelInfo *)); + palloc0((ntables + 1) * sizeof(*dpns->appendrels)); foreach(lc, pstmt->appendRelations) { AppendRelInfo *appinfo = lfirst_node(AppendRelInfo, lc); @@ -4400,7 +4400,7 @@ set_relation_column_names(deparse_namespace *dpns, RangeTblEntry *rte, tupdesc = RelationGetDescr(rel); ncolumns = tupdesc->natts; - real_colnames = (char **) palloc(ncolumns * sizeof(char *)); + real_colnames = (char **) palloc(ncolumns * sizeof(*real_colnames)); for (i = 0; i < ncolumns; i++) { @@ -4444,7 +4444,7 @@ set_relation_column_names(deparse_namespace *dpns, RangeTblEntry *rte, colnames = rte->eref->colnames; ncolumns = list_length(colnames); - real_colnames = (char **) palloc(ncolumns * sizeof(char *)); + real_colnames = (char **) palloc(ncolumns * sizeof(*real_colnames)); i = 0; foreach(lc, colnames) @@ -4480,8 +4480,8 @@ set_relation_column_names(deparse_namespace *dpns, RangeTblEntry *rte, * colname_is_unique will not consult that array, which is fine because it * would only be duplicate effort. */ - colinfo->new_colnames = (char **) palloc(ncolumns * sizeof(char *)); - colinfo->is_new_col = (bool *) palloc(ncolumns * sizeof(bool)); + colinfo->new_colnames = (char **) palloc(ncolumns * sizeof(*colinfo->new_colnames)); + colinfo->is_new_col = (bool *) palloc(ncolumns * sizeof(*colinfo->is_new_col)); /* If the RTE is wide enough, use a hash table to avoid O(N^2) costs */ build_colinfo_names_hash(colinfo); @@ -4683,8 +4683,8 @@ set_join_column_names(deparse_namespace *dpns, RangeTblEntry *rte, nnewcolumns = leftcolinfo->num_new_cols + rightcolinfo->num_new_cols - list_length(colinfo->usingNames); colinfo->num_new_cols = nnewcolumns; - colinfo->new_colnames = (char **) palloc0(nnewcolumns * sizeof(char *)); - colinfo->is_new_col = (bool *) palloc0(nnewcolumns * sizeof(bool)); + colinfo->new_colnames = (char **) palloc0(nnewcolumns * sizeof(*colinfo->new_colnames)); + colinfo->is_new_col = (bool *) palloc0(nnewcolumns * sizeof(*colinfo->is_new_col)); /* * Generating the new_colnames array is a bit tricky since any new columns @@ -5096,8 +5096,8 @@ identify_join_columns(JoinExpr *j, RangeTblEntry *jrte, /* Initialize result arrays with zeroes */ numjoincols = list_length(jrte->joinaliasvars); Assert(numjoincols == list_length(jrte->eref->colnames)); - colinfo->leftattnos = (int *) palloc0(numjoincols * sizeof(int)); - colinfo->rightattnos = (int *) palloc0(numjoincols * sizeof(int)); + colinfo->leftattnos = (int *) palloc0(numjoincols * sizeof(*colinfo->leftattnos)); + colinfo->rightattnos = (int *) palloc0(numjoincols * sizeof(*colinfo->rightattnos)); /* * Deconstruct RTE's joinleftcols/joinrightcols into desired format. diff --git a/src/backend/utils/adt/selfuncs.c b/src/backend/utils/adt/selfuncs.c index c760b19db55..3eb1f8e16da 100644 --- a/src/backend/utils/adt/selfuncs.c +++ b/src/backend/utils/adt/selfuncs.c @@ -2436,8 +2436,8 @@ eqjoinsel(PG_FUNCTION_ARGS) if (have_mcvs1 && have_mcvs2) { fmgr_info(opfuncoid, &eqproc); - hasmatch1 = (bool *) palloc0(sslot1.nvalues * sizeof(bool)); - hasmatch2 = (bool *) palloc0(sslot2.nvalues * sizeof(bool)); + hasmatch1 = (bool *) palloc0(sslot1.nvalues * sizeof(*hasmatch1)); + hasmatch2 = (bool *) palloc0(sslot2.nvalues * sizeof(*hasmatch2)); /* * If the MCV lists are long enough to justify hashing, try to look up diff --git a/src/backend/utils/adt/tsquery_cleanup.c b/src/backend/utils/adt/tsquery_cleanup.c index 45de2da900c..8c47c21a647 100644 --- a/src/backend/utils/adt/tsquery_cleanup.c +++ b/src/backend/utils/adt/tsquery_cleanup.c @@ -102,7 +102,7 @@ plaintree(NODE *root, int *len) pl.len = 16; if (root && (root->valnode->type == QI_VAL || root->valnode->type == QI_OPR)) { - pl.ptr = (QueryItem *) palloc(pl.len * sizeof(QueryItem)); + pl.ptr = (QueryItem *) palloc(pl.len * sizeof(*pl.ptr)); plainnode(&pl, root); } else diff --git a/src/backend/utils/adt/tsquery_rewrite.c b/src/backend/utils/adt/tsquery_rewrite.c index 2f9e81fbfea..a1f1989d939 100644 --- a/src/backend/utils/adt/tsquery_rewrite.c +++ b/src/backend/utils/adt/tsquery_rewrite.c @@ -92,7 +92,7 @@ findeq(QTNode *node, QTNode *ex, QTNode *subs, bool *isfind) node->valnode->qoperator.oper == OP_OR); /* matched[] will record which children of node matched */ - matched = (bool *) palloc0(node->nchild * sizeof(bool)); + matched = (bool *) palloc0(node->nchild * sizeof(*matched)); nmatched = 0; i = j = 0; while (i < node->nchild && j < ex->nchild) diff --git a/src/backend/utils/adt/tsvector_op.c b/src/backend/utils/adt/tsvector_op.c index b809089ac5d..fb419102f23 100644 --- a/src/backend/utils/adt/tsvector_op.c +++ b/src/backend/utils/adt/tsvector_op.c @@ -594,7 +594,7 @@ tsvector_delete_arr(PG_FUNCTION_ARGS) * here we optimize things for that scenario: iterate through lexarr * performing binary search of each lexeme from lexarr in tsvector. */ - skip_indices = palloc0(nlex * sizeof(int)); + skip_indices = palloc0(nlex * sizeof(*skip_indices)); for (i = skip_count = 0; i < nlex; i++) { char *lex; @@ -686,8 +686,8 @@ tsvector_unnest(PG_FUNCTION_ARGS) * that in two separate arrays. */ posv = _POSVECPTR(tsin, arrin + i); - positions = palloc(posv->npos * sizeof(Datum)); - weights = palloc(posv->npos * sizeof(Datum)); + positions = palloc(posv->npos * sizeof(*positions)); + weights = palloc(posv->npos * sizeof(*weights)); for (j = 0; j < posv->npos; j++) { positions[j] = Int16GetDatum(WEP_GETPOS(posv->pos[j])); @@ -725,7 +725,7 @@ tsvector_to_array(PG_FUNCTION_ARGS) int i; ArrayType *array; - elements = palloc(tsin->size * sizeof(Datum)); + elements = palloc(tsin->size * sizeof(*elements)); for (i = 0; i < tsin->size; i++) { @@ -1539,7 +1539,7 @@ TS_phrase_output(ExecPhraseData *data, if (data->pos == NULL) { data->pos = (WordEntryPos *) - palloc(max_npos * sizeof(WordEntryPos)); + palloc(max_npos * sizeof(*data->pos)); data->allocated = true; } data->pos[data->npos++] = output_pos; diff --git a/src/backend/utils/adt/varlena.c b/src/backend/utils/adt/varlena.c index baa5b44ea8d..0be4180974e 100644 --- a/src/backend/utils/adt/varlena.c +++ b/src/backend/utils/adt/varlena.c @@ -3331,7 +3331,7 @@ replace_text_regexp(text *src_text, text *pattern_text, initStringInfo(&buf); /* Convert data string to wide characters. */ - data = (pg_wchar *) palloc((src_text_len + 1) * sizeof(pg_wchar)); + data = (pg_wchar *) palloc((src_text_len + 1) * sizeof(*data)); data_len = pg_mb2wchar_with_len(VARDATA_ANY(src_text), data, src_text_len); /* Check whether replace_text has escapes, especially regexp submatches. */ @@ -5464,7 +5464,7 @@ unicode_normalize_func(PG_FUNCTION_ARGS) /* convert to char32_t */ size = pg_mbstrlen_with_len(VARDATA_ANY(input), VARSIZE_ANY_EXHDR(input)); - input_chars = palloc((size + 1) * sizeof(char32_t)); + input_chars = palloc((size + 1) * sizeof(*input_chars)); p = (unsigned char *) VARDATA_ANY(input); for (i = 0; i < size; i++) { @@ -5532,7 +5532,7 @@ unicode_is_normalized(PG_FUNCTION_ARGS) /* convert to char32_t */ size = pg_mbstrlen_with_len(VARDATA_ANY(input), VARSIZE_ANY_EXHDR(input)); - input_chars = palloc((size + 1) * sizeof(char32_t)); + input_chars = palloc((size + 1) * sizeof(*input_chars)); p = (unsigned char *) VARDATA_ANY(input); for (i = 0; i < size; i++) { diff --git a/src/backend/utils/adt/xml.c b/src/backend/utils/adt/xml.c index c8ab9d61c68..715fb7d915f 100644 --- a/src/backend/utils/adt/xml.c +++ b/src/backend/utils/adt/xml.c @@ -1414,7 +1414,7 @@ xml_pnstrdup(const xmlChar *str, size_t len) { xmlChar *result; - result = (xmlChar *) palloc((len + 1) * sizeof(xmlChar)); + result = (xmlChar *) palloc((len + 1) * sizeof(*result)); memcpy(result, str, len * sizeof(xmlChar)); result[len] = 0; return result; @@ -1426,7 +1426,7 @@ pg_xmlCharStrndup(const char *str, size_t len) { xmlChar *result; - result = (xmlChar *) palloc((len + 1) * sizeof(xmlChar)); + result = (xmlChar *) palloc((len + 1) * sizeof(*result)); memcpy(result, str, len); result[len] = '\0'; diff --git a/src/backend/utils/cache/catcache.c b/src/backend/utils/cache/catcache.c index 1d09c66ac95..9a80880be58 100644 --- a/src/backend/utils/cache/catcache.c +++ b/src/backend/utils/cache/catcache.c @@ -936,7 +936,7 @@ InitCatCache(int id, */ cp = (CatCache *) palloc_aligned(sizeof(CatCache), PG_CACHE_LINE_SIZE, MCXT_ALLOC_ZERO); - cp->cc_bucket = palloc0(nbuckets * sizeof(dlist_head)); + cp->cc_bucket = palloc0(nbuckets * sizeof(*cp->cc_bucket)); /* * Many catcaches never receive any list searches. Therefore, we don't diff --git a/src/backend/utils/cache/inval.c b/src/backend/utils/cache/inval.c index 868f8f6188f..eca88a1e369 100644 --- a/src/backend/utils/cache/inval.c +++ b/src/backend/utils/cache/inval.c @@ -1103,7 +1103,7 @@ inplaceGetInvalidationMessages(SharedInvalidationMessage **msgs, *RelcacheInitFileInval = inplaceInvalInfo->RelcacheInitFileInval; nummsgs = NumMessagesInGroup(&inplaceInvalInfo->CurrentCmdInvalidMsgs); *msgs = msgarray = (SharedInvalidationMessage *) - palloc(nummsgs * sizeof(SharedInvalidationMessage)); + palloc(nummsgs * sizeof(*msgarray)); nmsgs = 0; ProcessMessageSubGroupMulti(&inplaceInvalInfo->CurrentCmdInvalidMsgs, diff --git a/src/backend/utils/cache/lsyscache.c b/src/backend/utils/cache/lsyscache.c index 5aa7a26d95c..a07853763fc 100644 --- a/src/backend/utils/cache/lsyscache.c +++ b/src/backend/utils/cache/lsyscache.c @@ -1873,7 +1873,7 @@ get_func_signature(Oid funcid, Oid **argtypes, int *nargs) result = procstruct->prorettype; *nargs = (int) procstruct->pronargs; Assert(*nargs == procstruct->proargtypes.dim1); - *argtypes = (Oid *) palloc(*nargs * sizeof(Oid)); + *argtypes = (Oid *) palloc(*nargs * sizeof(**argtypes)); memcpy(*argtypes, procstruct->proargtypes.values, *nargs * sizeof(Oid)); ReleaseSysCache(tp); diff --git a/src/backend/utils/cache/relcache.c b/src/backend/utils/cache/relcache.c index a4dc1cbe5ae..b8a997a4f26 100644 --- a/src/backend/utils/cache/relcache.c +++ b/src/backend/utils/cache/relcache.c @@ -3109,7 +3109,7 @@ RememberToFreeTupleDescAtEOX(TupleDesc td) oldcxt = MemoryContextSwitchTo(CacheMemoryContext); - EOXactTupleDescArray = (TupleDesc *) palloc(16 * sizeof(TupleDesc)); + EOXactTupleDescArray = (TupleDesc *) palloc(16 * sizeof(*EOXactTupleDescArray)); EOXactTupleDescArrayLen = 16; NextEOXactTupleDescNum = 0; MemoryContextSwitchTo(oldcxt); @@ -6194,7 +6194,7 @@ load_relcache_init_file(bool shared) * helps to guard against broken init files. */ max_rels = 100; - rels = (Relation *) palloc(max_rels * sizeof(Relation)); + rels = (Relation *) palloc(max_rels * sizeof(*rels)); num_rels = 0; nailed_rels = nailed_indexes = 0; diff --git a/src/backend/utils/cache/typcache.c b/src/backend/utils/cache/typcache.c index 0c17d99d021..aca0f14d579 100644 --- a/src/backend/utils/cache/typcache.c +++ b/src/backend/utils/cache/typcache.c @@ -1218,7 +1218,7 @@ load_domaintype_info(TypeCacheEntry *typentry) { cconslen = 8; ccons = (DomainConstraintState **) - palloc(cconslen * sizeof(DomainConstraintState *)); + palloc(cconslen * sizeof(*ccons)); } else if (nccons >= cconslen) { diff --git a/src/backend/utils/fmgr/funcapi.c b/src/backend/utils/fmgr/funcapi.c index f40879f0617..5c138be33b0 100644 --- a/src/backend/utils/fmgr/funcapi.c +++ b/src/backend/utils/fmgr/funcapi.c @@ -1410,7 +1410,7 @@ get_func_arg_info(HeapTuple procTup, ARR_ELEMTYPE(arr) != OIDOID) elog(ERROR, "proallargtypes is not a 1-D Oid array or it contains nulls"); Assert(numargs >= procStruct->pronargs); - *p_argtypes = (Oid *) palloc(numargs * sizeof(Oid)); + *p_argtypes = (Oid *) palloc(numargs * sizeof(**p_argtypes)); memcpy(*p_argtypes, ARR_DATA_PTR(arr), numargs * sizeof(Oid)); } @@ -1419,7 +1419,7 @@ get_func_arg_info(HeapTuple procTup, /* If no proallargtypes, use proargtypes */ numargs = procStruct->proargtypes.dim1; Assert(numargs == procStruct->pronargs); - *p_argtypes = (Oid *) palloc(numargs * sizeof(Oid)); + *p_argtypes = (Oid *) palloc(numargs * sizeof(**p_argtypes)); memcpy(*p_argtypes, procStruct->proargtypes.values, numargs * sizeof(Oid)); } @@ -1456,7 +1456,7 @@ get_func_arg_info(HeapTuple procTup, ARR_ELEMTYPE(arr) != CHAROID) elog(ERROR, "proargmodes is not a 1-D char array of length %d or it contains nulls", numargs); - *p_argmodes = (char *) palloc(numargs * sizeof(char)); + *p_argmodes = (char *) palloc(numargs * sizeof(**p_argmodes)); memcpy(*p_argmodes, ARR_DATA_PTR(arr), numargs * sizeof(char)); } @@ -1498,7 +1498,7 @@ get_func_trftypes(HeapTuple procTup, ARR_HASNULL(arr) || ARR_ELEMTYPE(arr) != OIDOID) elog(ERROR, "protrftypes is not a 1-D Oid array or it contains nulls"); - *p_trftypes = (Oid *) palloc(nelems * sizeof(Oid)); + *p_trftypes = (Oid *) palloc(nelems * sizeof(**p_trftypes)); memcpy(*p_trftypes, ARR_DATA_PTR(arr), nelems * sizeof(Oid)); @@ -1570,7 +1570,7 @@ get_func_input_arg_names(Datum proargnames, Datum proargmodes, } /* extract input-argument names */ - inargnames = (char **) palloc(numargs * sizeof(char *)); + inargnames = (char **) palloc(numargs * sizeof(*inargnames)); numinargs = 0; for (i = 0; i < numargs; i++) { @@ -1809,8 +1809,8 @@ build_function_result_tupdesc_d(char prokind, return NULL; /* extract output-argument types and names */ - outargtypes = (Oid *) palloc(numargs * sizeof(Oid)); - outargnames = (char **) palloc(numargs * sizeof(char *)); + outargtypes = (Oid *) palloc(numargs * sizeof(*outargtypes)); + outargnames = (char **) palloc(numargs * sizeof(*outargnames)); numoutargs = 0; for (i = 0; i < numargs; i++) { @@ -2040,7 +2040,7 @@ extract_variadic_args(FunctionCallInfo fcinfo, int variadic_start, &nargs); /* All the elements of the array have the same type */ - types_res = (Oid *) palloc0(nargs * sizeof(Oid)); + types_res = (Oid *) palloc0(nargs * sizeof(*types_res)); for (i = 0; i < nargs; i++) types_res[i] = element_type; } @@ -2048,9 +2048,9 @@ extract_variadic_args(FunctionCallInfo fcinfo, int variadic_start, { nargs = PG_NARGS() - variadic_start; Assert(nargs > 0); - nulls_res = (bool *) palloc0(nargs * sizeof(bool)); - args_res = (Datum *) palloc0(nargs * sizeof(Datum)); - types_res = (Oid *) palloc0(nargs * sizeof(Oid)); + nulls_res = (bool *) palloc0(nargs * sizeof(*nulls_res)); + args_res = (Datum *) palloc0(nargs * sizeof(*args_res)); + types_res = (Oid *) palloc0(nargs * sizeof(*types_res)); for (i = 0; i < nargs; i++) { diff --git a/src/backend/utils/misc/ps_status.c b/src/backend/utils/misc/ps_status.c index 5d8de92a57b..ec688b211e7 100644 --- a/src/backend/utils/misc/ps_status.c +++ b/src/backend/utils/misc/ps_status.c @@ -200,7 +200,7 @@ save_ps_display_args(int argc, char **argv) /* * move the environment out of the way */ - new_environ = (char **) malloc((i + 1) * sizeof(char *)); + new_environ = (char **) malloc((i + 1) * sizeof(*new_environ)); if (!new_environ) { write_stderr("out of memory\n"); @@ -240,7 +240,7 @@ save_ps_display_args(int argc, char **argv) char **new_argv; int i; - new_argv = (char **) malloc((argc + 1) * sizeof(char *)); + new_argv = (char **) malloc((argc + 1) * sizeof(*new_argv)); if (!new_argv) { write_stderr("out of memory\n"); diff --git a/src/backend/utils/sort/logtape.c b/src/backend/utils/sort/logtape.c index 42bf50221b8..a2c7f1ae8ac 100644 --- a/src/backend/utils/sort/logtape.c +++ b/src/backend/utils/sort/logtape.c @@ -566,7 +566,7 @@ LogicalTapeSetCreate(bool preallocate, SharedFileSet *fileset, int worker) lts->nHoleBlocks = 0L; lts->forgetFreeSpace = false; lts->freeBlocksLen = 32; /* reasonable initial guess */ - lts->freeBlocks = (int64 *) palloc(lts->freeBlocksLen * sizeof(int64)); + lts->freeBlocks = (int64 *) palloc(lts->freeBlocksLen * sizeof(*lts->freeBlocks)); lts->nFreeBlocks = 0; lts->enable_prealloc = preallocate; diff --git a/src/backend/utils/sort/tuplesort.c b/src/backend/utils/sort/tuplesort.c index 88ae529e843..a1cb8197519 100644 --- a/src/backend/utils/sort/tuplesort.c +++ b/src/backend/utils/sort/tuplesort.c @@ -788,7 +788,7 @@ tuplesort_begin_batch(Tuplesortstate *state) } if (state->memtuples == NULL) { - state->memtuples = (SortTuple *) palloc(state->memtupsize * sizeof(SortTuple)); + state->memtuples = (SortTuple *) palloc(state->memtupsize * sizeof(*state->memtuples)); USEMEM(state, GetMemoryChunkSpace(state->memtuples)); } @@ -1884,7 +1884,7 @@ inittapes(Tuplesortstate *state, bool mergeruns) state->nInputTapes = 0; state->nInputRuns = 0; - state->outputTapes = palloc0(state->maxTapes * sizeof(LogicalTape *)); + state->outputTapes = palloc0(state->maxTapes * sizeof(*state->outputTapes)); state->nOutputTapes = 0; state->nOutputRuns = 0; @@ -2109,7 +2109,7 @@ mergeruns(Tuplesortstate *state) * created as needed, here we only allocate the array to hold * them. */ - state->outputTapes = palloc0(state->nInputTapes * sizeof(LogicalTape *)); + state->outputTapes = palloc0(state->nInputTapes * sizeof(*state->outputTapes)); state->nOutputTapes = 0; state->nOutputRuns = 0; @@ -3093,7 +3093,7 @@ leader_takeover_tapes(Tuplesortstate *state) state->nInputTapes = 0; state->nInputRuns = 0; - state->outputTapes = palloc0(nParticipants * sizeof(LogicalTape *)); + state->outputTapes = palloc0(nParticipants * sizeof(*state->outputTapes)); state->nOutputTapes = nParticipants; state->nOutputRuns = nParticipants; diff --git a/src/backend/utils/sort/tuplestore.c b/src/backend/utils/sort/tuplestore.c index def945b0454..5b651233458 100644 --- a/src/backend/utils/sort/tuplestore.c +++ b/src/backend/utils/sort/tuplestore.c @@ -290,7 +290,7 @@ tuplestore_begin_common(int eflags, bool interXact, int maxKBytes) ALLOCSET_SEPARATE_THRESHOLD / sizeof(void *) + 1); state->growmemtuples = true; - state->memtuples = (void **) palloc(state->memtupsize * sizeof(void *)); + state->memtuples = (void **) palloc(state->memtupsize * sizeof(*state->memtuples)); USEMEM(state, GetMemoryChunkSpace(state->memtuples)); @@ -298,7 +298,7 @@ tuplestore_begin_common(int eflags, bool interXact, int maxKBytes) state->readptrcount = 1; state->readptrsize = 8; /* arbitrary */ state->readptrs = (TSReadPointer *) - palloc(state->readptrsize * sizeof(TSReadPointer)); + palloc(state->readptrsize * sizeof(*state->readptrs)); state->readptrs[0].eflags = eflags; state->readptrs[0].eof_reached = false; diff --git a/src/backend/utils/time/snapmgr.c b/src/backend/utils/time/snapmgr.c index 40a2e90e071..f98bd0b6c94 100644 --- a/src/backend/utils/time/snapmgr.c +++ b/src/backend/utils/time/snapmgr.c @@ -1489,7 +1489,7 @@ ImportSnapshot(const char *idstr) (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION), errmsg("invalid snapshot data in file \"%s\"", path))); - snapshot.xip = (TransactionId *) palloc(xcnt * sizeof(TransactionId)); + snapshot.xip = (TransactionId *) palloc(xcnt * sizeof(*snapshot.xip)); for (i = 0; i < xcnt; i++) snapshot.xip[i] = parseXidFromText("xip:", &filebuf, path); @@ -1505,7 +1505,7 @@ ImportSnapshot(const char *idstr) (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION), errmsg("invalid snapshot data in file \"%s\"", path))); - snapshot.subxip = (TransactionId *) palloc(xcnt * sizeof(TransactionId)); + snapshot.subxip = (TransactionId *) palloc(xcnt * sizeof(*snapshot.subxip)); for (i = 0; i < xcnt; i++) snapshot.subxip[i] = parseXidFromText("sxp:", &filebuf, path); } diff --git a/src/bin/initdb/initdb.c b/src/bin/initdb/initdb.c index 92fe2f531f7..92393fdbede 100644 --- a/src/bin/initdb/initdb.c +++ b/src/bin/initdb/initdb.c @@ -444,7 +444,7 @@ escape_quotes_bki(const char *src) static void add_stringlist_item(_stringlist **listhead, const char *str) { - _stringlist *newentry = pg_malloc(sizeof(_stringlist)); + _stringlist *newentry = pg_malloc(sizeof(*newentry)); _stringlist *oldentry; newentry->str = pg_strdup(str); @@ -687,7 +687,7 @@ readfile(const char *path) initStringInfo(&line); maxlines = 1024; - result = (char **) pg_malloc(maxlines * sizeof(char *)); + result = (char **) pg_malloc(maxlines * sizeof(*result)); n = 0; while (pg_get_line_buf(infile, &line)) diff --git a/src/bin/pg_amcheck/pg_amcheck.c b/src/bin/pg_amcheck/pg_amcheck.c index 2b1fd566c35..b92b42d0761 100644 --- a/src/bin/pg_amcheck/pg_amcheck.c +++ b/src/bin/pg_amcheck/pg_amcheck.c @@ -1593,7 +1593,7 @@ compile_database_list(PGconn *conn, SimplePtrList *databases, if (initial_dbname) { - DatabaseInfo *dat = (DatabaseInfo *) pg_malloc0(sizeof(DatabaseInfo)); + DatabaseInfo *dat = (DatabaseInfo *) pg_malloc0(sizeof(*dat)); /* This database is included. Add to list */ if (opts.verbose) @@ -1738,7 +1738,7 @@ compile_database_list(PGconn *conn, SimplePtrList *databases, if (opts.verbose) pg_log_info("including database \"%s\"", datname); - dat = (DatabaseInfo *) pg_malloc0(sizeof(DatabaseInfo)); + dat = (DatabaseInfo *) pg_malloc0(sizeof(*dat)); dat->datname = pstrdup(datname); simple_ptr_list_append(databases, dat); } @@ -2202,7 +2202,7 @@ compile_relation_list_one_db(PGconn *conn, SimplePtrList *relations, { /* Current record pertains to a relation */ - RelationInfo *rel = (RelationInfo *) pg_malloc0(sizeof(RelationInfo)); + RelationInfo *rel = (RelationInfo *) pg_malloc0(sizeof(*rel)); Assert(OidIsValid(oid)); Assert((is_heap && !is_btree) || (is_btree && !is_heap)); diff --git a/src/bin/pg_basebackup/pg_basebackup.c b/src/bin/pg_basebackup/pg_basebackup.c index 0a3ca4315de..d8ca8781aea 100644 --- a/src/bin/pg_basebackup/pg_basebackup.c +++ b/src/bin/pg_basebackup/pg_basebackup.c @@ -320,7 +320,7 @@ kill_bgchild_atexit(void) static void tablespace_list_append(const char *arg) { - TablespaceListCell *cell = (TablespaceListCell *) pg_malloc0(sizeof(TablespaceListCell)); + TablespaceListCell *cell = (TablespaceListCell *) pg_malloc0(sizeof(*cell)); char *dst; char *dst_ptr; const char *arg_ptr; @@ -623,7 +623,7 @@ StartLogStreamer(char *startpos, uint32 timeline, char *sysidentifier, lo; char statusdir[MAXPGPATH]; - param = pg_malloc0(sizeof(logstreamer_param)); + param = pg_malloc0(sizeof(*param)); param->timeline = timeline; param->sysidentifier = sysidentifier; param->wal_compress_algorithm = wal_compress_algorithm; diff --git a/src/bin/pg_basebackup/walmethods.c b/src/bin/pg_basebackup/walmethods.c index eaaabc5f374..beca6c39b9d 100644 --- a/src/bin/pg_basebackup/walmethods.c +++ b/src/bin/pg_basebackup/walmethods.c @@ -102,7 +102,7 @@ static char * dir_get_file_name(WalWriteMethod *wwmethod, const char *pathname, const char *temp_suffix) { - char *filename = pg_malloc0(MAXPGPATH * sizeof(char)); + char *filename = pg_malloc0(MAXPGPATH * sizeof(*filename)); snprintf(filename, MAXPGPATH, "%s%s%s", pathname, @@ -275,7 +275,7 @@ dir_open_for_write(WalWriteMethod *wwmethod, const char *pathname, } } - f = pg_malloc0(sizeof(DirectoryMethodFile)); + f = pg_malloc0(sizeof(*f)); #ifdef HAVE_LIBZ if (wwmethod->compression_algorithm == PG_COMPRESSION_GZIP) f->gzfp = gzfp; @@ -643,7 +643,7 @@ CreateWalDirectoryMethod(const char *basedir, { DirectoryMethodData *wwmethod; - wwmethod = pg_malloc0(sizeof(DirectoryMethodData)); + wwmethod = pg_malloc0(sizeof(*wwmethod)); *((const WalWriteMethodOps **) &wwmethod->base.ops) = &WalDirectoryMethodOps; wwmethod->base.compression_algorithm = compression_algorithm; @@ -825,7 +825,7 @@ static char * tar_get_file_name(WalWriteMethod *wwmethod, const char *pathname, const char *temp_suffix) { - char *filename = pg_malloc0(MAXPGPATH * sizeof(char)); + char *filename = pg_malloc0(MAXPGPATH * sizeof(*filename)); snprintf(filename, MAXPGPATH, "%s%s", pathname, temp_suffix ? temp_suffix : ""); @@ -893,7 +893,7 @@ tar_open_for_write(WalWriteMethod *wwmethod, const char *pathname, return NULL; } - tar_data->currentfile = pg_malloc0(sizeof(TarMethodFile)); + tar_data->currentfile = pg_malloc0(sizeof(*tar_data->currentfile)); tar_data->currentfile->base.wwmethod = wwmethod; tmppath = tar_get_file_name(wwmethod, pathname, temp_suffix); @@ -1360,7 +1360,7 @@ CreateWalTarMethod(const char *tarbase, const char *suffix = (compression_algorithm == PG_COMPRESSION_GZIP) ? ".tar.gz" : ".tar"; - wwmethod = pg_malloc0(sizeof(TarMethodData)); + wwmethod = pg_malloc0(sizeof(*wwmethod)); *((const WalWriteMethodOps **) &wwmethod->base.ops) = &WalTarMethodOps; wwmethod->base.compression_algorithm = compression_algorithm; diff --git a/src/bin/pg_combinebackup/load_manifest.c b/src/bin/pg_combinebackup/load_manifest.c index 44db0d2b164..c60e82adde6 100644 --- a/src/bin/pg_combinebackup/load_manifest.c +++ b/src/bin/pg_combinebackup/load_manifest.c @@ -139,7 +139,7 @@ load_backup_manifest(char *backup_directory) /* Create the hash table. */ ht = manifest_files_create(initial_size, NULL); - result = pg_malloc0(sizeof(manifest_data)); + result = pg_malloc0(sizeof(*result)); result->files = ht; context.private_data = result; context.version_cb = combinebackup_version_cb; diff --git a/src/bin/pg_combinebackup/pg_combinebackup.c b/src/bin/pg_combinebackup/pg_combinebackup.c index c9bf0a9e105..0cb001fe9a5 100644 --- a/src/bin/pg_combinebackup/pg_combinebackup.c +++ b/src/bin/pg_combinebackup/pg_combinebackup.c @@ -455,7 +455,7 @@ main(int argc, char *argv[]) static void add_tablespace_mapping(cb_options *opt, char *arg) { - cb_tablespace_mapping *tsmap = pg_malloc0(sizeof(cb_tablespace_mapping)); + cb_tablespace_mapping *tsmap = pg_malloc0(sizeof(*tsmap)); char *dst; char *dst_ptr; char *arg_ptr; @@ -1171,7 +1171,7 @@ process_directory_recursively(Oid tsoid, static void remember_to_cleanup_directory(char *target_path, bool rmtopdir) { - cb_cleanup_dir *dir = pg_malloc(sizeof(cb_cleanup_dir)); + cb_cleanup_dir *dir = pg_malloc(sizeof(*dir)); dir->target_path = target_path; dir->rmtopdir = rmtopdir; @@ -1259,7 +1259,7 @@ scan_for_existing_tablespaces(char *pathname, cb_options *opt) } /* Create a new tablespace object. */ - ts = pg_malloc0(sizeof(cb_tablespace)); + ts = pg_malloc0(sizeof(*ts)); ts->oid = oid; /* diff --git a/src/bin/pg_combinebackup/reconstruct.c b/src/bin/pg_combinebackup/reconstruct.c index 38d8e8a2dc9..d0718aab3c7 100644 --- a/src/bin/pg_combinebackup/reconstruct.c +++ b/src/bin/pg_combinebackup/reconstruct.c @@ -120,7 +120,7 @@ reconstruct_from_incremental_file(char *input_filename, * Every block must come either from the latest version of the file or * from one of the prior backups. */ - source = pg_malloc0(sizeof(rfile *) * (1 + n_prior_backups)); + source = pg_malloc0(sizeof(*source) * (1 + n_prior_backups)); /* * Use the information from the latest incremental file to figure out how @@ -135,8 +135,8 @@ reconstruct_from_incremental_file(char *input_filename, * need to obtain it and at what offset in that file it's stored. * sourcemap gives us the first of these things, and offsetmap the latter. */ - sourcemap = pg_malloc0(sizeof(rfile *) * block_length); - offsetmap = pg_malloc0(sizeof(off_t) * block_length); + sourcemap = pg_malloc0(sizeof(*sourcemap) * block_length); + offsetmap = pg_malloc0(sizeof(*offsetmap) * block_length); /* * Every block that is present in the newest incremental file should be @@ -483,7 +483,7 @@ make_incremental_rfile(char *filename) if (rf->num_blocks > 0) { rf->relative_block_numbers = - pg_malloc0(sizeof(BlockNumber) * rf->num_blocks); + pg_malloc0(sizeof(*rf->relative_block_numbers) * rf->num_blocks); read_bytes(rf, rf->relative_block_numbers, sizeof(BlockNumber) * rf->num_blocks); } @@ -512,7 +512,7 @@ make_rfile(char *filename, bool missing_ok) { rfile *rf; - rf = pg_malloc0(sizeof(rfile)); + rf = pg_malloc0(sizeof(*rf)); rf->filename = pstrdup(filename); if ((rf->fd = open(filename, O_RDONLY | PG_BINARY, 0)) < 0) { diff --git a/src/bin/pg_combinebackup/write_manifest.c b/src/bin/pg_combinebackup/write_manifest.c index c845175a82c..43efb6c2696 100644 --- a/src/bin/pg_combinebackup/write_manifest.c +++ b/src/bin/pg_combinebackup/write_manifest.c @@ -47,7 +47,7 @@ static size_t hex_encode(const uint8 *src, size_t len, char *dst); manifest_writer * create_manifest_writer(char *directory, uint64 system_identifier) { - manifest_writer *mwriter = pg_malloc(sizeof(manifest_writer)); + manifest_writer *mwriter = pg_malloc(sizeof(*mwriter)); snprintf(mwriter->pathname, MAXPGPATH, "%s/backup_manifest", directory); mwriter->fd = -1; diff --git a/src/bin/pg_ctl/pg_ctl.c b/src/bin/pg_ctl/pg_ctl.c index dfe7b4d2f9e..cd8916d78f2 100644 --- a/src/bin/pg_ctl/pg_ctl.c +++ b/src/bin/pg_ctl/pg_ctl.c @@ -346,7 +346,7 @@ readfile(const char *path, int *numlines) { /* empty file */ close(fd); - result = (char **) pg_malloc(sizeof(char *)); + result = (char **) pg_malloc(sizeof(*result)); *result = NULL; return result; } @@ -374,7 +374,7 @@ readfile(const char *path, int *numlines) } /* set up the result buffer */ - result = (char **) pg_malloc((nlines + 1) * sizeof(char *)); + result = (char **) pg_malloc((nlines + 1) * sizeof(*result)); *numlines = nlines; /* now split the buffer into lines */ diff --git a/src/bin/pg_dump/compress_gzip.c b/src/bin/pg_dump/compress_gzip.c index be31209f811..99b5b2746f5 100644 --- a/src/bin/pg_dump/compress_gzip.c +++ b/src/bin/pg_dump/compress_gzip.c @@ -57,7 +57,7 @@ DeflateCompressorInit(CompressorState *cs) GzipCompressorState *gzipcs; z_streamp zp; - gzipcs = (GzipCompressorState *) pg_malloc0(sizeof(GzipCompressorState)); + gzipcs = (GzipCompressorState *) pg_malloc0(sizeof(*gzipcs)); zp = gzipcs->zp = (z_streamp) pg_malloc(sizeof(z_stream)); zp->zalloc = Z_NULL; zp->zfree = Z_NULL; diff --git a/src/bin/pg_dump/compress_io.c b/src/bin/pg_dump/compress_io.c index 9cadc6f2a3f..6faad249121 100644 --- a/src/bin/pg_dump/compress_io.c +++ b/src/bin/pg_dump/compress_io.c @@ -125,7 +125,7 @@ AllocateCompressor(const pg_compress_specification compression_spec, { CompressorState *cs; - cs = (CompressorState *) pg_malloc0(sizeof(CompressorState)); + cs = (CompressorState *) pg_malloc0(sizeof(*cs)); cs->readF = readF; cs->writeF = writeF; @@ -195,7 +195,7 @@ InitCompressFileHandle(const pg_compress_specification compression_spec) { CompressFileHandle *CFH; - CFH = pg_malloc0(sizeof(CompressFileHandle)); + CFH = pg_malloc0(sizeof(*CFH)); if (compression_spec.algorithm == PG_COMPRESSION_NONE) InitCompressFileHandleNone(CFH, compression_spec); diff --git a/src/bin/pg_dump/compress_none.c b/src/bin/pg_dump/compress_none.c index 94c155a572d..996acb775e2 100644 --- a/src/bin/pg_dump/compress_none.c +++ b/src/bin/pg_dump/compress_none.c @@ -124,7 +124,7 @@ InitCompressorNone(CompressorState *cs, { NoneCompressorState *nonecs; - nonecs = (NoneCompressorState *) pg_malloc(sizeof(NoneCompressorState)); + nonecs = (NoneCompressorState *) pg_malloc(sizeof(*nonecs)); nonecs->buflen = DEFAULT_IO_BUFFER_SIZE; nonecs->buffer = pg_malloc(nonecs->buflen); nonecs->bufdata = 0; diff --git a/src/bin/pg_dump/dumputils.c b/src/bin/pg_dump/dumputils.c index 2d22723aa91..55860259d9e 100644 --- a/src/bin/pg_dump/dumputils.c +++ b/src/bin/pg_dump/dumputils.c @@ -160,7 +160,7 @@ buildACLCommands(const char *name, const char *subname, const char *nspname, * Besides, a false mismatch will just cause the output to be a little * more verbose than it really needed to be. */ - grantitems = (char **) pg_malloc(naclitems * sizeof(char *)); + grantitems = (char **) pg_malloc(naclitems * sizeof(*grantitems)); for (i = 0; i < naclitems; i++) { bool found = false; @@ -176,7 +176,7 @@ buildACLCommands(const char *name, const char *subname, const char *nspname, if (!found) grantitems[ngrantitems++] = aclitems[i]; } - revokeitems = (char **) pg_malloc(nbaseitems * sizeof(char *)); + revokeitems = (char **) pg_malloc(nbaseitems * sizeof(*revokeitems)); for (i = 0; i < nbaseitems; i++) { bool found = false; @@ -774,7 +774,7 @@ SplitGUCList(char *rawstring, char separator, * list terminator. */ *namelist = nextptr = (char **) - pg_malloc((strlen(rawstring) / 2 + 2) * sizeof(char *)); + pg_malloc((strlen(rawstring) / 2 + 2) * sizeof(*nextptr)); *nextptr = NULL; while (isspace((unsigned char) *nextp)) diff --git a/src/bin/pg_dump/parallel.c b/src/bin/pg_dump/parallel.c index 086adcdc502..92ace7d5ddf 100644 --- a/src/bin/pg_dump/parallel.c +++ b/src/bin/pg_dump/parallel.c @@ -469,7 +469,7 @@ WaitForTerminatingWorkers(ParallelState *pstate) } #else /* WIN32 */ /* On Windows, we must use WaitForMultipleObjects() */ - HANDLE *lpHandles = pg_malloc(sizeof(HANDLE) * pstate->numWorkers); + HANDLE *lpHandles = pg_malloc(sizeof(*lpHandles) * pstate->numWorkers); int nrun = 0; DWORD ret; uintptr_t hThread; @@ -903,7 +903,7 @@ ParallelBackupStart(ArchiveHandle *AH) Assert(AH->public.numWorkers > 0); - pstate = (ParallelState *) pg_malloc(sizeof(ParallelState)); + pstate = (ParallelState *) pg_malloc(sizeof(*pstate)); pstate->numWorkers = AH->public.numWorkers; pstate->te = NULL; @@ -914,9 +914,9 @@ ParallelBackupStart(ArchiveHandle *AH) /* Create status arrays, being sure to initialize all fields to 0 */ pstate->te = (TocEntry **) - pg_malloc0(pstate->numWorkers * sizeof(TocEntry *)); + pg_malloc0(pstate->numWorkers * sizeof(*pstate->te)); pstate->parallelSlot = (ParallelSlot *) - pg_malloc0(pstate->numWorkers * sizeof(ParallelSlot)); + pg_malloc0(pstate->numWorkers * sizeof(*pstate->parallelSlot)); #ifdef WIN32 /* Make fmtId() and fmtQualifiedId() use thread-local storage */ @@ -969,7 +969,7 @@ ParallelBackupStart(ArchiveHandle *AH) #ifdef WIN32 /* Create transient structure to pass args to worker function */ - wi = (WorkerInfo *) pg_malloc(sizeof(WorkerInfo)); + wi = (WorkerInfo *) pg_malloc(sizeof(*wi)); wi->AH = AH; wi->slot = slot; diff --git a/src/bin/pg_dump/pg_backup_archiver.c b/src/bin/pg_dump/pg_backup_archiver.c index 4a63f7392ae..f7687627152 100644 --- a/src/bin/pg_dump/pg_backup_archiver.c +++ b/src/bin/pg_dump/pg_backup_archiver.c @@ -134,7 +134,7 @@ static void StrictNamesCheck(RestoreOptions *ropt); DumpOptions * NewDumpOptions(void) { - DumpOptions *opts = (DumpOptions *) pg_malloc(sizeof(DumpOptions)); + DumpOptions *opts = (DumpOptions *) pg_malloc(sizeof(*opts)); InitDumpOptions(opts); return opts; @@ -1107,7 +1107,7 @@ NewRestoreOptions(void) { RestoreOptions *opts; - opts = (RestoreOptions *) pg_malloc0(sizeof(RestoreOptions)); + opts = (RestoreOptions *) pg_malloc0(sizeof(*opts)); /* set any fields that shouldn't default to zeroes */ opts->format = archUnknown; @@ -1244,7 +1244,7 @@ ArchiveEntry(Archive *AHX, CatalogId catalogId, DumpId dumpId, ArchiveHandle *AH = (ArchiveHandle *) AHX; TocEntry *newToc; - newToc = (TocEntry *) pg_malloc0(sizeof(TocEntry)); + newToc = (TocEntry *) pg_malloc0(sizeof(*newToc)); AH->tocCount++; if (dumpId > AH->maxDumpId) @@ -1272,7 +1272,7 @@ ArchiveEntry(Archive *AHX, CatalogId catalogId, DumpId dumpId, if (opts->nDeps > 0) { - newToc->dependencies = (DumpId *) pg_malloc(opts->nDeps * sizeof(DumpId)); + newToc->dependencies = (DumpId *) pg_malloc(opts->nDeps * sizeof(*newToc->dependencies)); memcpy(newToc->dependencies, opts->deps, opts->nDeps * sizeof(DumpId)); newToc->nDeps = opts->nDeps; } @@ -1575,7 +1575,7 @@ SortTocFromFile(Archive *AHX) StringInfoData linebuf; /* Allocate space for the 'wanted' array, and init it */ - ropt->idWanted = (bool *) pg_malloc0(sizeof(bool) * AH->maxDumpId); + ropt->idWanted = (bool *) pg_malloc0(sizeof(*ropt->idWanted) * AH->maxDumpId); /* Setup the file */ fh = fopen(ropt->tocFile, PG_BINARY_R); @@ -1991,7 +1991,7 @@ buildTocEntryArrays(ArchiveHandle *AH) TocEntry *te; AH->tocsByDumpId = (TocEntry **) pg_malloc0((maxDumpId + 1) * sizeof(TocEntry *)); - AH->tableDataId = (DumpId *) pg_malloc0((maxDumpId + 1) * sizeof(DumpId)); + AH->tableDataId = (DumpId *) pg_malloc0((maxDumpId + 1) * sizeof(*AH->tableDataId)); for (te = AH->toc->next; te != AH->toc; te = te->next) { @@ -2385,7 +2385,7 @@ _allocAH(const char *FileSpec, const ArchiveFormat fmt, pg_log_debug("allocating AH for %s, format %d", FileSpec ? FileSpec : "(stdio)", fmt); - AH = (ArchiveHandle *) pg_malloc0(sizeof(ArchiveHandle)); + AH = (ArchiveHandle *) pg_malloc0(sizeof(*AH)); AH->version = K_VERS_SELF; @@ -2509,7 +2509,7 @@ WriteDataChunks(ArchiveHandle *AH, ParallelState *pstate) TocEntry **tes; int ntes; - tes = (TocEntry **) pg_malloc(AH->tocCount * sizeof(TocEntry *)); + tes = (TocEntry **) pg_malloc(AH->tocCount * sizeof(*tes)); ntes = 0; for (te = AH->toc->next; te != AH->toc; te = te->next) { @@ -2720,7 +2720,7 @@ ReadToc(ArchiveHandle *AH) for (i = 0; i < AH->tocCount; i++) { - te = (TocEntry *) pg_malloc0(sizeof(TocEntry)); + te = (TocEntry *) pg_malloc0(sizeof(*te)); te->dumpId = ReadInt(AH); if (te->dumpId > AH->maxDumpId) @@ -2817,7 +2817,7 @@ ReadToc(ArchiveHandle *AH) if (AH->version >= K_VERS_1_5) { depSize = 100; - deps = (DumpId *) pg_malloc(sizeof(DumpId) * depSize); + deps = (DumpId *) pg_malloc(sizeof(*deps) * depSize); depIdx = 0; for (;;) { @@ -4883,7 +4883,7 @@ fix_dependencies(ArchiveHandle *AH) { if (strcmp(te2->desc, "BLOBS") == 0) { - te->dependencies = (DumpId *) pg_malloc(sizeof(DumpId)); + te->dependencies = (DumpId *) pg_malloc(sizeof(*te->dependencies)); te->dependencies[0] = te2->dumpId; te->nDeps++; te->depCount++; @@ -4926,7 +4926,7 @@ fix_dependencies(ArchiveHandle *AH) for (te = AH->toc->next; te != AH->toc; te = te->next) { if (te->nRevDeps > 0) - te->revDeps = (DumpId *) pg_malloc(te->nRevDeps * sizeof(DumpId)); + te->revDeps = (DumpId *) pg_malloc(te->nRevDeps * sizeof(*te->revDeps)); te->nRevDeps = 0; } @@ -5041,7 +5041,7 @@ identify_locking_dependencies(ArchiveHandle *AH, TocEntry *te) * difference between a dependency on a table and a dependency on its * data, so that closer analysis would be needed here. */ - lockids = (DumpId *) pg_malloc(te->nDeps * sizeof(DumpId)); + lockids = (DumpId *) pg_malloc(te->nDeps * sizeof(*lockids)); nlockids = 0; for (i = 0; i < te->nDeps; i++) { @@ -5149,11 +5149,11 @@ CloneArchive(ArchiveHandle *AH) ArchiveHandle *clone; /* Make a "flat" copy */ - clone = (ArchiveHandle *) pg_malloc(sizeof(ArchiveHandle)); + clone = (ArchiveHandle *) pg_malloc(sizeof(*clone)); memcpy(clone, AH, sizeof(ArchiveHandle)); /* Likewise flat-copy the RestoreOptions, so we can alter them locally */ - clone->public.ropt = (RestoreOptions *) pg_malloc(sizeof(RestoreOptions)); + clone->public.ropt = (RestoreOptions *) pg_malloc(sizeof(*clone->public.ropt)); memcpy(clone->public.ropt, AH->public.ropt, sizeof(RestoreOptions)); /* Handle format-independent fields */ diff --git a/src/bin/pg_dump/pg_backup_custom.c b/src/bin/pg_dump/pg_backup_custom.c index 2226520dffc..985fc74d18d 100644 --- a/src/bin/pg_dump/pg_backup_custom.c +++ b/src/bin/pg_dump/pg_backup_custom.c @@ -136,7 +136,7 @@ InitArchiveFmt_Custom(ArchiveHandle *AH) AH->WorkerJobRestorePtr = _WorkerJobRestoreCustom; /* Set up a private area. */ - ctx = (lclContext *) pg_malloc0(sizeof(lclContext)); + ctx = (lclContext *) pg_malloc0(sizeof(*ctx)); AH->formatData = ctx; /* @@ -199,7 +199,7 @@ _ArchiveEntry(ArchiveHandle *AH, TocEntry *te) { lclTocEntry *ctx; - ctx = (lclTocEntry *) pg_malloc0(sizeof(lclTocEntry)); + ctx = (lclTocEntry *) pg_malloc0(sizeof(*ctx)); if (te->dataDumper) ctx->dataState = K_OFFSET_POS_NOT_SET; else @@ -240,7 +240,7 @@ _ReadExtraToc(ArchiveHandle *AH, TocEntry *te) if (ctx == NULL) { - ctx = (lclTocEntry *) pg_malloc0(sizeof(lclTocEntry)); + ctx = (lclTocEntry *) pg_malloc0(sizeof(*ctx)); te->formatData = ctx; } diff --git a/src/bin/pg_dump/pg_backup_directory.c b/src/bin/pg_dump/pg_backup_directory.c index 94d401d8a4e..cebc505ea40 100644 --- a/src/bin/pg_dump/pg_backup_directory.c +++ b/src/bin/pg_dump/pg_backup_directory.c @@ -140,7 +140,7 @@ InitArchiveFmt_Directory(ArchiveHandle *AH) AH->WorkerJobDumpPtr = _WorkerJobDumpDirectory; /* Set up our private context */ - ctx = (lclContext *) pg_malloc0(sizeof(lclContext)); + ctx = (lclContext *) pg_malloc0(sizeof(*ctx)); AH->formatData = ctx; ctx->dataFH = NULL; @@ -200,7 +200,7 @@ _ArchiveEntry(ArchiveHandle *AH, TocEntry *te) lclTocEntry *tctx; char fn[MAXPGPATH]; - tctx = (lclTocEntry *) pg_malloc0(sizeof(lclTocEntry)); + tctx = (lclTocEntry *) pg_malloc0(sizeof(*tctx)); if (strcmp(te->desc, "BLOBS") == 0) { snprintf(fn, MAXPGPATH, "blobs_%d.toc", te->dumpId); @@ -252,7 +252,7 @@ _ReadExtraToc(ArchiveHandle *AH, TocEntry *te) if (tctx == NULL) { - tctx = (lclTocEntry *) pg_malloc0(sizeof(lclTocEntry)); + tctx = (lclTocEntry *) pg_malloc0(sizeof(*tctx)); te->formatData = tctx; } diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c index 24ad201af2f..16f74738976 100644 --- a/src/bin/pg_dump/pg_dump.c +++ b/src/bin/pg_dump/pg_dump.c @@ -1542,7 +1542,7 @@ setup_connection(Archive *AH, const char *dumpencoding, * Initialize prepared-query state to "nothing prepared". We do this here * so that a parallel dump worker will have its own state. */ - AH->is_prepared = (bool *) pg_malloc0(NUM_PREP_QUERIES * sizeof(bool)); + AH->is_prepared = (bool *) pg_malloc0(NUM_PREP_QUERIES * sizeof(*AH->is_prepared)); /* * Start transaction-snapshot mode transaction to dump consistent data. @@ -2570,7 +2570,7 @@ dumpTableData_insert(Archive *fout, const void *dcontext) * actual column value --- but we can save a few cycles by fetching nulls * rather than the uninteresting-to-us value. */ - attgenerated = (char *) pg_malloc(tbinfo->numatts * sizeof(char)); + attgenerated = (char *) pg_malloc(tbinfo->numatts * sizeof(*attgenerated)); appendPQExpBufferStr(q, "DECLARE _pg_dump_cursor CURSOR FOR SELECT "); nfields = 0; for (i = 0; i < tbinfo->numatts; i++) @@ -3071,7 +3071,7 @@ makeTableDataInfo(DumpOptions *dopt, TableInfo *tbinfo) return; /* OK, let's dump it */ - tdinfo = (TableDataInfo *) pg_malloc(sizeof(TableDataInfo)); + tdinfo = (TableDataInfo *) pg_malloc(sizeof(*tdinfo)); if (tbinfo->relkind == RELKIND_MATVIEW) tdinfo->dobj.objType = DO_REFRESH_MATVIEW; @@ -4074,7 +4074,7 @@ getLOs(Archive *fout) * pg_largeobject_metadata so that any large object * comments/seclables are dumped after it. */ - loinfo->dobj.dependencies = (DumpId *) pg_malloc(sizeof(DumpId)); + loinfo->dobj.dependencies = (DumpId *) pg_malloc(sizeof(*loinfo->dobj.dependencies)); loinfo->dobj.dependencies[0] = lo_metadata_dumpId; loinfo->dobj.nDeps = loinfo->dobj.allocDeps = 1; } @@ -4086,14 +4086,14 @@ getLOs(Archive *fout) * Create a "BLOBS" data item for the group, too. This is just a * placeholder for sorting; it carries no data now. */ - lodata = (DumpableObject *) pg_malloc(sizeof(DumpableObject)); + lodata = (DumpableObject *) pg_malloc(sizeof(*lodata)); lodata->objType = DO_LARGE_OBJECT_DATA; lodata->catId = nilCatalogId; AssignDumpId(lodata); lodata->name = pg_strdup(namebuf); lodata->components |= DUMP_COMPONENT_DATA; /* Set up explicit dependency from data to metadata */ - lodata->dependencies = (DumpId *) pg_malloc(sizeof(DumpId)); + lodata->dependencies = (DumpId *) pg_malloc(sizeof(*lodata->dependencies)); lodata->dependencies[0] = loinfo->dobj.dumpId; lodata->nDeps = lodata->allocDeps = 1; } @@ -4309,7 +4309,7 @@ getPolicies(Archive *fout, TableInfo tblinfo[], int numTables) * Note: use tableoid 0 so that this object won't be mistaken for * something that pg_depend entries apply to. */ - polinfo = pg_malloc(sizeof(PolicyInfo)); + polinfo = pg_malloc(sizeof(*polinfo)); polinfo->dobj.objType = DO_POLICY; polinfo->dobj.catId.tableoid = 0; polinfo->dobj.catId.oid = tbinfo->dobj.catId.oid; @@ -4365,7 +4365,7 @@ getPolicies(Archive *fout, TableInfo tblinfo[], int numTables) i_polqual = PQfnumber(res, "polqual"); i_polwithcheck = PQfnumber(res, "polwithcheck"); - polinfo = pg_malloc(ntups * sizeof(PolicyInfo)); + polinfo = pg_malloc(ntups * sizeof(*polinfo)); for (j = 0; j < ntups; j++) { @@ -4607,7 +4607,7 @@ getPublications(Archive *fout) i_pubviaroot = PQfnumber(res, "pubviaroot"); i_pubgencols = PQfnumber(res, "pubgencols"); - pubinfo = pg_malloc(ntups * sizeof(PublicationInfo)); + pubinfo = pg_malloc(ntups * sizeof(*pubinfo)); for (i = 0; i < ntups; i++) { @@ -4786,7 +4786,7 @@ getPublicationNamespaces(Archive *fout) i_pnnspid = PQfnumber(res, "pnnspid"); /* this allocation may be more than we need */ - pubsinfo = pg_malloc(ntups * sizeof(PublicationSchemaInfo)); + pubsinfo = pg_malloc(ntups * sizeof(*pubsinfo)); j = 0; for (i = 0; i < ntups; i++) @@ -4885,7 +4885,7 @@ getPublicationTables(Archive *fout, TableInfo tblinfo[], int numTables) i_prattrs = PQfnumber(res, "prattrs"); /* this allocation may be more than we need */ - pubrinfo = pg_malloc(ntups * sizeof(PublicationRelInfo)); + pubrinfo = pg_malloc(ntups * sizeof(*pubrinfo)); j = 0; for (i = 0; i < ntups; i++) @@ -5262,7 +5262,7 @@ getSubscriptions(Archive *fout) i_suborigin = PQfnumber(res, "suborigin"); i_suboriginremotelsn = PQfnumber(res, "suboriginremotelsn"); - subinfo = pg_malloc(ntups * sizeof(SubscriptionInfo)); + subinfo = pg_malloc(ntups * sizeof(*subinfo)); for (i = 0; i < ntups; i++) { @@ -5356,7 +5356,7 @@ getSubscriptionRelations(Archive *fout) i_srsubstate = PQfnumber(res, "srsubstate"); i_srsublsn = PQfnumber(res, "srsublsn"); - subrinfo = pg_malloc(ntups * sizeof(SubRelInfo)); + subrinfo = pg_malloc(ntups * sizeof(*subrinfo)); for (int i = 0; i < ntups; i++) { Oid cur_srsubid = atooid(PQgetvalue(res, i, i_srsubid)); @@ -5837,7 +5837,7 @@ collectBinaryUpgradeClassOids(Archive *fout) nbinaryUpgradeClassOids = PQntuples(res); binaryUpgradeClassOids = (BinaryUpgradeClassOidItem *) - pg_malloc(nbinaryUpgradeClassOids * sizeof(BinaryUpgradeClassOidItem)); + pg_malloc(nbinaryUpgradeClassOids * sizeof(*binaryUpgradeClassOids)); for (int i = 0; i < nbinaryUpgradeClassOids; i++) { @@ -6018,7 +6018,7 @@ getNamespaces(Archive *fout) ntups = PQntuples(res); - nsinfo = (NamespaceInfo *) pg_malloc(ntups * sizeof(NamespaceInfo)); + nsinfo = (NamespaceInfo *) pg_malloc(ntups * sizeof(*nsinfo)); i_tableoid = PQfnumber(res, "tableoid"); i_oid = PQfnumber(res, "oid"); @@ -6150,7 +6150,7 @@ getExtensions(Archive *fout, int *numExtensions) if (ntups == 0) goto cleanup; - extinfo = (ExtensionInfo *) pg_malloc(ntups * sizeof(ExtensionInfo)); + extinfo = (ExtensionInfo *) pg_malloc(ntups * sizeof(*extinfo)); i_tableoid = PQfnumber(res, "tableoid"); i_oid = PQfnumber(res, "oid"); @@ -6249,7 +6249,7 @@ getTypes(Archive *fout) ntups = PQntuples(res); - tyinfo = (TypeInfo *) pg_malloc(ntups * sizeof(TypeInfo)); + tyinfo = (TypeInfo *) pg_malloc(ntups * sizeof(*tyinfo)); i_tableoid = PQfnumber(res, "tableoid"); i_oid = PQfnumber(res, "oid"); @@ -6335,7 +6335,7 @@ getTypes(Archive *fout) (tyinfo[i].typtype == TYPTYPE_BASE || tyinfo[i].typtype == TYPTYPE_RANGE)) { - stinfo = (ShellTypeInfo *) pg_malloc(sizeof(ShellTypeInfo)); + stinfo = (ShellTypeInfo *) pg_malloc(sizeof(*stinfo)); stinfo->dobj.objType = DO_SHELL_TYPE; stinfo->dobj.catId = nilCatalogId; AssignDumpId(&stinfo->dobj); @@ -6398,7 +6398,7 @@ getOperators(Archive *fout) ntups = PQntuples(res); - oprinfo = (OprInfo *) pg_malloc(ntups * sizeof(OprInfo)); + oprinfo = (OprInfo *) pg_malloc(ntups * sizeof(*oprinfo)); i_tableoid = PQfnumber(res, "tableoid"); i_oid = PQfnumber(res, "oid"); @@ -6470,7 +6470,7 @@ getCollations(Archive *fout) ntups = PQntuples(res); - collinfo = (CollInfo *) pg_malloc(ntups * sizeof(CollInfo)); + collinfo = (CollInfo *) pg_malloc(ntups * sizeof(*collinfo)); i_tableoid = PQfnumber(res, "tableoid"); i_oid = PQfnumber(res, "oid"); @@ -6534,7 +6534,7 @@ getConversions(Archive *fout) ntups = PQntuples(res); - convinfo = (ConvInfo *) pg_malloc(ntups * sizeof(ConvInfo)); + convinfo = (ConvInfo *) pg_malloc(ntups * sizeof(*convinfo)); i_tableoid = PQfnumber(res, "tableoid"); i_oid = PQfnumber(res, "oid"); @@ -6607,7 +6607,7 @@ getAccessMethods(Archive *fout) ntups = PQntuples(res); - aminfo = (AccessMethodInfo *) pg_malloc(ntups * sizeof(AccessMethodInfo)); + aminfo = (AccessMethodInfo *) pg_malloc(ntups * sizeof(*aminfo)); i_tableoid = PQfnumber(res, "tableoid"); i_oid = PQfnumber(res, "oid"); @@ -6669,7 +6669,7 @@ getOpclasses(Archive *fout) ntups = PQntuples(res); - opcinfo = (OpclassInfo *) pg_malloc(ntups * sizeof(OpclassInfo)); + opcinfo = (OpclassInfo *) pg_malloc(ntups * sizeof(*opcinfo)); i_tableoid = PQfnumber(res, "tableoid"); i_oid = PQfnumber(res, "oid"); @@ -6734,7 +6734,7 @@ getOpfamilies(Archive *fout) ntups = PQntuples(res); - opfinfo = (OpfamilyInfo *) pg_malloc(ntups * sizeof(OpfamilyInfo)); + opfinfo = (OpfamilyInfo *) pg_malloc(ntups * sizeof(*opfinfo)); i_tableoid = PQfnumber(res, "tableoid"); i_oid = PQfnumber(res, "oid"); @@ -6852,7 +6852,7 @@ getAggregates(Archive *fout) ntups = PQntuples(res); - agginfo = (AggInfo *) pg_malloc(ntups * sizeof(AggInfo)); + agginfo = (AggInfo *) pg_malloc(ntups * sizeof(*agginfo)); i_tableoid = PQfnumber(res, "tableoid"); i_oid = PQfnumber(res, "oid"); @@ -6885,7 +6885,7 @@ getAggregates(Archive *fout) agginfo[i].aggfn.argtypes = NULL; else { - agginfo[i].aggfn.argtypes = (Oid *) pg_malloc(agginfo[i].aggfn.nargs * sizeof(Oid)); + agginfo[i].aggfn.argtypes = (Oid *) pg_malloc(agginfo[i].aggfn.nargs * sizeof(*agginfo[i].aggfn.argtypes)); parseOidArray(PQgetvalue(res, i, i_proargtypes), agginfo[i].aggfn.argtypes, agginfo[i].aggfn.nargs); @@ -7043,7 +7043,7 @@ getFuncs(Archive *fout) ntups = PQntuples(res); - finfo = (FuncInfo *) pg_malloc0(ntups * sizeof(FuncInfo)); + finfo = (FuncInfo *) pg_malloc0(ntups * sizeof(*finfo)); i_tableoid = PQfnumber(res, "tableoid"); i_oid = PQfnumber(res, "oid"); @@ -7078,7 +7078,7 @@ getFuncs(Archive *fout) finfo[i].argtypes = NULL; else { - finfo[i].argtypes = (Oid *) pg_malloc(finfo[i].nargs * sizeof(Oid)); + finfo[i].argtypes = (Oid *) pg_malloc(finfo[i].nargs * sizeof(*finfo[i].argtypes)); parseOidArray(PQgetvalue(res, i, i_proargtypes), finfo[i].argtypes, finfo[i].nargs); } @@ -7120,14 +7120,14 @@ getRelationStatistics(Archive *fout, DumpableObject *rel, int32 relpages, (relkind == RELKIND_MATVIEW || relkind == RELKIND_FOREIGN_TABLE)) { - RelStatsInfo *info = pg_malloc0(sizeof(RelStatsInfo)); + RelStatsInfo *info = pg_malloc0(sizeof(*info)); DumpableObject *dobj = &info->dobj; dobj->objType = DO_REL_STATS; dobj->catId.tableoid = 0; dobj->catId.oid = 0; AssignDumpId(dobj); - dobj->dependencies = (DumpId *) pg_malloc(sizeof(DumpId)); + dobj->dependencies = (DumpId *) pg_malloc(sizeof(*dobj->dependencies)); dobj->dependencies[0] = rel->dumpId; dobj->nDeps = 1; dobj->allocDeps = 1; @@ -7412,7 +7412,7 @@ getTables(Archive *fout, int *numTables) * only one, because we don't yet know which tables might be inheritance * ancestors of the target table. */ - tblinfo = (TableInfo *) pg_malloc0(ntups * sizeof(TableInfo)); + tblinfo = (TableInfo *) pg_malloc0(ntups * sizeof(*tblinfo)); i_reltableoid = PQfnumber(res, "tableoid"); i_reloid = PQfnumber(res, "oid"); @@ -7744,7 +7744,7 @@ getInherits(Archive *fout, int *numInherits) *numInherits = ntups; - inhinfo = (InhInfo *) pg_malloc(ntups * sizeof(InhInfo)); + inhinfo = (InhInfo *) pg_malloc(ntups * sizeof(*inhinfo)); i_inhrelid = PQfnumber(res, "inhrelid"); i_inhparent = PQfnumber(res, "inhparent"); @@ -8056,7 +8056,7 @@ getIndexes(Archive *fout, TableInfo tblinfo[], int numTables) i_indstatcols = PQfnumber(res, "indstatcols"); i_indstatvals = PQfnumber(res, "indstatvals"); - indxinfo = (IndxInfo *) pg_malloc(ntups * sizeof(IndxInfo)); + indxinfo = (IndxInfo *) pg_malloc(ntups * sizeof(*indxinfo)); /* * Outer loop iterates once per table, not once per row. Incrementing of @@ -8122,7 +8122,7 @@ getIndexes(Archive *fout, TableInfo tblinfo[], int numTables) indxinfo[j].indreloptions = pg_strdup(PQgetvalue(res, j, i_indreloptions)); indxinfo[j].indstatcols = pg_strdup(PQgetvalue(res, j, i_indstatcols)); indxinfo[j].indstatvals = pg_strdup(PQgetvalue(res, j, i_indstatvals)); - indxinfo[j].indkeys = (Oid *) pg_malloc(indxinfo[j].indnattrs * sizeof(Oid)); + indxinfo[j].indkeys = (Oid *) pg_malloc(indxinfo[j].indnattrs * sizeof(*indxinfo[j].indkeys)); parseOidArray(PQgetvalue(res, j, i_indkey), indxinfo[j].indkeys, indxinfo[j].indnattrs); indxinfo[j].indisclustered = (PQgetvalue(res, j, i_indisclustered)[0] == 't'); @@ -8160,7 +8160,7 @@ getIndexes(Archive *fout, TableInfo tblinfo[], int numTables) */ ConstraintInfo *constrinfo; - constrinfo = (ConstraintInfo *) pg_malloc(sizeof(ConstraintInfo)); + constrinfo = (ConstraintInfo *) pg_malloc(sizeof(*constrinfo)); constrinfo->dobj.objType = DO_CONSTRAINT; constrinfo->dobj.catId.tableoid = atooid(PQgetvalue(res, j, i_contableoid)); constrinfo->dobj.catId.oid = atooid(PQgetvalue(res, j, i_conoid)); @@ -8251,7 +8251,7 @@ getExtendedStatistics(Archive *fout) i_stxrelid = PQfnumber(res, "stxrelid"); i_stattarget = PQfnumber(res, "stxstattarget"); - statsextinfo = (StatsExtInfo *) pg_malloc(ntups * sizeof(StatsExtInfo)); + statsextinfo = (StatsExtInfo *) pg_malloc(ntups * sizeof(*statsextinfo)); for (i = 0; i < ntups; i++) { @@ -8359,7 +8359,7 @@ getConstraints(Archive *fout, TableInfo tblinfo[], int numTables) i_conindid = PQfnumber(res, "conindid"); i_condef = PQfnumber(res, "condef"); - constrinfo = (ConstraintInfo *) pg_malloc(ntups * sizeof(ConstraintInfo)); + constrinfo = (ConstraintInfo *) pg_malloc(ntups * sizeof(*constrinfo)); curtblindx = -1; for (int j = 0; j < ntups; j++) @@ -8520,7 +8520,7 @@ getDomainConstraints(Archive *fout, TypeInfo *tyinfo) i_convalidated = PQfnumber(res, "convalidated"); i_contype = PQfnumber(res, "contype"); - constrinfo = (ConstraintInfo *) pg_malloc(ntups * sizeof(ConstraintInfo)); + constrinfo = (ConstraintInfo *) pg_malloc(ntups * sizeof(*constrinfo)); tyinfo->domChecks = constrinfo; /* 'i' tracks result rows; 'j' counts CHECK constraints */ @@ -8608,7 +8608,7 @@ getRules(Archive *fout) ntups = PQntuples(res); - ruleinfo = (RuleInfo *) pg_malloc(ntups * sizeof(RuleInfo)); + ruleinfo = (RuleInfo *) pg_malloc(ntups * sizeof(*ruleinfo)); i_tableoid = PQfnumber(res, "tableoid"); i_oid = PQfnumber(res, "oid"); @@ -8814,7 +8814,7 @@ getTriggers(Archive *fout, TableInfo tblinfo[], int numTables) i_tgispartition = PQfnumber(res, "tgispartition"); i_tgdef = PQfnumber(res, "tgdef"); - tginfo = (TriggerInfo *) pg_malloc(ntups * sizeof(TriggerInfo)); + tginfo = (TriggerInfo *) pg_malloc(ntups * sizeof(*tginfo)); /* * Outer loop iterates once per table, not once per row. Incrementing of @@ -8911,7 +8911,7 @@ getEventTriggers(Archive *fout) ntups = PQntuples(res); - evtinfo = (EventTriggerInfo *) pg_malloc(ntups * sizeof(EventTriggerInfo)); + evtinfo = (EventTriggerInfo *) pg_malloc(ntups * sizeof(*evtinfo)); i_tableoid = PQfnumber(res, "tableoid"); i_oid = PQfnumber(res, "oid"); @@ -8985,7 +8985,7 @@ getProcLangs(Archive *fout) ntups = PQntuples(res); - planginfo = (ProcLangInfo *) pg_malloc(ntups * sizeof(ProcLangInfo)); + planginfo = (ProcLangInfo *) pg_malloc(ntups * sizeof(*planginfo)); i_tableoid = PQfnumber(res, "tableoid"); i_oid = PQfnumber(res, "oid"); @@ -9077,7 +9077,7 @@ getCasts(Archive *fout) ntups = PQntuples(res); - castinfo = (CastInfo *) pg_malloc(ntups * sizeof(CastInfo)); + castinfo = (CastInfo *) pg_malloc(ntups * sizeof(*castinfo)); i_tableoid = PQfnumber(res, "tableoid"); i_oid = PQfnumber(res, "oid"); @@ -9176,7 +9176,7 @@ getTransforms(Archive *fout) ntups = PQntuples(res); - transforminfo = (TransformInfo *) pg_malloc(ntups * sizeof(TransformInfo)); + transforminfo = (TransformInfo *) pg_malloc(ntups * sizeof(*transforminfo)); i_tableoid = PQfnumber(res, "tableoid"); i_oid = PQfnumber(res, "oid"); @@ -9514,27 +9514,27 @@ getTableAttrs(Archive *fout, TableInfo *tblinfo, int numTables) /* Save data for this table */ tbinfo->numatts = numatts; - tbinfo->attnames = (char **) pg_malloc(numatts * sizeof(char *)); - tbinfo->atttypnames = (char **) pg_malloc(numatts * sizeof(char *)); - tbinfo->attstattarget = (int *) pg_malloc(numatts * sizeof(int)); - tbinfo->attstorage = (char *) pg_malloc(numatts * sizeof(char)); - tbinfo->typstorage = (char *) pg_malloc(numatts * sizeof(char)); - tbinfo->attidentity = (char *) pg_malloc(numatts * sizeof(char)); - tbinfo->attgenerated = (char *) pg_malloc(numatts * sizeof(char)); - tbinfo->attisdropped = (bool *) pg_malloc(numatts * sizeof(bool)); - tbinfo->attlen = (int *) pg_malloc(numatts * sizeof(int)); - tbinfo->attalign = (char *) pg_malloc(numatts * sizeof(char)); - tbinfo->attislocal = (bool *) pg_malloc(numatts * sizeof(bool)); - tbinfo->attoptions = (char **) pg_malloc(numatts * sizeof(char *)); - tbinfo->attcollation = (Oid *) pg_malloc(numatts * sizeof(Oid)); - tbinfo->attcompression = (char *) pg_malloc(numatts * sizeof(char)); - tbinfo->attfdwoptions = (char **) pg_malloc(numatts * sizeof(char *)); - tbinfo->attmissingval = (char **) pg_malloc(numatts * sizeof(char *)); - tbinfo->notnull_constrs = (char **) pg_malloc(numatts * sizeof(char *)); - tbinfo->notnull_comment = (char **) pg_malloc(numatts * sizeof(char *)); - tbinfo->notnull_invalid = (bool *) pg_malloc(numatts * sizeof(bool)); - tbinfo->notnull_noinh = (bool *) pg_malloc(numatts * sizeof(bool)); - tbinfo->notnull_islocal = (bool *) pg_malloc(numatts * sizeof(bool)); + tbinfo->attnames = (char **) pg_malloc(numatts * sizeof(*tbinfo->attnames)); + tbinfo->atttypnames = (char **) pg_malloc(numatts * sizeof(*tbinfo->atttypnames)); + tbinfo->attstattarget = (int *) pg_malloc(numatts * sizeof(*tbinfo->attstattarget)); + tbinfo->attstorage = (char *) pg_malloc(numatts * sizeof(*tbinfo->attstorage)); + tbinfo->typstorage = (char *) pg_malloc(numatts * sizeof(*tbinfo->typstorage)); + tbinfo->attidentity = (char *) pg_malloc(numatts * sizeof(*tbinfo->attidentity)); + tbinfo->attgenerated = (char *) pg_malloc(numatts * sizeof(*tbinfo->attgenerated)); + tbinfo->attisdropped = (bool *) pg_malloc(numatts * sizeof(*tbinfo->attisdropped)); + tbinfo->attlen = (int *) pg_malloc(numatts * sizeof(*tbinfo->attlen)); + tbinfo->attalign = (char *) pg_malloc(numatts * sizeof(*tbinfo->attalign)); + tbinfo->attislocal = (bool *) pg_malloc(numatts * sizeof(*tbinfo->attislocal)); + tbinfo->attoptions = (char **) pg_malloc(numatts * sizeof(*tbinfo->attoptions)); + tbinfo->attcollation = (Oid *) pg_malloc(numatts * sizeof(*tbinfo->attcollation)); + tbinfo->attcompression = (char *) pg_malloc(numatts * sizeof(*tbinfo->attcompression)); + tbinfo->attfdwoptions = (char **) pg_malloc(numatts * sizeof(*tbinfo->attfdwoptions)); + tbinfo->attmissingval = (char **) pg_malloc(numatts * sizeof(*tbinfo->attmissingval)); + tbinfo->notnull_constrs = (char **) pg_malloc(numatts * sizeof(*tbinfo->notnull_constrs)); + tbinfo->notnull_comment = (char **) pg_malloc(numatts * sizeof(*tbinfo->notnull_comment)); + tbinfo->notnull_invalid = (bool *) pg_malloc(numatts * sizeof(*tbinfo->notnull_invalid)); + tbinfo->notnull_noinh = (bool *) pg_malloc(numatts * sizeof(*tbinfo->notnull_noinh)); + tbinfo->notnull_islocal = (bool *) pg_malloc(numatts * sizeof(*tbinfo->notnull_islocal)); tbinfo->attrdefs = (AttrDefInfo **) pg_malloc(numatts * sizeof(AttrDefInfo *)); hasdefaults = false; @@ -9620,7 +9620,7 @@ getTableAttrs(Archive *fout, TableInfo *tblinfo, int numTables) res = ExecuteSqlQuery(fout, q->data, PGRES_TUPLES_OK); numDefaults = PQntuples(res); - attrdefs = (AttrDefInfo *) pg_malloc(numDefaults * sizeof(AttrDefInfo)); + attrdefs = (AttrDefInfo *) pg_malloc(numDefaults * sizeof(*attrdefs)); curtblindx = -1; for (int j = 0; j < numDefaults; j++) @@ -9756,7 +9756,7 @@ getTableAttrs(Archive *fout, TableInfo *tblinfo, int numTables) res = ExecuteSqlQuery(fout, q->data, PGRES_TUPLES_OK); numConstrs = PQntuples(res); - constrs = (ConstraintInfo *) pg_malloc(numConstrs * sizeof(ConstraintInfo)); + constrs = (ConstraintInfo *) pg_malloc(numConstrs * sizeof(*constrs)); i_tableoid = PQfnumber(res, "tableoid"); i_oid = PQfnumber(res, "oid"); @@ -9855,7 +9855,7 @@ getTableAttrs(Archive *fout, TableInfo *tblinfo, int numTables) res = ExecuteSqlQuery(fout, q->data, PGRES_TUPLES_OK); numConstrs = PQntuples(res); - constrs = (ConstraintInfo *) pg_malloc(numConstrs * sizeof(ConstraintInfo)); + constrs = (ConstraintInfo *) pg_malloc(numConstrs * sizeof(*constrs)); i_tableoid = PQfnumber(res, "tableoid"); i_oid = PQfnumber(res, "oid"); @@ -10183,7 +10183,7 @@ getTSParsers(Archive *fout) ntups = PQntuples(res); - prsinfo = (TSParserInfo *) pg_malloc(ntups * sizeof(TSParserInfo)); + prsinfo = (TSParserInfo *) pg_malloc(ntups * sizeof(*prsinfo)); i_tableoid = PQfnumber(res, "tableoid"); i_oid = PQfnumber(res, "oid"); @@ -10250,7 +10250,7 @@ getTSDictionaries(Archive *fout) ntups = PQntuples(res); - dictinfo = (TSDictInfo *) pg_malloc(ntups * sizeof(TSDictInfo)); + dictinfo = (TSDictInfo *) pg_malloc(ntups * sizeof(*dictinfo)); i_tableoid = PQfnumber(res, "tableoid"); i_oid = PQfnumber(res, "oid"); @@ -10314,7 +10314,7 @@ getTSTemplates(Archive *fout) ntups = PQntuples(res); - tmplinfo = (TSTemplateInfo *) pg_malloc(ntups * sizeof(TSTemplateInfo)); + tmplinfo = (TSTemplateInfo *) pg_malloc(ntups * sizeof(*tmplinfo)); i_tableoid = PQfnumber(res, "tableoid"); i_oid = PQfnumber(res, "oid"); @@ -10373,7 +10373,7 @@ getTSConfigurations(Archive *fout) ntups = PQntuples(res); - cfginfo = (TSConfigInfo *) pg_malloc(ntups * sizeof(TSConfigInfo)); + cfginfo = (TSConfigInfo *) pg_malloc(ntups * sizeof(*cfginfo)); i_tableoid = PQfnumber(res, "tableoid"); i_oid = PQfnumber(res, "oid"); @@ -10445,7 +10445,7 @@ getForeignDataWrappers(Archive *fout) ntups = PQntuples(res); - fdwinfo = (FdwInfo *) pg_malloc(ntups * sizeof(FdwInfo)); + fdwinfo = (FdwInfo *) pg_malloc(ntups * sizeof(*fdwinfo)); i_tableoid = PQfnumber(res, "tableoid"); i_oid = PQfnumber(res, "oid"); @@ -10528,7 +10528,7 @@ getForeignServers(Archive *fout) ntups = PQntuples(res); - srvinfo = (ForeignServerInfo *) pg_malloc(ntups * sizeof(ForeignServerInfo)); + srvinfo = (ForeignServerInfo *) pg_malloc(ntups * sizeof(*srvinfo)); i_tableoid = PQfnumber(res, "tableoid"); i_oid = PQfnumber(res, "oid"); @@ -10626,7 +10626,7 @@ getDefaultACLs(Archive *fout) ntups = PQntuples(res); - daclinfo = (DefaultACLInfo *) pg_malloc(ntups * sizeof(DefaultACLInfo)); + daclinfo = (DefaultACLInfo *) pg_malloc(ntups * sizeof(*daclinfo)); i_oid = PQfnumber(res, "oid"); i_tableoid = PQfnumber(res, "tableoid"); @@ -10725,7 +10725,7 @@ collectRoleNames(Archive *fout) nrolenames = PQntuples(res); - rolenames = (RoleNameItem *) pg_malloc(nrolenames * sizeof(RoleNameItem)); + rolenames = (RoleNameItem *) pg_malloc(nrolenames * sizeof(*rolenames)); for (i = 0; i < nrolenames; i++) { @@ -11602,7 +11602,7 @@ collectComments(Archive *fout) ntups = PQntuples(res); - comments = (CommentItem *) pg_malloc(ntups * sizeof(CommentItem)); + comments = (CommentItem *) pg_malloc(ntups * sizeof(*comments)); ncomments = 0; dobj = NULL; @@ -13678,7 +13678,7 @@ dumpFunc(Archive *fout, const FuncInfo *finfo) if (*protrftypes) { - Oid *typeids = pg_malloc(FUNC_MAX_ARGS * sizeof(Oid)); + Oid *typeids = pg_malloc(FUNC_MAX_ARGS * sizeof(*typeids)); int i; appendPQExpBufferStr(q, " TRANSFORM "); @@ -16805,7 +16805,7 @@ collectSecLabels(Archive *fout) ntups = PQntuples(res); - seclabels = (SecLabelItem *) pg_malloc(ntups * sizeof(SecLabelItem)); + seclabels = (SecLabelItem *) pg_malloc(ntups * sizeof(*seclabels)); nseclabels = 0; dobj = NULL; @@ -18945,7 +18945,7 @@ collectSequences(Archive *fout) res = ExecuteSqlQuery(fout, query, PGRES_TUPLES_OK); nsequences = PQntuples(res); - sequences = (SequenceItem *) pg_malloc(nsequences * sizeof(SequenceItem)); + sequences = (SequenceItem *) pg_malloc(nsequences * sizeof(*sequences)); for (int i = 0; i < nsequences; i++) { @@ -19022,7 +19022,7 @@ dumpSequence(Archive *fout, const TableInfo *tbinfo) PQntuples(res)), tbinfo->dobj.name, PQntuples(res)); - seq = pg_malloc0(sizeof(SequenceItem)); + seq = pg_malloc0(sizeof(*seq)); seq->seqtype = parse_sequence_type(PQgetvalue(res, 0, 0)); seq->startv = strtoi64(PQgetvalue(res, 0, 1), NULL, 10); seq->incby = strtoi64(PQgetvalue(res, 0, 2), NULL, 10); @@ -20114,7 +20114,7 @@ createBoundaryObjects(void) { DumpableObject *dobjs; - dobjs = (DumpableObject *) pg_malloc(2 * sizeof(DumpableObject)); + dobjs = (DumpableObject *) pg_malloc(2 * sizeof(*dobjs)); dobjs[0].objType = DO_PRE_DATA_BOUNDARY; dobjs[0].catId = nilCatalogId; @@ -20288,7 +20288,7 @@ BuildArchiveDependencies(Archive *fout) continue; /* Set up work array */ allocDeps = 64; - dependencies = (DumpId *) pg_malloc(allocDeps * sizeof(DumpId)); + dependencies = (DumpId *) pg_malloc(allocDeps * sizeof(*dependencies)); nDeps = 0; /* Recursively find all dumpable dependencies */ findDumpableDependencies(AH, dobj, diff --git a/src/bin/pg_dump/pg_dump_sort.c b/src/bin/pg_dump/pg_dump_sort.c index 164c76e0864..a35e98b0ac7 100644 --- a/src/bin/pg_dump/pg_dump_sort.c +++ b/src/bin/pg_dump/pg_dump_sort.c @@ -561,7 +561,7 @@ sortDumpableObjects(DumpableObject **objs, int numObjs, preDataBoundId = preBoundaryId; postDataBoundId = postBoundaryId; - ordering = (DumpableObject **) pg_malloc(numObjs * sizeof(DumpableObject *)); + ordering = (DumpableObject **) pg_malloc(numObjs * sizeof(*ordering)); while (!TopoSort(objs, numObjs, ordering, &nOrdering)) findDependencyLoops(ordering, nOrdering, numObjs); @@ -640,8 +640,8 @@ TopoSort(DumpableObject **objs, * We also make a map showing the input-order index of the item with * dumpId j. */ - beforeConstraints = (int *) pg_malloc0((maxDumpId + 1) * sizeof(int)); - idMap = (int *) pg_malloc((maxDumpId + 1) * sizeof(int)); + beforeConstraints = (int *) pg_malloc0((maxDumpId + 1) * sizeof(*beforeConstraints)); + idMap = (int *) pg_malloc((maxDumpId + 1) * sizeof(*idMap)); for (i = 0; i < numObjs; i++) { obj = objs[i]; @@ -776,9 +776,9 @@ findDependencyLoops(DumpableObject **objs, int nObjs, int totObjs) bool fixedloop; int i; - processed = (bool *) pg_malloc0((getMaxDumpId() + 1) * sizeof(bool)); - searchFailed = (DumpId *) pg_malloc0((getMaxDumpId() + 1) * sizeof(DumpId)); - workspace = (DumpableObject **) pg_malloc(totObjs * sizeof(DumpableObject *)); + processed = (bool *) pg_malloc0((getMaxDumpId() + 1) * sizeof(*processed)); + searchFailed = (DumpId *) pg_malloc0((getMaxDumpId() + 1) * sizeof(*searchFailed)); + workspace = (DumpableObject **) pg_malloc(totObjs * sizeof(*workspace)); fixedloop = false; for (i = 0; i < nObjs; i++) diff --git a/src/bin/pg_dump/pg_dumpall.c b/src/bin/pg_dump/pg_dumpall.c index 8fa04930399..f5b76475bcb 100644 --- a/src/bin/pg_dump/pg_dumpall.c +++ b/src/bin/pg_dump/pg_dumpall.c @@ -1140,7 +1140,7 @@ dumpRoleMembership(PGconn *conn) } remaining = end - start; - done = pg_malloc0(remaining * sizeof(bool)); + done = pg_malloc0(remaining * sizeof(*done)); ht = rolename_create(remaining, NULL); /* diff --git a/src/bin/pg_rewind/datapagemap.c b/src/bin/pg_rewind/datapagemap.c index a0645afc83b..4110ab77d41 100644 --- a/src/bin/pg_rewind/datapagemap.c +++ b/src/bin/pg_rewind/datapagemap.c @@ -76,7 +76,7 @@ datapagemap_iterate(datapagemap_t *map) { datapagemap_iterator_t *iter; - iter = pg_malloc(sizeof(datapagemap_iterator_t)); + iter = pg_malloc(sizeof(*iter)); iter->map = map; iter->nextblkno = 0; diff --git a/src/bin/pg_rewind/libpq_source.c b/src/bin/pg_rewind/libpq_source.c index 575585357b7..6cc5b5467d2 100644 --- a/src/bin/pg_rewind/libpq_source.c +++ b/src/bin/pg_rewind/libpq_source.c @@ -84,7 +84,7 @@ init_libpq_source(PGconn *conn) init_libpq_conn(conn); - src = pg_malloc0(sizeof(libpq_source)); + src = pg_malloc0(sizeof(*src)); src->common.traverse_files = libpq_traverse_files; src->common.fetch_file = libpq_fetch_file; diff --git a/src/bin/pg_rewind/local_source.c b/src/bin/pg_rewind/local_source.c index 8db1a8c44aa..f84017a1831 100644 --- a/src/bin/pg_rewind/local_source.c +++ b/src/bin/pg_rewind/local_source.c @@ -39,7 +39,7 @@ init_local_source(const char *datadir) { local_source *src; - src = pg_malloc0(sizeof(local_source)); + src = pg_malloc0(sizeof(*src)); src->common.traverse_files = local_traverse_files; src->common.fetch_file = local_fetch_file; diff --git a/src/bin/pg_rewind/pg_rewind.c b/src/bin/pg_rewind/pg_rewind.c index 06c464f6ac5..d32631b4f67 100644 --- a/src/bin/pg_rewind/pg_rewind.c +++ b/src/bin/pg_rewind/pg_rewind.c @@ -874,7 +874,7 @@ getTimelineHistory(TimeLineID tli, bool is_source, int *nentries) */ if (tli == 1) { - history = (TimeLineHistoryEntry *) pg_malloc(sizeof(TimeLineHistoryEntry)); + history = (TimeLineHistoryEntry *) pg_malloc(sizeof(*history)); history->tli = tli; history->begin = history->end = InvalidXLogRecPtr; *nentries = 1; diff --git a/src/bin/pg_rewind/timeline.c b/src/bin/pg_rewind/timeline.c index 6784969951f..804d882819f 100644 --- a/src/bin/pg_rewind/timeline.c +++ b/src/bin/pg_rewind/timeline.c @@ -117,7 +117,7 @@ rewind_parseTimeLineHistory(char *buffer, TimeLineID targetTLI, int *nentries) if (entries) entries = pg_realloc(entries, nlines * sizeof(TimeLineHistoryEntry)); else - entries = pg_malloc(1 * sizeof(TimeLineHistoryEntry)); + entries = pg_malloc(1 * sizeof(*entries)); entry = &entries[nlines - 1]; entry->tli = targetTLI; diff --git a/src/bin/pg_upgrade/check.c b/src/bin/pg_upgrade/check.c index 1e17d64b3ec..2cb1d1b69f4 100644 --- a/src/bin/pg_upgrade/check.c +++ b/src/bin/pg_upgrade/check.c @@ -481,8 +481,8 @@ check_for_data_types_usage(ClusterInfo *cluster) } /* Allocate memory for queries and for task states */ - queries = pg_malloc0(sizeof(char *) * n_data_types_usage_checks); - states = pg_malloc0(sizeof(struct data_type_check_state) * n_data_types_usage_checks); + queries = pg_malloc0(sizeof(*queries) * n_data_types_usage_checks); + states = pg_malloc0(sizeof(*states) * n_data_types_usage_checks); for (int i = 0; i < n_data_types_usage_checks; i++) { diff --git a/src/bin/pg_upgrade/function.c b/src/bin/pg_upgrade/function.c index 9ad53caeebc..2e31bf4539f 100644 --- a/src/bin/pg_upgrade/function.c +++ b/src/bin/pg_upgrade/function.c @@ -85,7 +85,7 @@ get_loadable_libraries(void) struct loadable_libraries_state state; char *query; - state.ress = (PGresult **) pg_malloc(old_cluster.dbarr.ndbs * sizeof(PGresult *)); + state.ress = (PGresult **) pg_malloc(old_cluster.dbarr.ndbs * sizeof(*state.ress)); state.totaltups = 0; query = psprintf("SELECT DISTINCT probin " @@ -107,7 +107,7 @@ get_loadable_libraries(void) * plugins. */ n_libinfos = state.totaltups + count_old_cluster_logical_slots(); - os_info.libraries = (LibraryInfo *) pg_malloc(sizeof(LibraryInfo) * n_libinfos); + os_info.libraries = (LibraryInfo *) pg_malloc(sizeof(*os_info.libraries) * n_libinfos); totaltups = 0; for (dbnum = 0; dbnum < old_cluster.dbarr.ndbs; dbnum++) diff --git a/src/bin/pg_upgrade/info.c b/src/bin/pg_upgrade/info.c index 7ce08270168..db9a40931e7 100644 --- a/src/bin/pg_upgrade/info.c +++ b/src/bin/pg_upgrade/info.c @@ -53,7 +53,7 @@ gen_db_file_maps(DbInfo *old_db, DbInfo *new_db, bool all_matched = true; /* There will certainly not be more mappings than there are old rels */ - maps = (FileNameMap *) pg_malloc(sizeof(FileNameMap) * + maps = (FileNameMap *) pg_malloc(sizeof(*maps) * old_db->rel_arr.nrels); /* @@ -370,7 +370,7 @@ get_template0_info(ClusterInfo *cluster) if (PQntuples(dbres) != 1) pg_fatal("template0 not found"); - locale = pg_malloc(sizeof(DbLocaleInfo)); + locale = pg_malloc(sizeof(*locale)); i_datencoding = PQfnumber(dbres, "encoding"); i_datlocprovider = PQfnumber(dbres, "datlocprovider"); @@ -439,7 +439,7 @@ get_db_infos(ClusterInfo *cluster) i_spclocation = PQfnumber(res, "spclocation"); ntups = PQntuples(res); - dbinfos = (DbInfo *) pg_malloc0(sizeof(DbInfo) * ntups); + dbinfos = (DbInfo *) pg_malloc0(sizeof(*dbinfos) * ntups); for (tupnum = 0; tupnum < ntups; tupnum++) { @@ -585,7 +585,7 @@ static void process_rel_infos(DbInfo *dbinfo, PGresult *res, void *arg) { int ntups = PQntuples(res); - RelInfo *relinfos = (RelInfo *) pg_malloc(sizeof(RelInfo) * ntups); + RelInfo *relinfos = (RelInfo *) pg_malloc(sizeof(*relinfos) * ntups); int i_reloid = PQfnumber(res, "reloid"); int i_indtable = PQfnumber(res, "indtable"); int i_toastheap = PQfnumber(res, "toastheap"); @@ -739,7 +739,7 @@ process_old_cluster_logical_slot_infos(DbInfo *dbinfo, PGresult *res, void *arg) int i_caught_up; int i_invalid; - slotinfos = (LogicalSlotInfo *) pg_malloc(sizeof(LogicalSlotInfo) * num_slots); + slotinfos = (LogicalSlotInfo *) pg_malloc(sizeof(*slotinfos) * num_slots); i_slotname = PQfnumber(res, "slot_name"); i_plugin = PQfnumber(res, "plugin"); diff --git a/src/bin/pg_upgrade/parallel.c b/src/bin/pg_upgrade/parallel.c index 6d7941844a7..d5ff58ad323 100644 --- a/src/bin/pg_upgrade/parallel.c +++ b/src/bin/pg_upgrade/parallel.c @@ -85,13 +85,13 @@ parallel_exec_prog(const char *log_file, const char *opt_log_file, /* parallel */ #ifdef WIN32 if (thread_handles == NULL) - thread_handles = pg_malloc(user_opts.jobs * sizeof(HANDLE)); + thread_handles = pg_malloc(user_opts.jobs * sizeof(*thread_handles)); if (exec_thread_args == NULL) { int i; - exec_thread_args = pg_malloc(user_opts.jobs * sizeof(exec_thread_arg *)); + exec_thread_args = pg_malloc(user_opts.jobs * sizeof(*exec_thread_args)); /* * For safety and performance, we keep the args allocated during @@ -99,7 +99,7 @@ parallel_exec_prog(const char *log_file, const char *opt_log_file, * thread different from the one that allocated it. */ for (i = 0; i < user_opts.jobs; i++) - exec_thread_args[i] = pg_malloc0(sizeof(exec_thread_arg)); + exec_thread_args[i] = pg_malloc0(sizeof(*exec_thread_args[i])); } cur_thread_args = (void **) exec_thread_args; @@ -188,13 +188,13 @@ parallel_transfer_all_new_dbs(DbInfoArr *old_db_arr, DbInfoArr *new_db_arr, /* parallel */ #ifdef WIN32 if (thread_handles == NULL) - thread_handles = pg_malloc(user_opts.jobs * sizeof(HANDLE)); + thread_handles = pg_malloc(user_opts.jobs * sizeof(*thread_handles)); if (transfer_thread_args == NULL) { int i; - transfer_thread_args = pg_malloc(user_opts.jobs * sizeof(transfer_thread_arg *)); + transfer_thread_args = pg_malloc(user_opts.jobs * sizeof(*transfer_thread_args)); /* * For safety and performance, we keep the args allocated during @@ -202,7 +202,7 @@ parallel_transfer_all_new_dbs(DbInfoArr *old_db_arr, DbInfoArr *new_db_arr, * thread different from the one that allocated it. */ for (i = 0; i < user_opts.jobs; i++) - transfer_thread_args[i] = pg_malloc0(sizeof(transfer_thread_arg)); + transfer_thread_args[i] = pg_malloc0(sizeof(*transfer_thread_args[i])); } cur_thread_args = (void **) transfer_thread_args; diff --git a/src/bin/pg_upgrade/tablespace.c b/src/bin/pg_upgrade/tablespace.c index 151d74e1734..f73e04c3135 100644 --- a/src/bin/pg_upgrade/tablespace.c +++ b/src/bin/pg_upgrade/tablespace.c @@ -69,9 +69,9 @@ get_tablespace_paths(void) if (PQntuples(res) != 0) { old_cluster.tablespaces = - (char **) pg_malloc(old_cluster.num_tablespaces * sizeof(char *)); + (char **) pg_malloc(old_cluster.num_tablespaces * sizeof(*old_cluster.tablespaces)); new_cluster.tablespaces = - (char **) pg_malloc(new_cluster.num_tablespaces * sizeof(char *)); + (char **) pg_malloc(new_cluster.num_tablespaces * sizeof(*new_cluster.tablespaces)); } else { diff --git a/src/bin/pg_upgrade/task.c b/src/bin/pg_upgrade/task.c index ee0e2457152..aba82a05e39 100644 --- a/src/bin/pg_upgrade/task.c +++ b/src/bin/pg_upgrade/task.c @@ -116,7 +116,7 @@ typedef struct UpgradeTaskSlot UpgradeTask * upgrade_task_create(void) { - UpgradeTask *task = pg_malloc0(sizeof(UpgradeTask)); + UpgradeTask *task = pg_malloc0(sizeof(*task)); task->queries = createPQExpBuffer(); @@ -419,7 +419,7 @@ void upgrade_task_run(const UpgradeTask *task, const ClusterInfo *cluster) { int jobs = Max(1, user_opts.jobs); - UpgradeTaskSlot *slots = pg_malloc0(sizeof(UpgradeTaskSlot) * jobs); + UpgradeTaskSlot *slots = pg_malloc0(sizeof(*slots) * jobs); dbs_complete = 0; dbs_processing = 0; diff --git a/src/bin/pg_verifybackup/astreamer_verify.c b/src/bin/pg_verifybackup/astreamer_verify.c index e503a3ec487..4ef1f166f7c 100644 --- a/src/bin/pg_verifybackup/astreamer_verify.c +++ b/src/bin/pg_verifybackup/astreamer_verify.c @@ -79,7 +79,7 @@ astreamer_verify_content_new(astreamer *next, verifier_context *context, streamer->tblspc_oid = tblspc_oid; if (!context->skip_checksums) - streamer->checksum_ctx = pg_malloc(sizeof(pg_checksum_context)); + streamer->checksum_ctx = pg_malloc(sizeof(*streamer->checksum_ctx)); return &streamer->base; } diff --git a/src/bin/pg_verifybackup/pg_verifybackup.c b/src/bin/pg_verifybackup/pg_verifybackup.c index 1cd5fa791c0..6f4a8fcd622 100644 --- a/src/bin/pg_verifybackup/pg_verifybackup.c +++ b/src/bin/pg_verifybackup/pg_verifybackup.c @@ -418,7 +418,7 @@ parse_manifest_file(char *manifest_path) /* Create the hash table. */ ht = manifest_files_create(initial_size, NULL); - result = pg_malloc0(sizeof(manifest_data)); + result = pg_malloc0(sizeof(*result)); result->files = ht; context.private_data = result; context.version_cb = verifybackup_version_cb; @@ -970,7 +970,7 @@ precheck_tar_backup_file(verifier_context *context, char *relpath, * Append the information to the list for complete verification at a later * stage. */ - tar = pg_malloc(sizeof(tar_file)); + tar = pg_malloc(sizeof(*tar)); tar->relpath = pstrdup(relpath); tar->tblspc_oid = tblspc_oid; tar->compress_algorithm = compress_algorithm; @@ -1007,7 +1007,7 @@ verify_tar_file(verifier_context *context, char *relpath, char *fullpath, return; } - buffer = pg_malloc(READ_CHUNK_SIZE * sizeof(char)); + buffer = pg_malloc(READ_CHUNK_SIZE * sizeof(*buffer)); /* Perform the reads */ while ((rc = read(fd, buffer, READ_CHUNK_SIZE)) > 0) @@ -1065,7 +1065,7 @@ verify_backup_checksums(verifier_context *context) progress_report(false); - buffer = pg_malloc(READ_CHUNK_SIZE * sizeof(uint8)); + buffer = pg_malloc(READ_CHUNK_SIZE * sizeof(*buffer)); manifest_files_start_iterate(manifest->files, &it); while ((m = manifest_files_iterate(manifest->files, &it)) != NULL) diff --git a/src/bin/pgbench/pgbench.c b/src/bin/pgbench/pgbench.c index 45b340d3da5..86b6e24a56a 100644 --- a/src/bin/pgbench/pgbench.c +++ b/src/bin/pgbench/pgbench.c @@ -3067,7 +3067,7 @@ allocCStatePrepared(CState *st) { Assert(st->prepared == NULL); - st->prepared = pg_malloc(sizeof(bool *) * num_scripts); + st->prepared = pg_malloc(sizeof(*st->prepared) * num_scripts); for (int i = 0; i < num_scripts; i++) { ParsedScript *script = &sql_script[i]; @@ -3075,7 +3075,7 @@ allocCStatePrepared(CState *st) for (numcmds = 0; script->commands[numcmds] != NULL; numcmds++) ; - st->prepared[i] = pg_malloc0(sizeof(bool) * numcmds); + st->prepared[i] = pg_malloc0(sizeof(*st->prepared[i]) * numcmds); } } @@ -5659,7 +5659,7 @@ create_sql_command(PQExpBuffer buf) return NULL; /* Allocate and initialize Command structure */ - my_command = (Command *) pg_malloc(sizeof(Command)); + my_command = (Command *) pg_malloc(sizeof(*my_command)); initPQExpBuffer(&my_command->lines); appendPQExpBufferStr(&my_command->lines, p); my_command->first_line = NULL; /* this is set later */ @@ -5755,7 +5755,7 @@ process_backslash_command(PsqlScanState sstate, const char *source, } /* Allocate and initialize Command structure */ - my_command = (Command *) pg_malloc0(sizeof(Command)); + my_command = (Command *) pg_malloc0(sizeof(*my_command)); my_command->type = META_COMMAND; my_command->argc = 0; initSimpleStats(&my_command->stats); @@ -6011,7 +6011,7 @@ ParseScript(const char *script, const char *desc, int weight) /* Initialize all fields of ps */ ps.desc = desc; ps.weight = weight; - ps.commands = (Command **) pg_malloc(sizeof(Command *) * alloc_num); + ps.commands = (Command **) pg_malloc(sizeof(*ps.commands) * alloc_num); initStats(&ps.stats, 0); /* Prepare to parse script */ @@ -6844,7 +6844,7 @@ main(int argc, char **argv) } } - state = (CState *) pg_malloc0(sizeof(CState)); + state = (CState *) pg_malloc0(sizeof(*state)); /* set random seed early, because it may be used while parsing scripts. */ if (!set_random_seed(getenv("PGBENCH_RANDOM_SEED"))) @@ -7412,7 +7412,7 @@ main(int argc, char **argv) PQfinish(con); /* set up thread data structures */ - threads = (TState *) pg_malloc(sizeof(TState) * nthreads); + threads = (TState *) pg_malloc(sizeof(*threads) * nthreads); nclients_dealt = 0; for (i = 0; i < nthreads; i++) diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c index 4a2976dddf0..feac14892d4 100644 --- a/src/bin/psql/command.c +++ b/src/bin/psql/command.c @@ -5665,7 +5665,7 @@ savePsetInfo(const printQueryOpt *popt) { printQueryOpt *save; - save = (printQueryOpt *) pg_malloc(sizeof(printQueryOpt)); + save = (printQueryOpt *) pg_malloc(sizeof(*save)); /* Flat-copy all the scalar fields, then duplicate sub-structures. */ memcpy(save, popt, sizeof(printQueryOpt)); diff --git a/src/bin/psql/copy.c b/src/bin/psql/copy.c index 92c955b637a..f4f945ff258 100644 --- a/src/bin/psql/copy.c +++ b/src/bin/psql/copy.c @@ -99,7 +99,7 @@ parse_slash_copy(const char *args) return NULL; } - result = pg_malloc0(sizeof(struct copy_options)); + result = pg_malloc0(sizeof(*result)); result->before_tofrom = pg_strdup(""); /* initialize for appending */ diff --git a/src/bin/psql/crosstabview.c b/src/bin/psql/crosstabview.c index 3e5cd0a96d4..2f50a9d3fdf 100644 --- a/src/bin/psql/crosstabview.c +++ b/src/bin/psql/crosstabview.c @@ -246,10 +246,10 @@ PrintResultInCrosstab(const PGresult *res) num_rows = piv_rows.count; array_columns = (pivot_field *) - pg_malloc(sizeof(pivot_field) * num_columns); + pg_malloc(sizeof(*array_columns) * num_columns); array_rows = (pivot_field *) - pg_malloc(sizeof(pivot_field) * num_rows); + pg_malloc(sizeof(*array_rows) * num_rows); avlCollectFields(&piv_columns, piv_columns.root, array_columns, 0); avlCollectFields(&piv_rows, piv_rows.root, array_rows, 0); @@ -312,7 +312,7 @@ printCrosstab(const PGresult *result, * map associating each piv_columns[].rank to its index in piv_columns. * This avoids an O(N^2) loop later. */ - horiz_map = (int *) pg_malloc(sizeof(int) * num_columns); + horiz_map = (int *) pg_malloc(sizeof(*horiz_map) * num_columns); for (i = 0; i < num_columns; i++) horiz_map[piv_columns[i].rank] = i; @@ -437,7 +437,7 @@ error: static void avlInit(avl_tree *tree) { - tree->end = (avl_node *) pg_malloc0(sizeof(avl_node)); + tree->end = (avl_node *) pg_malloc0(sizeof(*tree->end)); tree->end->children[0] = tree->end->children[1] = tree->end; tree->count = 0; tree->root = tree->end; @@ -533,7 +533,7 @@ avlInsertNode(avl_tree *tree, avl_node **node, pivot_field field) if (current == tree->end) { avl_node *new_node = (avl_node *) - pg_malloc(sizeof(avl_node)); + pg_malloc(sizeof(*new_node)); new_node->height = 1; new_node->field = field; diff --git a/src/bin/psql/describe.c b/src/bin/psql/describe.c index 36f24502842..85693e01eea 100644 --- a/src/bin/psql/describe.c +++ b/src/bin/psql/describe.c @@ -5306,7 +5306,7 @@ listSchemas(const char *pattern, bool verbose, bool showSystem) * storing "Publications:" string) + publication schema mapping * count + 1 (for storing NULL). */ - footers = (char **) pg_malloc((1 + pub_schema_tuples + 1) * sizeof(char *)); + footers = (char **) pg_malloc((1 + pub_schema_tuples + 1) * sizeof(*footers)); footers[0] = pg_strdup(_("Publications:")); /* Might be an empty set - that's ok */ diff --git a/src/bin/psql/tab-complete.in.c b/src/bin/psql/tab-complete.in.c index 20d7a65c614..b6e4e976d36 100644 --- a/src/bin/psql/tab-complete.in.c +++ b/src/bin/psql/tab-complete.in.c @@ -6295,7 +6295,7 @@ complete_from_variables(const char *text, const char *prefix, const char *suffix int i; struct _variable *ptr; - varnames = (char **) pg_malloc((maxvars + 1) * sizeof(char *)); + varnames = (char **) pg_malloc((maxvars + 1) * sizeof(*varnames)); for (ptr = pset.vars->next; ptr; ptr = ptr->next) { @@ -6873,7 +6873,7 @@ get_previous_words(int point, char **buffer, int *nwords) * This is usually much more space than we need, but it's cheaper than * doing a separate malloc() for each word. */ - previous_words = (char **) pg_malloc(point * sizeof(char *)); + previous_words = (char **) pg_malloc(point * sizeof(*previous_words)); *buffer = outptr = (char *) pg_malloc(point * 2); /* diff --git a/src/bin/scripts/reindexdb.c b/src/bin/scripts/reindexdb.c index 8ddcc5312f7..cc06b7d1d3d 100644 --- a/src/bin/scripts/reindexdb.c +++ b/src/bin/scripts/reindexdb.c @@ -322,7 +322,7 @@ reindex_one_database(ConnParams *cparams, ReindexType type, * database itself, so build a list with a single entry. */ Assert(user_list == NULL); - process_list = pg_malloc0(sizeof(SimpleStringList)); + process_list = pg_malloc0(sizeof(*process_list)); simple_string_list_append(process_list, PQdb(conn)); break; @@ -713,7 +713,7 @@ get_parallel_tables_list(PGconn *conn, ReindexType type, return NULL; } - tables = pg_malloc0(sizeof(SimpleStringList)); + tables = pg_malloc0(sizeof(*tables)); /* Build qualified identifiers for each table */ for (int i = 0; i < ntups; i++) @@ -809,7 +809,7 @@ get_parallel_tabidx_list(PGconn *conn, return; } - *table_list = pg_malloc0(sizeof(SimpleOidList)); + *table_list = pg_malloc0(sizeof(**table_list)); /* * Build two lists, one with table OIDs and the other with fully-qualified diff --git a/src/bin/scripts/vacuuming.c b/src/bin/scripts/vacuuming.c index 5d2d8a64961..b5cf00defcf 100644 --- a/src/bin/scripts/vacuuming.c +++ b/src/bin/scripts/vacuuming.c @@ -459,7 +459,7 @@ vacuum_all_databases(ConnParams *cparams, SimpleStringList **found_objs = NULL; if (vacopts->missing_stats_only) - found_objs = palloc0(numdbs * sizeof(SimpleStringList *)); + found_objs = palloc0(numdbs * sizeof(*found_objs)); /* * When analyzing all databases in stages, we analyze them all in the diff --git a/src/common/blkreftable.c b/src/common/blkreftable.c index 0e08f4e40ed..c886a8d460b 100644 --- a/src/common/blkreftable.c +++ b/src/common/blkreftable.c @@ -1069,7 +1069,7 @@ BlockRefTableEntryMarkBlockModified(BlockRefTableEntry *entry, unsigned j; /* Allocate a new chunk. */ - newchunk = palloc0(MAX_ENTRIES_PER_CHUNK * sizeof(uint16)); + newchunk = palloc0(MAX_ENTRIES_PER_CHUNK * sizeof(*newchunk)); /* Set the bit for each existing entry. */ for (j = 0; j < entry->chunk_usage[chunkno]; ++j) diff --git a/src/fe_utils/conditional.c b/src/fe_utils/conditional.c index 9e1ad687f08..1cb2b72f9ed 100644 --- a/src/fe_utils/conditional.c +++ b/src/fe_utils/conditional.c @@ -52,7 +52,7 @@ conditional_stack_destroy(ConditionalStack cstack) void conditional_stack_push(ConditionalStack cstack, ifState new_state) { - IfStackElem *p = (IfStackElem *) pg_malloc(sizeof(IfStackElem)); + IfStackElem *p = (IfStackElem *) pg_malloc(sizeof(*p)); p->if_state = new_state; p->query_len = -1; diff --git a/src/fe_utils/print.c b/src/fe_utils/print.c index 4d97ad2ddeb..8e4cca433b1 100644 --- a/src/fe_utils/print.c +++ b/src/fe_utils/print.c @@ -3305,7 +3305,7 @@ printTableAddCell(printTableContent *const content, char *cell, { if (content->cellmustfree == NULL) content->cellmustfree = - pg_malloc0((total_cells + 1) * sizeof(bool)); + pg_malloc0((total_cells + 1) * sizeof(*content->cellmustfree)); content->cellmustfree[content->cellsadded] = true; } @@ -3477,7 +3477,7 @@ count_table_lines(const printTableContent *cont, * Scan all column headers and determine their heights. Cache the values * since vertical mode repeats the headers for every record. */ - header_height = (int *) pg_malloc(cont->ncolumns * sizeof(int)); + header_height = (int *) pg_malloc(cont->ncolumns * sizeof(*header_height)); for (i = 0; i < cont->ncolumns; i++) { pg_wcssize((const unsigned char *) cont->headers[i], diff --git a/src/fe_utils/simple_list.c b/src/fe_utils/simple_list.c index 483d5455594..15103968bb9 100644 --- a/src/fe_utils/simple_list.c +++ b/src/fe_utils/simple_list.c @@ -27,7 +27,7 @@ simple_oid_list_append(SimpleOidList *list, Oid val) { SimpleOidListCell *cell; - cell = (SimpleOidListCell *) pg_malloc(sizeof(SimpleOidListCell)); + cell = (SimpleOidListCell *) pg_malloc(sizeof(*cell)); cell->next = NULL; cell->val = val; @@ -163,7 +163,7 @@ simple_ptr_list_append(SimplePtrList *list, void *ptr) { SimplePtrListCell *cell; - cell = (SimplePtrListCell *) pg_malloc(sizeof(SimplePtrListCell)); + cell = (SimplePtrListCell *) pg_malloc(sizeof(*cell)); cell->next = NULL; cell->ptr = ptr; diff --git a/src/interfaces/ecpg/ecpglib/misc.c b/src/interfaces/ecpg/ecpglib/misc.c index 1885732a652..35371bcfaab 100644 --- a/src/interfaces/ecpg/ecpglib/misc.c +++ b/src/interfaces/ecpg/ecpglib/misc.c @@ -114,7 +114,7 @@ ECPGget_sqlca(void) sqlca = pthread_getspecific(sqlca_key); if (sqlca == NULL) { - sqlca = malloc(sizeof(struct sqlca_t)); + sqlca = malloc(sizeof(*sqlca)); if (sqlca == NULL) return NULL; ecpg_init_sqlca(sqlca); diff --git a/src/interfaces/libpq/fe-auth-scram.c b/src/interfaces/libpq/fe-auth-scram.c index f6d6a5aa977..38543b306b9 100644 --- a/src/interfaces/libpq/fe-auth-scram.c +++ b/src/interfaces/libpq/fe-auth-scram.c @@ -104,7 +104,7 @@ scram_init(PGconn *conn, Assert(sasl_mechanism != NULL); - state = (fe_scram_state *) malloc(sizeof(fe_scram_state)); + state = (fe_scram_state *) malloc(sizeof(*state)); if (!state) return NULL; memset(state, 0, sizeof(fe_scram_state)); diff --git a/src/interfaces/libpq/fe-auth.c b/src/interfaces/libpq/fe-auth.c index 84a042269de..dacdd963a7c 100644 --- a/src/interfaces/libpq/fe-auth.c +++ b/src/interfaces/libpq/fe-auth.c @@ -302,7 +302,7 @@ pg_SSPI_continue(PGconn *conn, int payloadlen) if (conn->sspictx == NULL) { /* On first run, transfer retrieved context handle */ - conn->sspictx = malloc(sizeof(CtxtHandle)); + conn->sspictx = malloc(sizeof(*conn->sspictx)); if (conn->sspictx == NULL) { libpq_append_conn_error(conn, "out of memory"); diff --git a/src/interfaces/libpq/fe-connect.c b/src/interfaces/libpq/fe-connect.c index 03eeb3dcdb5..68841217710 100644 --- a/src/interfaces/libpq/fe-connect.c +++ b/src/interfaces/libpq/fe-connect.c @@ -1153,7 +1153,7 @@ parse_comma_separated_list(char **startptr, bool *more) *more = (*e == ','); len = e - s; - p = (char *) malloc(sizeof(char) * (len + 1)); + p = (char *) malloc(sizeof(*p) * (len + 1)); if (p) { memcpy(p, s, len); @@ -4979,7 +4979,7 @@ pqMakeEmptyPGconn(void) WSASetLastError(0); #endif /* WIN32 */ - conn = (PGconn *) malloc(sizeof(PGconn)); + conn = (PGconn *) malloc(sizeof(*conn)); if (conn == NULL) return conn; @@ -5023,7 +5023,7 @@ pqMakeEmptyPGconn(void) conn->outBufSize = 16 * 1024; conn->outBuffer = (char *) malloc(conn->outBufSize); conn->rowBufLen = 32; - conn->rowBuf = (PGdataValue *) malloc(conn->rowBufLen * sizeof(PGdataValue)); + conn->rowBuf = (PGdataValue *) malloc(conn->rowBufLen * sizeof(*conn->rowBuf)); initPQExpBuffer(&conn->errorMessage); initPQExpBuffer(&conn->workBuffer); diff --git a/src/interfaces/libpq/fe-exec.c b/src/interfaces/libpq/fe-exec.c index 7ab33930a39..658f5a92001 100644 --- a/src/interfaces/libpq/fe-exec.c +++ b/src/interfaces/libpq/fe-exec.c @@ -161,7 +161,7 @@ PQmakeEmptyPGresult(PGconn *conn, ExecStatusType status) { PGresult *result; - result = (PGresult *) malloc(sizeof(PGresult)); + result = (PGresult *) malloc(sizeof(*result)); if (!result) return NULL; @@ -1043,7 +1043,7 @@ pqAddTuple(PGresult *res, PGresAttValue *tup, const char **errmsgp) if (res->tuples == NULL) newTuples = (PGresAttValue **) - malloc(newSize * sizeof(PGresAttValue *)); + malloc(newSize * sizeof(*newTuples)); else newTuples = (PGresAttValue **) realloc(res->tuples, newSize * sizeof(PGresAttValue *)); @@ -1326,7 +1326,7 @@ pqAllocCmdQueueEntry(PGconn *conn) if (conn->cmd_queue_recycle == NULL) { - entry = (PGcmdQueueEntry *) malloc(sizeof(PGcmdQueueEntry)); + entry = (PGcmdQueueEntry *) malloc(sizeof(*entry)); if (entry == NULL) { libpq_append_conn_error(conn, "out of memory"); diff --git a/src/interfaces/libpq/fe-lobj.c b/src/interfaces/libpq/fe-lobj.c index 05e17bed508..303263664f1 100644 --- a/src/interfaces/libpq/fe-lobj.c +++ b/src/interfaces/libpq/fe-lobj.c @@ -864,7 +864,7 @@ lo_initialize(PGconn *conn) * Allocate the structure to hold the function OIDs. We don't store it * into the PGconn until it's successfully filled. */ - lobjfuncs = (PGlobjfuncs *) malloc(sizeof(PGlobjfuncs)); + lobjfuncs = (PGlobjfuncs *) malloc(sizeof(*lobjfuncs)); if (lobjfuncs == NULL) { libpq_append_conn_error(conn, "out of memory"); diff --git a/src/interfaces/libpq/fe-print.c b/src/interfaces/libpq/fe-print.c index fc153bee630..fc9d604ba58 100644 --- a/src/interfaces/libpq/fe-print.c +++ b/src/interfaces/libpq/fe-print.c @@ -632,7 +632,7 @@ PQdisplayTuples(const PGresult *res, /* will be somewhat time consuming for very large results */ if (fillAlign) { - fLength = (int *) malloc(nFields * sizeof(int)); + fLength = (int *) malloc(nFields * sizeof(*fLength)); if (!fLength) { fprintf(stderr, libpq_gettext("out of memory\n")); diff --git a/src/interfaces/libpq/fe-protocol3.c b/src/interfaces/libpq/fe-protocol3.c index 16f504a867d..676683126fd 100644 --- a/src/interfaces/libpq/fe-protocol3.c +++ b/src/interfaces/libpq/fe-protocol3.c @@ -1252,13 +1252,13 @@ reportErrorPosition(PQExpBuffer msg, const char *query, int loc, int encoding) return; } - qidx = (int *) malloc(slen * sizeof(int)); + qidx = (int *) malloc(slen * sizeof(*qidx)); if (qidx == NULL) { free(wquery); return; } - scridx = (int *) malloc(slen * sizeof(int)); + scridx = (int *) malloc(slen * sizeof(*scridx)); if (scridx == NULL) { free(qidx); diff --git a/src/interfaces/libpq/libpq-events.c b/src/interfaces/libpq/libpq-events.c index a96e3694f1f..e59af3917d6 100644 --- a/src/interfaces/libpq/libpq-events.c +++ b/src/interfaces/libpq/libpq-events.c @@ -61,7 +61,7 @@ PQregisterEventProc(PGconn *conn, PGEventProc proc, if (conn->events) e = (PGEvent *) realloc(conn->events, newSize * sizeof(PGEvent)); else - e = (PGEvent *) malloc(newSize * sizeof(PGEvent)); + e = (PGEvent *) malloc(newSize * sizeof(*e)); if (!e) return false; diff --git a/src/pl/plperl/plperl.c b/src/pl/plperl/plperl.c index 02eced3b2c5..67e6727f377 100644 --- a/src/pl/plperl/plperl.c +++ b/src/pl/plperl/plperl.c @@ -1788,9 +1788,9 @@ plperl_modify_tuple(HV *hvTD, TriggerData *tdata, HeapTuple otup) tupdesc = tdata->tg_relation->rd_att; natts = tupdesc->natts; - modvalues = (Datum *) palloc0(natts * sizeof(Datum)); - modnulls = (bool *) palloc0(natts * sizeof(bool)); - modrepls = (bool *) palloc0(natts * sizeof(bool)); + modvalues = (Datum *) palloc0(natts * sizeof(*modvalues)); + modnulls = (bool *) palloc0(natts * sizeof(*modnulls)); + modrepls = (bool *) palloc0(natts * sizeof(*modrepls)); hv_iterinit(hvNew); while ((he = hv_iternext(hvNew))) @@ -2805,9 +2805,9 @@ compile_plperl_function(Oid fn_oid, bool is_trigger, bool is_event_trigger) prodesc->fn_xmin = HeapTupleHeaderGetRawXmin(procTup->t_data); prodesc->fn_tid = procTup->t_self; prodesc->nargs = procStruct->pronargs; - prodesc->arg_out_func = (FmgrInfo *) palloc0(prodesc->nargs * sizeof(FmgrInfo)); - prodesc->arg_is_rowtype = (bool *) palloc0(prodesc->nargs * sizeof(bool)); - prodesc->arg_arraytype = (Oid *) palloc0(prodesc->nargs * sizeof(Oid)); + prodesc->arg_out_func = (FmgrInfo *) palloc0(prodesc->nargs * sizeof(*prodesc->arg_out_func)); + prodesc->arg_is_rowtype = (bool *) palloc0(prodesc->nargs * sizeof(*prodesc->arg_is_rowtype)); + prodesc->arg_arraytype = (Oid *) palloc0(prodesc->nargs * sizeof(*prodesc->arg_arraytype)); MemoryContextSwitchTo(oldcontext); /* Remember if function is STABLE/IMMUTABLE */ @@ -3600,9 +3600,9 @@ plperl_spi_prepare(char *query, int argc, SV **argv) snprintf(qdesc->qname, sizeof(qdesc->qname), "%p", qdesc); qdesc->plan_cxt = plan_cxt; qdesc->nargs = argc; - qdesc->argtypes = (Oid *) palloc(argc * sizeof(Oid)); - qdesc->arginfuncs = (FmgrInfo *) palloc(argc * sizeof(FmgrInfo)); - qdesc->argtypioparams = (Oid *) palloc(argc * sizeof(Oid)); + qdesc->argtypes = (Oid *) palloc(argc * sizeof(*qdesc->argtypes)); + qdesc->arginfuncs = (FmgrInfo *) palloc(argc * sizeof(*qdesc->arginfuncs)); + qdesc->argtypioparams = (Oid *) palloc(argc * sizeof(*qdesc->argtypioparams)); MemoryContextSwitchTo(oldcontext); /************************************************************ @@ -3774,7 +3774,7 @@ plperl_spi_exec_prepared(char *query, HV *attr, int argc, SV **argv) if (argc > 0) { nulls = (char *) palloc(argc); - argvalues = (Datum *) palloc(argc * sizeof(Datum)); + argvalues = (Datum *) palloc(argc * sizeof(*argvalues)); } else { @@ -3887,7 +3887,7 @@ plperl_spi_query_prepared(char *query, int argc, SV **argv) if (argc > 0) { nulls = (char *) palloc(argc); - argvalues = (Datum *) palloc(argc * sizeof(Datum)); + argvalues = (Datum *) palloc(argc * sizeof(*argvalues)); } else { diff --git a/src/pl/plpython/plpy_cursorobject.c b/src/pl/plpython/plpy_cursorobject.c index cc74c4df6ba..068d9ddb982 100644 --- a/src/pl/plpython/plpy_cursorobject.c +++ b/src/pl/plpython/plpy_cursorobject.c @@ -243,8 +243,8 @@ PLy_cursor_plan(PyObject *ob, PyObject *args) if (nargs > 0) { - values = (Datum *) palloc(nargs * sizeof(Datum)); - nulls = (char *) palloc(nargs * sizeof(char)); + values = (Datum *) palloc(nargs * sizeof(*values)); + nulls = (char *) palloc(nargs * sizeof(*nulls)); } else { diff --git a/src/pl/plpython/plpy_exec.c b/src/pl/plpython/plpy_exec.c index 0117f1e77ef..934e13243e9 100644 --- a/src/pl/plpython/plpy_exec.c +++ b/src/pl/plpython/plpy_exec.c @@ -1001,9 +1001,9 @@ PLy_modify_tuple(PLyProcedure *proc, PyObject *pltd, TriggerData *tdata, tupdesc = RelationGetDescr(tdata->tg_relation); - modvalues = (Datum *) palloc0(tupdesc->natts * sizeof(Datum)); - modnulls = (bool *) palloc0(tupdesc->natts * sizeof(bool)); - modrepls = (bool *) palloc0(tupdesc->natts * sizeof(bool)); + modvalues = (Datum *) palloc0(tupdesc->natts * sizeof(*modvalues)); + modnulls = (bool *) palloc0(tupdesc->natts * sizeof(*modnulls)); + modrepls = (bool *) palloc0(tupdesc->natts * sizeof(*modrepls)); for (i = 0; i < nkeys; i++) { diff --git a/src/pl/plpython/plpy_spi.c b/src/pl/plpython/plpy_spi.c index 46f2ca0f792..5f7b369aad5 100644 --- a/src/pl/plpython/plpy_spi.c +++ b/src/pl/plpython/plpy_spi.c @@ -233,8 +233,8 @@ PLy_spi_execute_plan(PyObject *ob, PyObject *list, long limit) if (nargs > 0) { - values = (Datum *) palloc(nargs * sizeof(Datum)); - nulls = (char *) palloc(nargs * sizeof(char)); + values = (Datum *) palloc(nargs * sizeof(*values)); + nulls = (char *) palloc(nargs * sizeof(*nulls)); } else { diff --git a/src/pl/tcl/pltcl.c b/src/pl/tcl/pltcl.c index 187698ccdd2..95f25f672fa 100644 --- a/src/pl/tcl/pltcl.c +++ b/src/pl/tcl/pltcl.c @@ -1595,8 +1595,8 @@ compile_pltcl_function(Oid fn_oid, Oid tgreloid, prodesc->fn_xmin = HeapTupleHeaderGetRawXmin(procTup->t_data); prodesc->fn_tid = procTup->t_self; prodesc->nargs = procStruct->pronargs; - prodesc->arg_out_func = (FmgrInfo *) palloc0(prodesc->nargs * sizeof(FmgrInfo)); - prodesc->arg_is_rowtype = (bool *) palloc0(prodesc->nargs * sizeof(bool)); + prodesc->arg_out_func = (FmgrInfo *) palloc0(prodesc->nargs * sizeof(*prodesc->arg_out_func)); + prodesc->arg_is_rowtype = (bool *) palloc0(prodesc->nargs * sizeof(*prodesc->arg_is_rowtype)); MemoryContextSwitchTo(oldcontext); /* Remember if function is STABLE/IMMUTABLE */ @@ -2671,9 +2671,9 @@ pltcl_SPI_prepare(ClientData cdata, Tcl_Interp *interp, qdesc = palloc0_object(pltcl_query_desc); snprintf(qdesc->qname, sizeof(qdesc->qname), "%p", qdesc); qdesc->nargs = nargs; - qdesc->argtypes = (Oid *) palloc(nargs * sizeof(Oid)); - qdesc->arginfuncs = (FmgrInfo *) palloc(nargs * sizeof(FmgrInfo)); - qdesc->argtypioparams = (Oid *) palloc(nargs * sizeof(Oid)); + qdesc->argtypes = (Oid *) palloc(nargs * sizeof(*qdesc->argtypes)); + qdesc->arginfuncs = (FmgrInfo *) palloc(nargs * sizeof(*qdesc->arginfuncs)); + qdesc->argtypioparams = (Oid *) palloc(nargs * sizeof(*qdesc->argtypioparams)); MemoryContextSwitchTo(oldcontext); /************************************************************ @@ -2916,7 +2916,7 @@ pltcl_SPI_execute_plan(ClientData cdata, Tcl_Interp *interp, * Setup the value array for SPI_execute_plan() using * the type specific input functions ************************************************************/ - argvalues = (Datum *) palloc(callObjc * sizeof(Datum)); + argvalues = (Datum *) palloc(callObjc * sizeof(*argvalues)); for (j = 0; j < callObjc; j++) { @@ -3290,7 +3290,7 @@ pltcl_build_tuple_result(Tcl_Interp *interp, Tcl_Obj **kvObjv, int kvObjc, attinmeta = NULL; } - values = (char **) palloc0(tupdesc->natts * sizeof(char *)); + values = (char **) palloc0(tupdesc->natts * sizeof(*values)); if (kvObjc % 2 != 0) ereport(ERROR, diff --git a/src/port/dirent.c b/src/port/dirent.c index a10484ea32c..9d6924e8365 100644 --- a/src/port/dirent.c +++ b/src/port/dirent.c @@ -48,7 +48,7 @@ opendir(const char *dirname) return NULL; } - d = malloc(sizeof(DIR)); + d = malloc(sizeof(*d)); if (!d) { errno = ENOMEM; diff --git a/src/timezone/localtime.c b/src/timezone/localtime.c index 20147f1a2c2..7a97bfd0d72 100644 --- a/src/timezone/localtime.c +++ b/src/timezone/localtime.c @@ -1366,7 +1366,7 @@ gmtsub(pg_time_t const *timep, int_fast32_t offset, if (gmtptr == NULL) { /* Allocate on first use */ - gmtptr = (struct state *) malloc(sizeof(struct state)); + gmtptr = (struct state *) malloc(sizeof(*gmtptr)); if (gmtptr == NULL) return NULL; /* errno should be set by malloc */ gmtload(gmtptr); -- 2.34.1 --0japS73BvShvidpF--