Avoid unecessary MemSet call (src/backend/utils/cache/relcache.c)
Hi hackers,
At function load_relcache_init_file, there is an unnecessary function call,
to initialize pgstat_info pointer to NULL.
MemSet(&rel->pgstat_info, 0, sizeof(rel->pgstat_info));
I think that intention with use of MemSet was:
MemSet(&rel->pgstat_info, 0, sizeof(*rel->pgstat_info));
Initialize with sizeof of Struct size, not with sizeof pointer size.
But so it breaks.
Attached a tiny patch.
regards,
Ranier Vilela
Attachments:
avoid_unecessary_memset_call.patchapplication/octet-stream; name=avoid_unecessary_memset_call.patchDownload
diff --git a/src/backend/utils/cache/relcache.c b/src/backend/utils/cache/relcache.c
index 60e72f9e8b..6da7a5cf7f 100644
--- a/src/backend/utils/cache/relcache.c
+++ b/src/backend/utils/cache/relcache.c
@@ -6265,7 +6265,7 @@ load_relcache_init_file(bool shared)
rel->rd_firstRelfilenodeSubid = InvalidSubTransactionId;
rel->rd_droppedSubid = InvalidSubTransactionId;
rel->rd_amcache = NULL;
- MemSet(&rel->pgstat_info, 0, sizeof(rel->pgstat_info));
+ rel->pgstat_info = NULL;On Sun, 15 May 2022 at 09:47, Ranier Vilela <ranier.vf@gmail.com> wrote:
At function load_relcache_init_file, there is an unnecessary function call,
to initialize pgstat_info pointer to NULL.MemSet(&rel->pgstat_info, 0, sizeof(rel->pgstat_info));
What seems to have happened here is the field was changed to become a
pointer in 77947c51c. It's not incorrect to use MemSet() to zero out
the pointer field. What it does probably do is confuse the casual
reader into thinking the field is a struct rather than a pointer to
one. It's probably worth making that consistent with the other
fields so nobody gets confused.
Can you add a CF entry for PG16 for this so we come back to it after we branch?
David
Em seg., 16 de mai. de 2022 às 20:26, David Rowley <dgrowleyml@gmail.com>
escreveu:
On Sun, 15 May 2022 at 09:47, Ranier Vilela <ranier.vf@gmail.com> wrote:
At function load_relcache_init_file, there is an unnecessary function
call,
to initialize pgstat_info pointer to NULL.
MemSet(&rel->pgstat_info, 0, sizeof(rel->pgstat_info));
What seems to have happened here is the field was changed to become a
pointer in 77947c51c. It's not incorrect to use MemSet() to zero out
the pointer field. What it does probably do is confuse the casual
reader into thinking the field is a struct rather than a pointer to
one. It's probably worth making that consistent with the other
fields so nobody gets confused.Can you add a CF entry for PG16 for this so we come back to it after we
branch?
Of course.
I will add it.
regards,
Ranier Vilela
Em ter., 17 de mai. de 2022 às 10:33, Ranier Vilela <ranier.vf@gmail.com>
escreveu:
Em seg., 16 de mai. de 2022 às 20:26, David Rowley <dgrowleyml@gmail.com>
escreveu:On Sun, 15 May 2022 at 09:47, Ranier Vilela <ranier.vf@gmail.com> wrote:
At function load_relcache_init_file, there is an unnecessary function
call,
to initialize pgstat_info pointer to NULL.
MemSet(&rel->pgstat_info, 0, sizeof(rel->pgstat_info));
What seems to have happened here is the field was changed to become a
pointer in 77947c51c. It's not incorrect to use MemSet() to zero out
the pointer field. What it does probably do is confuse the casual
reader into thinking the field is a struct rather than a pointer to
one. It's probably worth making that consistent with the other
fields so nobody gets confused.Can you add a CF entry for PG16 for this so we come back to it after we
branch?Of course.
I will add it.
Created https://commitfest.postgresql.org/38/3640/
However, I would like to add more.
I found, I believe, a serious problem of incorrect usage of the memset api.
Historically, people have relied on using memset or MemSet, using the
variable name as an argument for the sizeof.
While it works correctly, for arrays, when it comes to pointers to
structures, things go awry.
#include <stdio.h>
struct test_t
{
double b;
int a;
char c;
};
typedef struct test_t Test;
int main()
{
Test * my_test;
printf("Sizeof pointer=%u\n", sizeof(my_test));
printf("Sizeof struct=%u\n", sizeof(Test));
}
Output:
Sizeof pointer=8
Sizeof struct=16
So throughout the code there are these misuses.
So, taking advantage of this CF I'm going to add one more big patch, with
suggestions to fix the calls.
This pass vcregress check.
regards,
Ranier Vilela
Attachments:
001-avoid_unecessary_memset_call.patchapplication/octet-stream; name=001-avoid_unecessary_memset_call.patchDownload
diff --git a/src/backend/utils/cache/relcache.c b/src/backend/utils/cache/relcache.c
index 60e72f9e8b..6da7a5cf7f 100644
--- a/src/backend/utils/cache/relcache.c
+++ b/src/backend/utils/cache/relcache.c
@@ -6265,7 +6265,7 @@ load_relcache_init_file(bool shared)
rel->rd_firstRelfilenodeSubid = InvalidSubTransactionId;
rel->rd_droppedSubid = InvalidSubTransactionId;
rel->rd_amcache = NULL;
- MemSet(&rel->pgstat_info, 0, sizeof(rel->pgstat_info));
+ rel->pgstat_info = NULL;002-fix_api_memset_usage.patchapplication/octet-stream; name=002-fix_api_memset_usage.patchDownload
diff --git a/contrib/bloom/blcost.c b/contrib/bloom/blcost.c
index d42e4e9628..b35e96ea20 100644
--- a/contrib/bloom/blcost.c
+++ b/contrib/bloom/blcost.c
@@ -28,7 +28,7 @@ blcostestimate(PlannerInfo *root, IndexPath *path, double loop_count,
IndexOptInfo *index = path->indexinfo;
GenericCosts costs;
- MemSet(&costs, 0, sizeof(costs));
+ MemSet(&costs, 0, sizeof(GenericCosts));
/* We have to visit all index tuples anyway */
costs.numIndexTuples = index->tuples;
diff --git a/contrib/bloom/blinsert.c b/contrib/bloom/blinsert.c
index 82378db441..b80c47cd65 100644
--- a/contrib/bloom/blinsert.c
+++ b/contrib/bloom/blinsert.c
@@ -132,7 +132,7 @@ blbuild(Relation heap, Relation index, IndexInfo *indexInfo)
BloomInitMetapage(index);
/* Initialize the bloom build state */
- memset(&buildstate, 0, sizeof(buildstate));
+ memset(&buildstate, 0, sizeof(BloomBuildState));
initBloomState(&buildstate.blstate, index);
buildstate.tmpCtx = AllocSetContextCreate(CurrentMemoryContext,
"Bloom build temporary context",
diff --git a/contrib/intarray/_int_selfuncs.c b/contrib/intarray/_int_selfuncs.c
index 3d8ff6781b..4ec42e9edf 100644
--- a/contrib/intarray/_int_selfuncs.c
+++ b/contrib/intarray/_int_selfuncs.c
@@ -221,7 +221,7 @@ _int_matchsel(PG_FUNCTION_ARGS)
}
}
else
- memset(&sslot, 0, sizeof(sslot));
+ memset(&sslot, 0, sizeof(AttStatsSlot));
/* Process the logical expression in the query, using the stats */
selec = int_query_opr_selec(GETQUERY(query) + query->size - 1,
diff --git a/contrib/pg_trgm/trgm_regexp.c b/contrib/pg_trgm/trgm_regexp.c
index 58d32ba946..adabb3d8cd 100644
--- a/contrib/pg_trgm/trgm_regexp.c
+++ b/contrib/pg_trgm/trgm_regexp.c
@@ -926,7 +926,7 @@ transformGraph(TrgmNFA *trgmNFA)
trgmNFA->nstates = 0;
/* Create initial state: ambiguous prefix, NFA's initial state */
- MemSet(&initkey, 0, sizeof(initkey));
+ MemSet(&initkey, 0, sizeof(TrgmStateKey));
initkey.prefix.colors[0] = COLOR_UNKNOWN;
initkey.prefix.colors[1] = COLOR_UNKNOWN;
initkey.nstate = pg_reg_getinitialstate(trgmNFA->regex);
@@ -1028,7 +1028,7 @@ addKey(TrgmNFA *trgmNFA, TrgmState *state, TrgmStateKey *key)
* Ensure any pad bytes in destKey are zero, since it may get used as a
* hashtable key by getState.
*/
- MemSet(&destKey, 0, sizeof(destKey));
+ MemSet(&destKey, 0, sizeof(TrgmStateKey));
/*
* Compare key to each existing enter key of the state to check for
@@ -1209,7 +1209,7 @@ addArcs(TrgmNFA *trgmNFA, TrgmState *state)
* Ensure any pad bytes in destKey are zero, since it may get used as a
* hashtable key by getState.
*/
- MemSet(&destKey, 0, sizeof(destKey));
+ MemSet(&destKey, 0, sizeof(TrgmStateKey));
/*
* Iterate over enter keys associated with this expanded-graph state. This
diff --git a/contrib/pgcrypto/crypt-blowfish.c b/contrib/pgcrypto/crypt-blowfish.c
index a663852ccf..63fcef562d 100644
--- a/contrib/pgcrypto/crypt-blowfish.c
+++ b/contrib/pgcrypto/crypt-blowfish.c
@@ -750,7 +750,7 @@ _crypt_blowfish_rn(const char *key, const char *setting,
/* Overwrite the most obvious sensitive data we have on the stack. Note
* that this does not guarantee there's no sensitive data left on the
* stack and/or in registers; I'm not aware of portable code that does. */
- px_memset(&data, 0, sizeof(data));
+ px_memset(&data, 0, sizeof(struct data));
return output;
}
diff --git a/contrib/pgstattuple/pgstatindex.c b/contrib/pgstattuple/pgstatindex.c
index e1048e47ff..87be62f023 100644
--- a/contrib/pgstattuple/pgstatindex.c
+++ b/contrib/pgstattuple/pgstatindex.c
@@ -601,7 +601,7 @@ pgstathashindex(PG_FUNCTION_ARGS)
errmsg("cannot access temporary indexes of other sessions")));
/* Get the information we need from the metapage. */
- memset(&stats, 0, sizeof(stats));
+ memset(&stats, 0, sizeof(HashIndexStat));
metabuf = _hash_getbuf(rel, HASH_METAPAGE, HASH_READ, LH_META_PAGE);
metap = HashPageGetMeta(BufferGetPage(metabuf));
stats.version = metap->hashm_version;
diff --git a/contrib/postgres_fdw/connection.c b/contrib/postgres_fdw/connection.c
index 061ffaf329..20a8162268 100644
--- a/contrib/postgres_fdw/connection.c
+++ b/contrib/postgres_fdw/connection.c
@@ -311,7 +311,7 @@ make_new_connection(ConnCacheEntry *entry, UserMapping *user)
entry->mapping_hashvalue =
GetSysCacheHashValue1(USERMAPPINGOID,
ObjectIdGetDatum(user->umid));
- memset(&entry->state, 0, sizeof(entry->state));
+ memset(&entry->state, 0, sizeof(PgFdwConnState));
/*
* Determine whether to keep the connection that we're about to make here
@@ -1533,7 +1533,7 @@ pgfdw_abort_cleanup(ConnCacheEntry *entry, bool toplevel)
* fetch_more_data(); in that case reset the per-connection state here.
*/
if (entry->state.pendingAreq)
- memset(&entry->state, 0, sizeof(entry->state));
+ memset(&entry->state, 0, sizeof(PgFdwConnState));
/* Disarm changing_xact_state if it all worked */
entry->changing_xact_state = false;
diff --git a/contrib/sepgsql/hooks.c b/contrib/sepgsql/hooks.c
index 97e61b8043..2882ddb377 100644
--- a/contrib/sepgsql/hooks.c
+++ b/contrib/sepgsql/hooks.c
@@ -480,5 +480,5 @@ _PG_init(void)
ProcessUtility_hook = sepgsql_utility_command;
/* init contextual info */
- memset(&sepgsql_context_info, 0, sizeof(sepgsql_context_info));
+ memset(&sepgsql_context_info, 0, sizeof(sepgsql_context_info_t));
}
diff --git a/src/backend/access/common/scankey.c b/src/backend/access/common/scankey.c
index ff2b608f2e..e761f17dd2 100644
--- a/src/backend/access/common/scankey.c
+++ b/src/backend/access/common/scankey.c
@@ -51,7 +51,7 @@ ScanKeyEntryInitialize(ScanKey entry,
else
{
Assert(flags & (SK_SEARCHNULL | SK_SEARCHNOTNULL));
- MemSet(&entry->sk_func, 0, sizeof(entry->sk_func));
+ MemSet(&entry->sk_func, 0, sizeof(FmgrInfo));
}
}
diff --git a/src/backend/access/gin/ginfast.c b/src/backend/access/gin/ginfast.c
index 7409fdc165..8119baaacb 100644
--- a/src/backend/access/gin/ginfast.c
+++ b/src/backend/access/gin/ginfast.c
@@ -1058,7 +1058,7 @@ gin_clean_pending_list(PG_FUNCTION_ARGS)
aclcheck_error(ACLCHECK_NOT_OWNER, OBJECT_INDEX,
RelationGetRelationName(indexRel));
- memset(&stats, 0, sizeof(stats));
+ memset(&stats, 0, sizeof(IndexBulkDeleteResult));
initGinState(&ginstate, indexRel);
ginInsertCleanup(&ginstate, true, true, true, &stats);
diff --git a/src/backend/access/gin/ginvacuum.c b/src/backend/access/gin/ginvacuum.c
index b4fa5f6bf8..451fe28ff1 100644
--- a/src/backend/access/gin/ginvacuum.c
+++ b/src/backend/access/gin/ginvacuum.c
@@ -721,7 +721,7 @@ ginvacuumcleanup(IndexVacuumInfo *info, IndexBulkDeleteResult *stats)
false, true, stats);
}
- memset(&idxStat, 0, sizeof(idxStat));
+ memset(&idxStat, 0, sizeof(GinStatsData));
/*
* XXX we always report the heap tuple count as the number of index
diff --git a/src/backend/access/heap/rewriteheap.c b/src/backend/access/heap/rewriteheap.c
index 2a53826736..01989d79a2 100644
--- a/src/backend/access/heap/rewriteheap.c
+++ b/src/backend/access/heap/rewriteheap.c
@@ -411,7 +411,7 @@ rewrite_heap_tuple(RewriteState state,
{
OldToNewMapping mapping;
- memset(&hashkey, 0, sizeof(hashkey));
+ memset(&hashkey, 0, sizeof(TidHashKey));
hashkey.xmin = HeapTupleHeaderGetUpdateXid(old_tuple->t_data);
hashkey.tid = old_tuple->t_data->t_ctid;
@@ -493,7 +493,7 @@ rewrite_heap_tuple(RewriteState state,
*/
UnresolvedTup unresolved;
- memset(&hashkey, 0, sizeof(hashkey));
+ memset(&hashkey, 0, sizeof(TidHashKey));
hashkey.xmin = HeapTupleHeaderGetXmin(new_tuple->t_data);
hashkey.tid = old_tid;
@@ -581,7 +581,7 @@ rewrite_heap_dead_tuple(RewriteState state, HeapTuple old_tuple)
TidHashKey hashkey;
bool found;
- memset(&hashkey, 0, sizeof(hashkey));
+ memset(&hashkey, 0, sizeof(TidHashKey));
hashkey.xmin = HeapTupleHeaderGetXmin(old_tuple->t_data);
hashkey.tid = old_tuple->t_self;
diff --git a/src/backend/access/spgist/spgdoinsert.c b/src/backend/access/spgist/spgdoinsert.c
index e84b5edc03..6194a92542 100644
--- a/src/backend/access/spgist/spgdoinsert.c
+++ b/src/backend/access/spgist/spgdoinsert.c
@@ -818,7 +818,7 @@ doPickSplit(Relation index, SpGistState *state,
oldLeafs[in.nTuples] = newLeafTuple;
in.nTuples++;
- memset(&out, 0, sizeof(out));
+ memset(&out, 0, sizeof(spgPickSplitOut));
if (!isNulls)
{
@@ -2185,7 +2185,7 @@ spgdoinsert(Relation index, SpGistState *state,
in.nNodes = innerTuple->nNodes;
in.nodeLabels = spgExtractNodeLabels(state, innerTuple);
- memset(&out, 0, sizeof(out));
+ memset(&out, 0, sizeof(spgChooseOut));
if (!isnull)
{
diff --git a/src/backend/access/spgist/spgscan.c b/src/backend/access/spgist/spgscan.c
index 87a345d290..888722f9e3 100644
--- a/src/backend/access/spgist/spgscan.c
+++ b/src/backend/access/spgist/spgscan.c
@@ -672,7 +672,7 @@ spgInnerTest(SpGistScanOpaque so, SpGistSearchItem *item,
int nNodes = innerTuple->nNodes;
int i;
- memset(&out, 0, sizeof(out));
+ memset(&out, 0, sizeof(spgInnerConsistentOut));
if (!isnull)
{
diff --git a/src/backend/access/spgist/spgvalidate.c b/src/backend/access/spgist/spgvalidate.c
index 82281f7b83..5167f60454 100644
--- a/src/backend/access/spgist/spgvalidate.c
+++ b/src/backend/access/spgist/spgvalidate.c
@@ -112,7 +112,7 @@ spgvalidate(Oid opclassoid)
ok = check_amproc_signature(procform->amproc, VOIDOID, true,
2, 2, INTERNALOID, INTERNALOID);
configIn.attType = procform->amproclefttype;
- memset(&configOut, 0, sizeof(configOut));
+ memset(&configOut, 0, sizeof(spgConfigOut));
OidFunctionCall2(procform->amproc,
PointerGetDatum(&configIn),
diff --git a/src/backend/access/transam/parallel.c b/src/backend/access/transam/parallel.c
index df0cd77558..3575a17ed2 100644
--- a/src/backend/access/transam/parallel.c
+++ b/src/backend/access/transam/parallel.c
@@ -557,7 +557,7 @@ LaunchParallelWorkers(ParallelContext *pcxt)
oldcontext = MemoryContextSwitchTo(TopTransactionContext);
/* Configure a worker. */
- memset(&worker, 0, sizeof(worker));
+ memset(&worker, 0, sizeof(BackgroundWorker));
snprintf(worker.bgw_name, BGW_MAXLEN, "parallel worker for PID %d",
MyProcPid);
snprintf(worker.bgw_type, BGW_MAXLEN, "parallel worker");
diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c
index 71136b11a2..afb918f13b 100644
--- a/src/backend/access/transam/xlog.c
+++ b/src/backend/access/transam/xlog.c
@@ -6302,7 +6302,7 @@ CreateCheckPoint(int flags)
* checkpoint proceeds, we always accumulate stats, even if
* log_checkpoints is currently off.
*/
- MemSet(&CheckpointStats, 0, sizeof(CheckpointStats));
+ MemSet(&CheckpointStats, 0, sizeof(CheckpointStatsData));
CheckpointStats.ckpt_start_t = GetCurrentTimestamp();
/*
@@ -6327,7 +6327,7 @@ CreateCheckPoint(int flags)
}
/* Begin filling in the checkpoint WAL record */
- MemSet(&checkPoint, 0, sizeof(checkPoint));
+ MemSet(&checkPoint, 0, sizeof(CheckPoint));
checkPoint.time = (pg_time_t) time(NULL);
/*
@@ -6999,7 +6999,7 @@ CreateRestartPoint(int flags)
* checkpoint proceeds, we always accumulate stats, even if
* log_checkpoints is currently off.
*/
- MemSet(&CheckpointStats, 0, sizeof(CheckpointStats));
+ MemSet(&CheckpointStats, 0, sizeof(CheckpointStatsData));
CheckpointStats.ckpt_start_t = GetCurrentTimestamp();
if (log_checkpoints)
diff --git a/src/backend/catalog/dependency.c b/src/backend/catalog/dependency.c
index de10923391..219dc21b28 100644
--- a/src/backend/catalog/dependency.c
+++ b/src/backend/catalog/dependency.c
@@ -572,8 +572,8 @@ findDependentObjects(const ObjectAddress *object,
NULL, nkeys, key);
/* initialize variables that loop may fill */
- memset(&owningObject, 0, sizeof(owningObject));
- memset(&partitionObject, 0, sizeof(partitionObject));
+ memset(&owningObject, 0, sizeof(ObjectAddress));
+ memset(&partitionObject, 0, sizeof(ObjectAddress));
while (HeapTupleIsValid(tup = systable_getnext(scan)))
{
@@ -997,7 +997,7 @@ findDependentObjects(const ObjectAddress *object,
else if (stack)
extra.dependee = *stack->object;
else
- memset(&extra.dependee, 0, sizeof(extra.dependee));
+ memset(&extra.dependee, 0, sizeof(ObjectAddress));
add_exact_object_address_extra(object, &extra, targetObjects);
}
@@ -1640,7 +1640,7 @@ recordDependencyOnSingleRelExpr(const ObjectAddress *depender,
context.addrs = new_object_addresses();
/* We gin up a rather bogus rangetable list to handle Vars */
- MemSet(&rte, 0, sizeof(rte));
+ MemSet(&rte, 0, sizeof(RangeTblEntry));
rte.type = T_RangeTblEntry;
rte.rtekind = RTE_RELATION;
rte.relid = relId;
diff --git a/src/backend/commands/analyze.c b/src/backend/commands/analyze.c
index 2da6b75a15..e9eeab9727 100644
--- a/src/backend/commands/analyze.c
+++ b/src/backend/commands/analyze.c
@@ -2394,7 +2394,7 @@ compute_scalar_stats(VacAttrStatsP stats,
tupnoLink = (int *) palloc(samplerows * sizeof(int));
track = (ScalarMCVItem *) palloc(num_mcv * sizeof(ScalarMCVItem));
- memset(&ssup, 0, sizeof(ssup));
+ memset(&ssup, 0, sizeof(SortSupportData));
ssup.ssup_cxt = CurrentMemoryContext;
ssup.ssup_collation = stats->attrcollid;
ssup.ssup_nulls_first = false;
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 2de0ebacec..5b837a0ee3 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -11508,7 +11508,7 @@ validateForeignKeyConstraint(char *conname,
/*
* Build a trigger call structure; we'll need it either way.
*/
- MemSet(&trig, 0, sizeof(trig));
+ MemSet(&trig, 0, sizeof(Trigger));
trig.tgoid = InvalidOid;
trig.tgname = conname;
trig.tgenabled = TRIGGER_FIRES_ON_ORIGIN;
@@ -19231,7 +19231,7 @@ ATDetachCheckNoForeignKeyRefs(Relation partition)
/* prevent data changes into the referencing table until commit */
rel = table_open(constrForm->conrelid, ShareLock);
- MemSet(&trig, 0, sizeof(trig));
+ MemSet(&trig, 0, sizeof(Trigger));
trig.tgoid = InvalidOid;
trig.tgname = NameStr(constrForm->conname);
trig.tgenabled = TRIGGER_FIRES_ON_ORIGIN;
diff --git a/src/backend/commands/typecmds.c b/src/backend/commands/typecmds.c
index 9b92b04242..a2d9904568 100644
--- a/src/backend/commands/typecmds.c
+++ b/src/backend/commands/typecmds.c
@@ -4119,7 +4119,7 @@ AlterType(AlterTypeStmt *stmt)
typForm = (Form_pg_type) GETSTRUCT(tup);
/* Process options */
- memset(&atparams, 0, sizeof(atparams));
+ memset(&atparams, 0, sizeof(AlterTypeRecurseParams));
foreach(pl, stmt->options)
{
DefElem *defel = (DefElem *) lfirst(pl);
@@ -4441,7 +4441,7 @@ AlterTypeRecurse(Oid typeOid, bool isImplicitArray,
if (!HeapTupleIsValid(arrtup))
elog(ERROR, "cache lookup failed for type %u", arrtypoid);
- memset(&arrparams, 0, sizeof(arrparams));
+ memset(&arrparams, 0, sizeof(AlterTypeRecurseParams));
arrparams.updateTypmodin = atparams->updateTypmodin;
arrparams.updateTypmodout = atparams->updateTypmodout;
arrparams.typmodinOid = atparams->typmodinOid;
diff --git a/src/backend/executor/execExpr.c b/src/backend/executor/execExpr.c
index 2831e7978b..a9d6cc4e07 100644
--- a/src/backend/executor/execExpr.c
+++ b/src/backend/executor/execExpr.c
@@ -3163,7 +3163,7 @@ ExecInitSubscriptingRef(ExprEvalStep *scratch, SubscriptingRef *sbsref,
* execution steps below; and it can optionally set up some data pointed
* to by the workspace field.
*/
- memset(&methods, 0, sizeof(methods));
+ memset(&methods, 0, sizeof(SubscriptExecSteps));
sbsroutines->exec_setup(sbsref, sbsrefstate, &methods);
/*
diff --git a/src/backend/executor/spi.c b/src/backend/executor/spi.c
index 29bc26669b..701ef3e132 100644
--- a/src/backend/executor/spi.c
+++ b/src/backend/executor/spi.c
@@ -611,7 +611,7 @@ SPI_execute(const char *src, bool read_only, long tcount)
_SPI_prepare_oneshot_plan(src, &plan);
- memset(&options, 0, sizeof(options));
+ memset(&options, 0, sizeof(SPIExecuteOptions));
options.read_only = read_only;
options.tcount = tcount;
@@ -683,7 +683,7 @@ SPI_execute_plan(SPIPlanPtr plan, Datum *Values, const char *Nulls,
if (res < 0)
return res;
- memset(&options, 0, sizeof(options));
+ memset(&options, 0, sizeof(SPIExecuteOptions));
options.params = _SPI_convert_params(plan->nargs, plan->argtypes,
Values, Nulls);
options.read_only = read_only;
@@ -741,7 +741,7 @@ SPI_execute_plan_with_paramlist(SPIPlanPtr plan, ParamListInfo params,
if (res < 0)
return res;
- memset(&options, 0, sizeof(options));
+ memset(&options, 0, sizeof(SPIExecuteOptions));
options.params = params;
options.read_only = read_only;
options.tcount = tcount;
@@ -786,7 +786,7 @@ SPI_execute_snapshot(SPIPlanPtr plan,
if (res < 0)
return res;
- memset(&options, 0, sizeof(options));
+ memset(&options, 0, sizeof(SPIExecuteOptions));
options.params = _SPI_convert_params(plan->nargs, plan->argtypes,
Values, Nulls);
options.read_only = read_only;
@@ -841,7 +841,7 @@ SPI_execute_with_args(const char *src,
_SPI_prepare_oneshot_plan(src, &plan);
- memset(&options, 0, sizeof(options));
+ memset(&options, 0, sizeof(SPIExecuteOptions));
options.params = paramLI;
options.read_only = read_only;
options.tcount = tcount;
diff --git a/src/backend/libpq/auth.c b/src/backend/libpq/auth.c
index efc53f3135..450ea73b22 100644
--- a/src/backend/libpq/auth.c
+++ b/src/backend/libpq/auth.c
@@ -3041,7 +3041,7 @@ PerformRadiusTransaction(const char *server, const char *secret, const char *por
if (identifier == NULL)
identifier = "postgresql";
- MemSet(&hint, 0, sizeof(hint));
+ MemSet(&hint, 0, sizeof(struct addrinfo));
hint.ai_socktype = SOCK_DGRAM;
hint.ai_family = AF_UNSPEC;
port = atoi(portstr);
@@ -3133,8 +3133,8 @@ PerformRadiusTransaction(const char *server, const char *secret, const char *por
return STATUS_ERROR;
}
- memset(&localaddr, 0, sizeof(localaddr));
#ifdef HAVE_IPV6
+ memset(&localaddr, 0, sizeof(struct sockaddr_in6));
localaddr.sin6_family = serveraddrs[0].ai_family;
localaddr.sin6_addr = in6addr_any;
if (localaddr.sin6_family == AF_INET6)
@@ -3142,6 +3142,7 @@ PerformRadiusTransaction(const char *server, const char *secret, const char *por
else
addrsize = sizeof(struct sockaddr_in);
#else
+ memset(&localaddr, 0, sizeof(struct sockaddr_in));
localaddr.sin_family = serveraddrs[0].ai_family;
localaddr.sin_addr.s_addr = INADDR_ANY;
addrsize = sizeof(struct sockaddr_in);
diff --git a/src/backend/libpq/hba.c b/src/backend/libpq/hba.c
index 327a4b42af..eb67505180 100644
--- a/src/backend/libpq/hba.c
+++ b/src/backend/libpq/hba.c
@@ -1964,7 +1964,7 @@ parse_hba_auth_opt(char *name, char *val, HbaLine *hbaline,
/* For each entry in the list, translate it */
foreach(l, parsed_servers)
{
- MemSet(&hints, 0, sizeof(hints));
+ MemSet(&hints, 0, sizeof(struct addrinfo));
hints.ai_socktype = SOCK_DGRAM;
hints.ai_family = AF_UNSPEC;
diff --git a/src/backend/libpq/ifaddr.c b/src/backend/libpq/ifaddr.c
index a41808aff0..346620ef33 100644
--- a/src/backend/libpq/ifaddr.c
+++ b/src/backend/libpq/ifaddr.c
@@ -137,7 +137,7 @@ pg_sockaddr_cidr_mask(struct sockaddr_storage *mask, char *numbits, int family)
if (bits < 0 || bits > 32)
return -1;
- memset(&mask4, 0, sizeof(mask4));
+ memset(&mask4, 0, sizeof(struct sockaddr_in));
/* avoid "x << 32", which is not portable */
if (bits > 0)
maskl = (0xffffffffUL << (32 - (int) bits))
@@ -157,7 +157,7 @@ pg_sockaddr_cidr_mask(struct sockaddr_storage *mask, char *numbits, int family)
if (bits < 0 || bits > 128)
return -1;
- memset(&mask6, 0, sizeof(mask6));
+ memset(&mask6, 0, sizeof(struct sockaddr_in6));
for (i = 0; i < 16; i++)
{
if (bits <= 0)
@@ -387,7 +387,7 @@ pg_foreach_ifaddr(PgIfAddrCallback callback, void *cb_data)
return -1;
}
- memset(&lifc, 0, sizeof(lifc));
+ memset(&lifc, 0, sizeof(struct lifconf));
lifc.lifc_family = AF_UNSPEC;
lifc.lifc_buf = buffer = ptr;
lifc.lifc_len = n_buffer;
@@ -508,7 +508,7 @@ pg_foreach_ifaddr(PgIfAddrCallback callback, void *cb_data)
return -1;
}
- memset(&ifc, 0, sizeof(ifc));
+ memset(&ifc, 0, sizeof(struct ifconf));
ifc.ifc_buf = buffer = ptr;
ifc.ifc_len = n_buffer;
@@ -566,10 +566,10 @@ pg_foreach_ifaddr(PgIfAddrCallback callback, void *cb_data)
#endif
/* addr 127.0.0.1/8 */
- memset(&addr, 0, sizeof(addr));
+ memset(&addr, 0, sizeof(struct sockaddr_in));
addr.sin_family = AF_INET;
addr.sin_addr.s_addr = pg_ntoh32(0x7f000001);
- memset(&mask, 0, sizeof(mask));
+ memset(&mask, 0, sizeof(struct sockaddr_storage));
pg_sockaddr_cidr_mask(&mask, "8", AF_INET);
run_ifaddr_callback(callback, cb_data,
(struct sockaddr *) &addr,
@@ -577,10 +577,10 @@ pg_foreach_ifaddr(PgIfAddrCallback callback, void *cb_data)
#ifdef HAVE_IPV6
/* addr ::1/128 */
- memset(&addr6, 0, sizeof(addr6));
+ memset(&addr6, 0, sizeof(struct sockaddr_in6));
addr6.sin6_family = AF_INET6;
addr6.sin6_addr.s6_addr[15] = 1;
- memset(&mask, 0, sizeof(mask));
+ memset(&mask, 0, sizeof(struct sockaddr_storage));
pg_sockaddr_cidr_mask(&mask, "128", AF_INET6);
run_ifaddr_callback(callback, cb_data,
(struct sockaddr *) &addr6,
diff --git a/src/backend/libpq/pqcomm.c b/src/backend/libpq/pqcomm.c
index 75392a8bb7..ed041b79eb 100644
--- a/src/backend/libpq/pqcomm.c
+++ b/src/backend/libpq/pqcomm.c
@@ -343,7 +343,7 @@ StreamServerPort(int family, const char *hostName, unsigned short portNumber,
#endif
/* Initialize hint structure */
- MemSet(&hint, 0, sizeof(hint));
+ MemSet(&hint, 0, sizeof(struct addrinfo));
hint.ai_family = family;
hint.ai_flags = AI_PASSIVE;
hint.ai_socktype = SOCK_STREAM;
diff --git a/src/backend/optimizer/path/allpaths.c b/src/backend/optimizer/path/allpaths.c
index 7ac116a791..77f1d0665f 100644
--- a/src/backend/optimizer/path/allpaths.c
+++ b/src/backend/optimizer/path/allpaths.c
@@ -2467,7 +2467,7 @@ set_subquery_pathlist(PlannerInfo *root, RelOptInfo *rel,
* will be set true if we find that output column i of the subquery is
* unsafe to use in a pushed-down qual.
*/
- memset(&safetyInfo, 0, sizeof(safetyInfo));
+ memset(&safetyInfo, 0, sizeof(pushdown_safety_info));
safetyInfo.unsafeColumns = (bool *)
palloc0((list_length(subquery->targetList) + 1) * sizeof(bool));
diff --git a/src/backend/optimizer/path/indxpath.c b/src/backend/optimizer/path/indxpath.c
index 0ef70ad7f1..f78d38e019 100644
--- a/src/backend/optimizer/path/indxpath.c
+++ b/src/backend/optimizer/path/indxpath.c
@@ -269,7 +269,7 @@ create_index_paths(PlannerInfo *root, RelOptInfo *rel)
/*
* Identify the restriction clauses that can match the index.
*/
- MemSet(&rclauseset, 0, sizeof(rclauseset));
+ MemSet(&rclauseset, 0, sizeof(IndexClauseSet));
match_restriction_clauses_to_index(root, index, &rclauseset);
/*
@@ -286,7 +286,7 @@ create_index_paths(PlannerInfo *root, RelOptInfo *rel)
* step finds only "loose" join clauses that have not been merged into
* EquivalenceClasses. Also, collect join OR clauses for later.
*/
- MemSet(&jclauseset, 0, sizeof(jclauseset));
+ MemSet(&jclauseset, 0, sizeof(IndexClauseSet));
match_join_clauses_to_index(root, rel, index,
&jclauseset, &joinorclauses);
@@ -294,7 +294,7 @@ create_index_paths(PlannerInfo *root, RelOptInfo *rel)
* Look for EquivalenceClasses that can generate joinclauses matching
* the index.
*/
- MemSet(&eclauseset, 0, sizeof(eclauseset));
+ MemSet(&eclauseset, 0, sizeof(IndexClauseSet));
match_eclass_clauses_to_index(root, index,
&eclauseset);
@@ -616,7 +616,7 @@ get_join_index_paths(PlannerInfo *root, RelOptInfo *rel,
return;
/* Identify indexclauses usable with this relids set */
- MemSet(&clauseset, 0, sizeof(clauseset));
+ MemSet(&clauseset, 0, sizeof(IndexClauseSet));
for (indexcol = 0; indexcol < index->nkeycolumns; indexcol++)
{
@@ -1211,7 +1211,7 @@ build_paths_for_OR(PlannerInfo *root, RelOptInfo *rel,
/*
* Identify the restriction clauses that can match the index.
*/
- MemSet(&clauseset, 0, sizeof(clauseset));
+ MemSet(&clauseset, 0, sizeof(IndexClauseSet));
match_clauses_to_index(root, clauses, index, &clauseset);
/*
diff --git a/src/backend/optimizer/plan/planner.c b/src/backend/optimizer/plan/planner.c
index a0f2390334..598bf3960a 100644
--- a/src/backend/optimizer/plan/planner.c
+++ b/src/backend/optimizer/plan/planner.c
@@ -5915,12 +5915,12 @@ expression_planner_with_deps(Expr *expr,
PlannerInfo root;
/* Make up dummy planner state so we can use setrefs machinery */
- MemSet(&glob, 0, sizeof(glob));
+ MemSet(&glob, 0, sizeof(PlannerGlobal));
glob.type = T_PlannerGlobal;
glob.relationOids = NIL;
glob.invalItems = NIL;
- MemSet(&root, 0, sizeof(root));
+ MemSet(&root, 0, sizeof(PlannerInfo));
root.type = T_PlannerInfo;
root.glob = &glob;
diff --git a/src/backend/optimizer/plan/setrefs.c b/src/backend/optimizer/plan/setrefs.c
index d95fd89807..eabeacb0e5 100644
--- a/src/backend/optimizer/plan/setrefs.c
+++ b/src/backend/optimizer/plan/setrefs.c
@@ -3274,14 +3274,14 @@ extract_query_dependencies(Node *query,
PlannerInfo root;
/* Make up dummy planner state so we can use this module's machinery */
- MemSet(&glob, 0, sizeof(glob));
+ MemSet(&glob, 0, sizeof(PlannerGlobal));
glob.type = T_PlannerGlobal;
glob.relationOids = NIL;
glob.invalItems = NIL;
/* Hack: we use glob.dependsOnRole to collect hasRowSecurity flags */
glob.dependsOnRole = false;
- MemSet(&root, 0, sizeof(root));
+ MemSet(&root, 0, sizeof(PlannerInfo));
root.type = T_PlannerInfo;
root.glob = &glob;
diff --git a/src/backend/parser/parse_target.c b/src/backend/parser/parse_target.c
index 2a1d44b813..375714154a 100644
--- a/src/backend/parser/parse_target.c
+++ b/src/backend/parser/parse_target.c
@@ -1596,7 +1596,7 @@ expandRecordVariable(ParseState *pstate, Var *var, int levelsup)
*/
ParseState mypstate;
- MemSet(&mypstate, 0, sizeof(mypstate));
+ MemSet(&mypstate, 0, sizeof(ParseState));
mypstate.parentParseState = pstate;
mypstate.p_rtable = rte->subquery->rtable;
/* don't bother filling the rest of the fake pstate */
@@ -1652,7 +1652,7 @@ expandRecordVariable(ParseState *pstate, Var *var, int levelsup)
ParseState mypstate;
Index levelsup;
- MemSet(&mypstate, 0, sizeof(mypstate));
+ MemSet(&mypstate, 0, sizeof(ParseState));
/* this loop must work, since GetCTEForRTE did */
for (levelsup = 0;
levelsup < rte->ctelevelsup + netlevelsup;
diff --git a/src/backend/postmaster/postmaster.c b/src/backend/postmaster/postmaster.c
index 3b73e26956..76ba287da4 100644
--- a/src/backend/postmaster/postmaster.c
+++ b/src/backend/postmaster/postmaster.c
@@ -4525,7 +4525,7 @@ postmaster_forkexec(int argc, char *argv[])
Port port;
/* This entry point passes dummy values for the Port variables */
- memset(&port, 0, sizeof(port));
+ memset(&port, 0, sizeof(Port));
return internal_forkexec(argc, argv, &port);
}
diff --git a/src/backend/replication/logical/launcher.c b/src/backend/replication/logical/launcher.c
index bd5f78cf9a..14014461a1 100644
--- a/src/backend/replication/logical/launcher.c
+++ b/src/backend/replication/logical/launcher.c
@@ -391,7 +391,7 @@ retry:
LWLockRelease(LogicalRepWorkerLock);
/* Register the new dynamic worker. */
- memset(&bgw, 0, sizeof(bgw));
+ memset(&bgw, 0, sizeof(BackgroundWorker));
bgw.bgw_flags = BGWORKER_SHMEM_ACCESS |
BGWORKER_BACKEND_DATABASE_CONNECTION;
bgw.bgw_start_time = BgWorkerStart_RecoveryFinished;
@@ -710,7 +710,7 @@ ApplyLauncherRegister(void)
if (max_logical_replication_workers == 0)
return;
- memset(&bgw, 0, sizeof(bgw));
+ memset(&bgw, 0, sizeof(BackgroundWorker));
bgw.bgw_flags = BGWORKER_SHMEM_ACCESS |
BGWORKER_BACKEND_DATABASE_CONNECTION;
bgw.bgw_start_time = BgWorkerStart_RecoveryFinished;
diff --git a/src/backend/replication/logical/origin.c b/src/backend/replication/logical/origin.c
index 21937ab2d3..524b880f78 100644
--- a/src/backend/replication/logical/origin.c
+++ b/src/backend/replication/logical/origin.c
@@ -615,7 +615,7 @@ CheckPointReplicationOrigin(void)
continue;
/* zero, to avoid uninitialized padding bytes */
- memset(&disk_state, 0, sizeof(disk_state));
+ memset(&disk_state, 0, sizeof(ReplicationStateOnDisk));
LWLockAcquire(&curstate->lock, LW_SHARED);
diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c
index 8da5f9089c..628087c417 100644
--- a/src/backend/replication/logical/reorderbuffer.c
+++ b/src/backend/replication/logical/reorderbuffer.c
@@ -314,7 +314,7 @@ ReorderBufferAllocate(void)
buffer =
(ReorderBuffer *) MemoryContextAlloc(new_ctx, sizeof(ReorderBuffer));
- memset(&hash_ctl, 0, sizeof(hash_ctl));
+ memset(&hash_ctl, 0, sizeof(HASHCTL));
buffer->context = new_ctx;
@@ -4740,7 +4740,7 @@ ReorderBufferToastReplace(ReorderBuffer *rb, ReorderBufferTXN *txn,
else
SET_VARSIZE(reconstructed, data_done + VARHDRSZ);
- memset(&redirect_pointer, 0, sizeof(redirect_pointer));
+ memset(&redirect_pointer, 0, sizeof(struct varatt_indirect));
redirect_pointer.pointer = reconstructed;
SET_VARTAG_EXTERNAL(new_datum, VARTAG_INDIRECT);
@@ -5115,7 +5115,7 @@ ResolveCminCmaxDuringDecoding(HTAB *tuplecid_data,
return false;
/* be careful about padding */
- memset(&key, 0, sizeof(key));
+ memset(&key, 0, sizeof(ReorderBufferTupleCidKey));
Assert(!BufferIsLocal(buffer));
diff --git a/src/backend/storage/ipc/standby.c b/src/backend/storage/ipc/standby.c
index 671b00a33c..42a6f5ee91 100644
--- a/src/backend/storage/ipc/standby.c
+++ b/src/backend/storage/ipc/standby.c
@@ -1402,7 +1402,7 @@ LogStandbyInvalidations(int nmsgs, SharedInvalidationMessage *msgs,
xl_invalidations xlrec;
/* prepare record */
- memset(&xlrec, 0, sizeof(xlrec));
+ memset(&xlrec, 0, sizeof(xl_invalidations));
xlrec.dbId = MyDatabaseId;
xlrec.tsId = MyDatabaseTableSpace;
xlrec.relcacheInitFileInval = relcacheInitFileInval;
diff --git a/src/backend/storage/lmgr/lock.c b/src/backend/storage/lmgr/lock.c
index 5f5803f681..62f670f5d0 100644
--- a/src/backend/storage/lmgr/lock.c
+++ b/src/backend/storage/lmgr/lock.c
@@ -603,7 +603,7 @@ LockHeldByMe(const LOCKTAG *locktag, LOCKMODE lockmode)
/*
* See if there is a LOCALLOCK entry for this lock and lockmode
*/
- MemSet(&localtag, 0, sizeof(localtag)); /* must clear padding */
+ MemSet(&localtag, 0, sizeof(LOCALLOCKTAG)); /* must clear padding */
localtag.lock = *locktag;
localtag.mode = lockmode;
@@ -658,7 +658,7 @@ LockHasWaiters(const LOCKTAG *locktag, LOCKMODE lockmode, bool sessionLock)
/*
* Find the LOCALLOCK entry for this lock and lockmode
*/
- MemSet(&localtag, 0, sizeof(localtag)); /* must clear padding */
+ MemSet(&localtag, 0, sizeof(LOCALLOCKTAG)); /* must clear padding */
localtag.lock = *locktag;
localtag.mode = lockmode;
@@ -820,7 +820,7 @@ LockAcquireExtended(const LOCKTAG *locktag,
/*
* Find or create a LOCALLOCK entry for this lock and lockmode
*/
- MemSet(&localtag, 0, sizeof(localtag)); /* must clear padding */
+ MemSet(&localtag, 0, sizeof(LOCALLOCKTAG)); /* must clear padding */
localtag.lock = *locktag;
localtag.mode = lockmode;
@@ -1999,7 +1999,7 @@ LockRelease(const LOCKTAG *locktag, LOCKMODE lockmode, bool sessionLock)
/*
* Find the LOCALLOCK entry for this lock and lockmode
*/
- MemSet(&localtag, 0, sizeof(localtag)); /* must clear padding */
+ MemSet(&localtag, 0, sizeof(LOCALLOCKTAG)); /* must clear padding */
localtag.lock = *locktag;
localtag.mode = lockmode;
diff --git a/src/backend/storage/lmgr/lwlock.c b/src/backend/storage/lmgr/lwlock.c
index 8aef909037..6b56fc345d 100644
--- a/src/backend/storage/lmgr/lwlock.c
+++ b/src/backend/storage/lmgr/lwlock.c
@@ -397,7 +397,7 @@ get_lwlock_stats_entry(LWLock *lock)
return &lwlock_stats_dummy;
/* Fetch or create the entry. */
- MemSet(&key, 0, sizeof(key));
+ MemSet(&key, 0, sizeof(lwlock_stats_key));
key.tranche = lock->tranche;
key.instance = lock;
lwstats = hash_search(lwlock_stats_htab, &key, HASH_ENTER, &found);
diff --git a/src/backend/utils/activity/backend_status.c b/src/backend/utils/activity/backend_status.c
index c7ed1e6d7a..f49ee51384 100644
--- a/src/backend/utils/activity/backend_status.c
+++ b/src/backend/utils/activity/backend_status.c
@@ -320,10 +320,10 @@ pgstat_bestart(void)
/* These structs can just start from zeroes each time, though */
#ifdef USE_SSL
- memset(&lsslstatus, 0, sizeof(lsslstatus));
+ memset(&lsslstatus, 0, sizeof(PgBackendSSLStatus));
#endif
#ifdef ENABLE_GSS
- memset(&lgssstatus, 0, sizeof(lgssstatus));
+ memset(&lgssstatus, 0, sizeof(PgBackendGSSStatus));
#endif
/*
@@ -353,9 +353,9 @@ pgstat_bestart(void)
*/
if (MyProcPort)
memcpy(&lbeentry.st_clientaddr, &MyProcPort->raddr,
- sizeof(lbeentry.st_clientaddr));
+ sizeof(SockAddr));
else
- MemSet(&lbeentry.st_clientaddr, 0, sizeof(lbeentry.st_clientaddr));
+ MemSet(&lbeentry.st_clientaddr, 0, sizeof(SockAddr));
#ifdef USE_SSL
if (MyProcPort && MyProcPort->ssl_in_use)
diff --git a/src/backend/utils/activity/pgstat_replslot.c b/src/backend/utils/activity/pgstat_replslot.c
index b77c05ab5f..59794eb378 100644
--- a/src/backend/utils/activity/pgstat_replslot.c
+++ b/src/backend/utils/activity/pgstat_replslot.c
@@ -123,7 +123,7 @@ pgstat_create_replslot(ReplicationSlot *slot)
* NB: need to accept that there might be stats from an older slot, e.g.
* if we previously crashed after dropping a slot.
*/
- memset(&shstatent->stats, 0, sizeof(shstatent->stats));
+ memset(&shstatent->stats, 0, sizeof(PgStat_StatReplSlotEntry));
namestrcpy(&shstatent->stats.slotname, NameStr(slot->data.name));
pgstat_unlock_entry(entry_ref);
diff --git a/src/backend/utils/activity/pgstat_wal.c b/src/backend/utils/activity/pgstat_wal.c
index 5a878bd115..993aedf460 100644
--- a/src/backend/utils/activity/pgstat_wal.c
+++ b/src/backend/utils/activity/pgstat_wal.c
@@ -154,7 +154,7 @@ pgstat_wal_reset_all_cb(TimestampTz ts)
PgStatShared_Wal *stats_shmem = &pgStatLocal.shmem->wal;
LWLockAcquire(&stats_shmem->lock, LW_EXCLUSIVE);
- memset(&stats_shmem->stats, 0, sizeof(stats_shmem->stats));
+ memset(&stats_shmem->stats, 0, sizeof(PgStat_WalStats));
stats_shmem->stats.stat_reset_timestamp = ts;
LWLockRelease(&stats_shmem->lock);
}
diff --git a/src/backend/utils/adt/array_selfuncs.c b/src/backend/utils/adt/array_selfuncs.c
index 8cbee1406b..b916d41c20 100644
--- a/src/backend/utils/adt/array_selfuncs.c
+++ b/src/backend/utils/adt/array_selfuncs.c
@@ -151,7 +151,7 @@ scalararraysel_containment(PlannerInfo *root,
!get_attstatsslot(&hslot, vardata.statsTuple,
STATISTIC_KIND_DECHIST, InvalidOid,
ATTSTATSSLOT_NUMBERS))
- memset(&hslot, 0, sizeof(hslot));
+ memset(&hslot, 0, sizeof(AttStatsSlot));
/*
* For = ANY, estimate as var @> ARRAY[const].
@@ -377,7 +377,7 @@ calc_arraycontsel(VariableStatData *vardata, Datum constval,
!get_attstatsslot(&hslot, vardata->statsTuple,
STATISTIC_KIND_DECHIST, InvalidOid,
ATTSTATSSLOT_NUMBERS))
- memset(&hslot, 0, sizeof(hslot));
+ memset(&hslot, 0, sizeof(AttStatsSlot));
/* Use the most-common-elements slot for the array Var. */
selec = mcelem_array_selec(array, typentry,
diff --git a/src/backend/utils/adt/json.c b/src/backend/utils/adt/json.c
index 553cc25eb9..529c2352b6 100644
--- a/src/backend/utils/adt/json.c
+++ b/src/backend/utils/adt/json.c
@@ -966,7 +966,7 @@ json_unique_check_init(JsonUniqueCheckState *cxt)
{
HASHCTL ctl;
- memset(&ctl, 0, sizeof(ctl));
+ memset(&ctl, 0, sizeof(HASHCTL));
ctl.keysize = sizeof(JsonUniqueHashEntry);
ctl.entrysize = sizeof(JsonUniqueHashEntry);
ctl.hcxt = CurrentMemoryContext;
@@ -1058,7 +1058,7 @@ json_object_agg_transfn_worker(FunctionCallInfo fcinfo,
if (unique_keys)
json_unique_builder_init(&state->unique_check);
else
- memset(&state->unique_check, 0, sizeof(state->unique_check));
+ memset(&state->unique_check, 0, sizeof(JsonUniqueBuilderState));
MemoryContextSwitchTo(oldcontext);
arg_type = get_fn_expr_argtype(fcinfo->flinfo, 1);
diff --git a/src/backend/utils/adt/jsonb.c b/src/backend/utils/adt/jsonb.c
index 39355e242d..a09c632c86 100644
--- a/src/backend/utils/adt/jsonb.c
+++ b/src/backend/utils/adt/jsonb.c
@@ -246,8 +246,8 @@ jsonb_from_cstring(char *json, int len, bool unique_keys)
JsonbInState state;
JsonSemAction sem;
- memset(&state, 0, sizeof(state));
- memset(&sem, 0, sizeof(sem));
+ memset(&state, 0, sizeof(JsonbInState));
+ memset(&sem, 0, sizeof(JsonSemAction));
lex = makeJsonLexContextCstringLen(json, len, GetDatabaseEncoding(), true);
state.unique_keys = unique_keys;
@@ -839,7 +839,7 @@ datum_to_jsonb(Datum val, bool is_null, JsonbInState *result,
lex = makeJsonLexContext(json, true);
- memset(&sem, 0, sizeof(sem));
+ memset(&sem, 0, sizeof(JsonSemAction));
sem.semstate = (void *) result;
diff --git a/src/backend/utils/adt/jsonfuncs.c b/src/backend/utils/adt/jsonfuncs.c
index d427bdfbe0..87c6431b33 100644
--- a/src/backend/utils/adt/jsonfuncs.c
+++ b/src/backend/utils/adt/jsonfuncs.c
@@ -2625,7 +2625,7 @@ populate_array_json(PopulateArrayContext *ctx, char *json, int len)
state.lex = makeJsonLexContextCstringLen(json, len, GetDatabaseEncoding(), true);
state.ctx = ctx;
- memset(&sem, 0, sizeof(sem));
+ memset(&sem, 0, sizeof(JsonSemAction));
sem.semstate = (void *) &state;
sem.object_start = populate_array_object_start;
sem.array_end = populate_array_array_end;
diff --git a/src/backend/utils/adt/mcxtfuncs.c b/src/backend/utils/adt/mcxtfuncs.c
index bb7cc94024..b7f832ccb5 100644
--- a/src/backend/utils/adt/mcxtfuncs.c
+++ b/src/backend/utils/adt/mcxtfuncs.c
@@ -62,7 +62,7 @@ PutMemoryContextsStatsTupleStore(Tuplestorestate *tupstore,
}
/* Examine the context itself */
- memset(&stat, 0, sizeof(stat));
+ memset(&stat, 0, sizeof(MemoryContextCounters));
(*context->methods->stats) (context, NULL, (void *) &level, &stat, true);
memset(values, 0, sizeof(values));
diff --git a/src/backend/utils/adt/multirangetypes_selfuncs.c b/src/backend/utils/adt/multirangetypes_selfuncs.c
index 919c8889d4..9a74c542ba 100644
--- a/src/backend/utils/adt/multirangetypes_selfuncs.c
+++ b/src/backend/utils/adt/multirangetypes_selfuncs.c
@@ -535,7 +535,7 @@ calc_hist_selectivity(TypeCacheEntry *typcache, VariableStatData *vardata,
}
}
else
- memset(&lslot, 0, sizeof(lslot));
+ memset(&lslot, 0, sizeof(AttStatsSlot));
/* Extract the bounds of the constant value. */
Assert(constval->rangeCount > 0);
diff --git a/src/backend/utils/adt/network_selfuncs.c b/src/backend/utils/adt/network_selfuncs.c
index 49196376a8..a34e74d97e 100644
--- a/src/backend/utils/adt/network_selfuncs.c
+++ b/src/backend/utils/adt/network_selfuncs.c
@@ -299,8 +299,8 @@ networkjoinsel_inner(Oid operator,
}
else
{
- memset(&mcv1_slot, 0, sizeof(mcv1_slot));
- memset(&hist1_slot, 0, sizeof(hist1_slot));
+ memset(&mcv1_slot, 0, sizeof(AttStatsSlot));
+ memset(&hist1_slot, 0, sizeof(AttStatsSlot));
}
if (HeapTupleIsValid(vardata2->statsTuple))
@@ -321,8 +321,8 @@ networkjoinsel_inner(Oid operator,
}
else
{
- memset(&mcv2_slot, 0, sizeof(mcv2_slot));
- memset(&hist2_slot, 0, sizeof(hist2_slot));
+ memset(&mcv2_slot, 0, sizeof(AttStatsSlot));
+ memset(&hist2_slot, 0, sizeof(AttStatsSlot));
}
opr_codenum = inet_opr_codenum(operator);
@@ -429,8 +429,8 @@ networkjoinsel_semi(Oid operator,
}
else
{
- memset(&mcv1_slot, 0, sizeof(mcv1_slot));
- memset(&hist1_slot, 0, sizeof(hist1_slot));
+ memset(&mcv1_slot, 0, sizeof(AttStatsSlot));
+ memset(&hist1_slot, 0, sizeof(AttStatsSlot));
}
if (HeapTupleIsValid(vardata2->statsTuple))
@@ -451,8 +451,8 @@ networkjoinsel_semi(Oid operator,
}
else
{
- memset(&mcv2_slot, 0, sizeof(mcv2_slot));
- memset(&hist2_slot, 0, sizeof(hist2_slot));
+ memset(&mcv2_slot, 0, sizeof(AttStatsSlot));
+ memset(&hist2_slot, 0, sizeof(AttStatsSlot));
}
opr_codenum = inet_opr_codenum(operator);
diff --git a/src/backend/utils/adt/pg_locale.c b/src/backend/utils/adt/pg_locale.c
index a0490a7522..5262b47902 100644
--- a/src/backend/utils/adt/pg_locale.c
+++ b/src/backend/utils/adt/pg_locale.c
@@ -497,7 +497,7 @@ PGLC_localeconv(void)
* allocated with strdup, to avoid premature elog(ERROR) and to allow
* using a single cleanup routine.
*/
- memset(&worklconv, 0, sizeof(worklconv));
+ memset(&worklconv, 0, sizeof(struct lconv));
/* Save prevailing values of monetary and numeric locales */
save_lc_monetary = setlocale(LC_MONETARY, NULL);
@@ -1548,7 +1548,7 @@ pg_newlocale_from_collation(Oid collid)
collform = (Form_pg_collation) GETSTRUCT(tp);
/* We'll fill in the result struct locally before allocating memory */
- memset(&result, 0, sizeof(result));
+ memset(&result, 0, sizeof(struct pg_locale_struct));
result.provider = collform->collprovider;
result.deterministic = collform->collisdeterministic;
diff --git a/src/backend/utils/adt/pgstatfuncs.c b/src/backend/utils/adt/pgstatfuncs.c
index 893690dad5..1828c2e0fe 100644
--- a/src/backend/utils/adt/pgstatfuncs.c
+++ b/src/backend/utils/adt/pgstatfuncs.c
@@ -731,7 +731,7 @@ pg_stat_get_activity(PG_FUNCTION_ARGS)
nulls[11] = true;
/* A zeroed client addr means we don't know */
- memset(&zero_clientaddr, 0, sizeof(zero_clientaddr));
+ memset(&zero_clientaddr, 0, sizeof(SockAddr));
if (memcmp(&(beentry->st_clientaddr), &zero_clientaddr,
sizeof(zero_clientaddr)) == 0)
{
@@ -1103,7 +1103,7 @@ pg_stat_get_backend_client_addr(PG_FUNCTION_ARGS)
PG_RETURN_NULL();
/* A zeroed client addr means we don't know */
- memset(&zero_clientaddr, 0, sizeof(zero_clientaddr));
+ memset(&zero_clientaddr, 0, sizeof(SockAddr));
if (memcmp(&(beentry->st_clientaddr), &zero_clientaddr,
sizeof(zero_clientaddr)) == 0)
PG_RETURN_NULL();
@@ -1150,7 +1150,7 @@ pg_stat_get_backend_client_port(PG_FUNCTION_ARGS)
PG_RETURN_NULL();
/* A zeroed client addr means we don't know */
- memset(&zero_clientaddr, 0, sizeof(zero_clientaddr));
+ memset(&zero_clientaddr, 0, sizeof(SockAddr));
if (memcmp(&(beentry->st_clientaddr), &zero_clientaddr,
sizeof(zero_clientaddr)) == 0)
PG_RETURN_NULL();
diff --git a/src/backend/utils/adt/rangetypes_selfuncs.c b/src/backend/utils/adt/rangetypes_selfuncs.c
index c2795f4593..9222381181 100644
--- a/src/backend/utils/adt/rangetypes_selfuncs.c
+++ b/src/backend/utils/adt/rangetypes_selfuncs.c
@@ -446,7 +446,7 @@ calc_hist_selectivity(TypeCacheEntry *typcache, VariableStatData *vardata,
}
}
else
- memset(&lslot, 0, sizeof(lslot));
+ memset(&lslot, 0, sizeof(AttStatsSlot));
/* Extract the bounds of the constant value. */
range_deserialize(typcache, constval, &const_lower, &const_upper, &empty);
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 49c4201dde..50fb6542ec 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -1057,7 +1057,7 @@ pg_get_triggerdef_worker(Oid trigid, bool pretty)
newrte->inFromCl = true;
/* Build two-element rtable */
- memset(&dpns, 0, sizeof(dpns));
+ memset(&dpns, 0, sizeof(deparse_namespace));
dpns.rtable = list_make2(oldrte, newrte);
dpns.subplans = NIL;
dpns.ctes = NIL;
@@ -3804,7 +3804,7 @@ select_rtable_names_for_explain(List *rtable, Bitmapset *rels_used)
{
deparse_namespace dpns;
- memset(&dpns, 0, sizeof(dpns));
+ memset(&dpns, 0, sizeof(deparse_namespace));
dpns.rtable = rtable;
dpns.subplans = NIL;
dpns.ctes = NIL;
diff --git a/src/backend/utils/adt/selfuncs.c b/src/backend/utils/adt/selfuncs.c
index fa1f589fad..0dec93f440 100644
--- a/src/backend/utils/adt/selfuncs.c
+++ b/src/backend/utils/adt/selfuncs.c
@@ -2271,8 +2271,8 @@ eqjoinsel(PG_FUNCTION_ARGS)
opfuncoid = get_opcode(operator);
- memset(&sslot1, 0, sizeof(sslot1));
- memset(&sslot2, 0, sizeof(sslot2));
+ memset(&sslot1, 0, sizeof(AttStatsSlot));
+ memset(&sslot2, 0, sizeof(AttStatsSlot));
if (HeapTupleIsValid(vardata1.statsTuple))
{
@@ -6797,7 +6797,7 @@ btcostestimate(PlannerInfo *root, IndexPath *path, double loop_count,
/*
* Now do generic index cost estimation.
*/
- MemSet(&costs, 0, sizeof(costs));
+ MemSet(&costs, 0, sizeof(GenericCosts));
costs.numIndexTuples = numIndexTuples;
genericcostestimate(root, path, loop_count, &costs);
@@ -6842,7 +6842,7 @@ btcostestimate(PlannerInfo *root, IndexPath *path, double loop_count,
* ordering, but don't negate it entirely. Before 8.0 we divided the
* correlation by the number of columns, but that seems too strong.)
*/
- MemSet(&vardata, 0, sizeof(vardata));
+ MemSet(&vardata, 0, sizeof(VariableStatData));
if (index->indexkeys[0] != 0)
{
@@ -6949,7 +6949,7 @@ hashcostestimate(PlannerInfo *root, IndexPath *path, double loop_count,
{
GenericCosts costs;
- MemSet(&costs, 0, sizeof(costs));
+ MemSet(&costs, 0, sizeof(GenericCosts));
genericcostestimate(root, path, loop_count, &costs);
@@ -6995,7 +6995,7 @@ gistcostestimate(PlannerInfo *root, IndexPath *path, double loop_count,
GenericCosts costs;
Cost descentCost;
- MemSet(&costs, 0, sizeof(costs));
+ MemSet(&costs, 0, sizeof(GenericCosts));
genericcostestimate(root, path, loop_count, &costs);
@@ -7052,7 +7052,7 @@ spgcostestimate(PlannerInfo *root, IndexPath *path, double loop_count,
GenericCosts costs;
Cost descentCost;
- MemSet(&costs, 0, sizeof(costs));
+ MemSet(&costs, 0, sizeof(GenericCosts));
genericcostestimate(root, path, loop_count, &costs);
@@ -7339,7 +7339,7 @@ gincost_scalararrayopexpr(PlannerInfo *root,
elmlen, elmbyval, elmalign,
&elemValues, &elemNulls, &numElems);
- memset(&arraycounts, 0, sizeof(arraycounts));
+ memset(&arraycounts, 0, sizeof(GinQualCounts));
for (i = 0; i < numElems; i++)
{
@@ -7350,7 +7350,7 @@ gincost_scalararrayopexpr(PlannerInfo *root,
continue;
/* Otherwise, apply extractQuery and get the actual term counts */
- memset(&elemcounts, 0, sizeof(elemcounts));
+ memset(&elemcounts, 0, sizeof(GinQualCounts));
if (gincost_pattern(index, indexcol, clause_op, elemValues[i],
&elemcounts))
@@ -7443,7 +7443,7 @@ gincostestimate(PlannerInfo *root, IndexPath *path, double loop_count,
}
else
{
- memset(&ginStats, 0, sizeof(ginStats));
+ memset(&ginStats, 0, sizeof(GinStatsData));
}
/*
@@ -7532,7 +7532,7 @@ gincostestimate(PlannerInfo *root, IndexPath *path, double loop_count,
/*
* Examine quals to estimate number of search entries & partial matches
*/
- memset(&counts, 0, sizeof(counts));
+ memset(&counts, 0, sizeof(GinQualCounts));
counts.arrayScans = 1;
matchPossible = true;
diff --git a/src/backend/utils/adt/tsvector_op.c b/src/backend/utils/adt/tsvector_op.c
index addc349151..9394a02ba2 100644
--- a/src/backend/utils/adt/tsvector_op.c
+++ b/src/backend/utils/adt/tsvector_op.c
@@ -1671,8 +1671,8 @@ TS_phrase_execute(QueryItem *curitem, void *arg, uint32 flags,
case OP_PHRASE:
case OP_AND:
- memset(&Ldata, 0, sizeof(Ldata));
- memset(&Rdata, 0, sizeof(Rdata));
+ memset(&Ldata, 0, sizeof(ExecPhraseData));
+ memset(&Rdata, 0, sizeof(ExecPhraseData));
lmatch = TS_phrase_execute(curitem + curitem->qoperator.left,
arg, flags, chkcond, &Ldata);
@@ -1753,8 +1753,8 @@ TS_phrase_execute(QueryItem *curitem, void *arg, uint32 flags,
}
case OP_OR:
- memset(&Ldata, 0, sizeof(Ldata));
- memset(&Rdata, 0, sizeof(Rdata));
+ memset(&Ldata, 0, sizeof(ExecPhraseData));
+ memset(&Rdata, 0, sizeof(ExecPhraseData));
lmatch = TS_phrase_execute(curitem + curitem->qoperator.left,
arg, flags, chkcond, &Ldata);
diff --git a/src/backend/utils/adt/varlena.c b/src/backend/utils/adt/varlena.c
index 919138eaf3..40d4bbb48a 100644
--- a/src/backend/utils/adt/varlena.c
+++ b/src/backend/utils/adt/varlena.c
@@ -4775,7 +4775,7 @@ text_to_array(PG_FUNCTION_ARGS)
SplitTextOutputData tstate;
/* For array output, tstate should start as all zeroes */
- memset(&tstate, 0, sizeof(tstate));
+ memset(&tstate, 0, sizeof(SplitTextOutputData));
if (!split_text(fcinfo, &tstate))
PG_RETURN_NULL();
diff --git a/src/backend/utils/cache/attoptcache.c b/src/backend/utils/cache/attoptcache.c
index 9e252a0891..ce4c66962f 100644
--- a/src/backend/utils/cache/attoptcache.c
+++ b/src/backend/utils/cache/attoptcache.c
@@ -110,7 +110,7 @@ get_attribute_options(Oid attrelid, int attnum)
/* Find existing cache entry, if any. */
if (!AttoptCacheHash)
InitializeAttoptCache();
- memset(&key, 0, sizeof(key)); /* make sure any padding bits are unset */
+ memset(&key, 0, sizeof(AttoptCacheKey)); /* make sure any padding bits are unset */
key.attrelid = attrelid;
key.attnum = attnum;
attopt =
diff --git a/src/backend/utils/cache/relfilenodemap.c b/src/backend/utils/cache/relfilenodemap.c
index 70c323c720..266d9aef5e 100644
--- a/src/backend/utils/cache/relfilenodemap.c
+++ b/src/backend/utils/cache/relfilenodemap.c
@@ -153,7 +153,7 @@ RelidByRelfilenode(Oid reltablespace, Oid relfilenode)
if (reltablespace == MyDatabaseTableSpace)
reltablespace = 0;
- MemSet(&key, 0, sizeof(key));
+ MemSet(&key, 0, sizeof(RelfilenodeMapKey));
key.reltablespace = reltablespace;
key.relfilenode = relfilenode;
diff --git a/src/backend/utils/fmgr/funcapi.c b/src/backend/utils/fmgr/funcapi.c
index 9197b0f1e2..6c49d4f948 100644
--- a/src/backend/utils/fmgr/funcapi.c
+++ b/src/backend/utils/fmgr/funcapi.c
@@ -776,8 +776,8 @@ resolve_polymorphic_tupdesc(TupleDesc tupdesc, oidvector *declared_args,
if (!call_expr)
return false; /* no hope */
- memset(&poly_actuals, 0, sizeof(poly_actuals));
- memset(&anyc_actuals, 0, sizeof(anyc_actuals));
+ memset(&poly_actuals, 0, sizeof(polymorphic_actuals));
+ memset(&anyc_actuals, 0, sizeof(polymorphic_actuals));
for (i = 0; i < nargs; i++)
{
@@ -1041,8 +1041,8 @@ resolve_polymorphic_argtypes(int numargs, Oid *argtypes, char *argmodes,
* resolve_polymorphic_tupdesc, we rely on the parser to have enforced
* type consistency and coerced ANYCOMPATIBLE args to a common supertype.
*/
- memset(&poly_actuals, 0, sizeof(poly_actuals));
- memset(&anyc_actuals, 0, sizeof(anyc_actuals));
+ memset(&poly_actuals, 0, sizeof(polymorphic_actuals));
+ memset(&anyc_actuals, 0, sizeof(polymorphic_actuals));
inargno = 0;
for (i = 0; i < numargs; i++)
{
diff --git a/src/backend/utils/mmgr/mcxt.c b/src/backend/utils/mmgr/mcxt.c
index e12be1b9bd..76ec50e5dc 100644
--- a/src/backend/utils/mmgr/mcxt.c
+++ b/src/backend/utils/mmgr/mcxt.c
@@ -522,7 +522,7 @@ MemoryContextStatsDetail(MemoryContext context, int max_children,
{
MemoryContextCounters grand_totals;
- memset(&grand_totals, 0, sizeof(grand_totals));
+ memset(&grand_totals, 0, sizeof(MemoryContextCounters));
MemoryContextStatsInternal(context, 0, true, max_children, &grand_totals, print_to_stderr);
@@ -582,7 +582,7 @@ MemoryContextStatsInternal(MemoryContext context, int level,
* Examine children. If there are more than max_children of them, we do
* not print the rest explicitly, but just summarize them.
*/
- memset(&local_totals, 0, sizeof(local_totals));
+ memset(&local_totals, 0, sizeof(MemoryContextCounters));
for (child = context->firstchild, ichild = 0;
child != NULL;
diff --git a/src/backend/utils/time/snapmgr.c b/src/backend/utils/time/snapmgr.c
index 5bc2a15160..84aecf64ec 100644
--- a/src/backend/utils/time/snapmgr.c
+++ b/src/backend/utils/time/snapmgr.c
@@ -1462,7 +1462,7 @@ ImportSnapshot(const char *idstr)
/*
* Construct a snapshot struct by parsing the file content.
*/
- memset(&snapshot, 0, sizeof(snapshot));
+ memset(&snapshot, 0, sizeof(SnapshotData));
parseVxidFromText("vxid:", &filebuf, path, &src_vxid);
src_pid = parseIntFromText("pid:", &filebuf, path);
diff --git a/src/bin/initdb/findtimezone.c b/src/bin/initdb/findtimezone.c
index ddb65e6489..7ff01ffef6 100644
--- a/src/bin/initdb/findtimezone.c
+++ b/src/bin/initdb/findtimezone.c
@@ -191,7 +191,7 @@ build_time_t(int year, int month, int day)
{
struct tm tm;
- memset(&tm, 0, sizeof(tm));
+ memset(&tm, 0, sizeof(struct tm));
tm.tm_mday = day;
tm.tm_mon = month - 1;
tm.tm_year = year - 1900;
diff --git a/src/bin/initdb/initdb.c b/src/bin/initdb/initdb.c
index ed6de7ca94..547efef1df 100644
--- a/src/bin/initdb/initdb.c
+++ b/src/bin/initdb/initdb.c
@@ -1959,7 +1959,7 @@ locale_date_order(const char *locale)
setlocale(LC_TIME, locale);
- memset(&testtime, 0, sizeof(testtime));
+ memset(&testtime, 0, sizeof(struct tm));
testtime.tm_mday = 22;
testtime.tm_mon = 10; /* November, should come out as "11" */
testtime.tm_year = 133; /* 2033 */
diff --git a/src/bin/pg_basebackup/pg_basebackup.c b/src/bin/pg_basebackup/pg_basebackup.c
index 4adb170d46..56aed21433 100644
--- a/src/bin/pg_basebackup/pg_basebackup.c
+++ b/src/bin/pg_basebackup/pg_basebackup.c
@@ -457,7 +457,7 @@ reached_end_position(XLogRecPtr segendpos, uint32 timeline,
FD_ZERO(&fds);
FD_SET(bgpipe[0], &fds);
- MemSet(&tv, 0, sizeof(tv));
+ MemSet(&tv, 0, sizeof(struct timeval));
r = select(bgpipe[0] + 1, &fds, NULL, NULL, &tv);
if (r == 1)
@@ -532,7 +532,7 @@ LogStreamerMain(logstreamer_param *param)
in_log_streamer = true;
- MemSet(&stream, 0, sizeof(stream));
+ MemSet(&stream, 0, sizeof(StreamCtl));
stream.startpos = param->startptr;
stream.timeline = param->timeline;
stream.sysidentifier = param->sysidentifier;
@@ -1293,7 +1293,7 @@ ReceiveArchiveStream(PGconn *conn, pg_compress_specification *compress)
ArchiveStreamState state;
/* Set up initial state. */
- memset(&state, 0, sizeof(state));
+ memset(&state, 0, sizeof(ArchiveStreamState));
state.tablespacenum = -1;
state.compress = compress;
@@ -1612,7 +1612,7 @@ ReceiveTarFile(PGconn *conn, char *archive_name, char *spclocation,
bool expect_unterminated_tarfile;
/* Pass all COPY data through to the backup streamer. */
- memset(&state, 0, sizeof(state));
+ memset(&state, 0, sizeof(WriteTarState));
is_recovery_guc_supported =
PQserverVersion(conn) >= MINIMUM_VERSION_FOR_RECOVERY_GUC;
expect_unterminated_tarfile =
diff --git a/src/bin/pg_basebackup/pg_receivewal.c b/src/bin/pg_basebackup/pg_receivewal.c
index ea3902c971..7c19e2ee24 100644
--- a/src/bin/pg_basebackup/pg_receivewal.c
+++ b/src/bin/pg_basebackup/pg_receivewal.c
@@ -439,7 +439,7 @@ FindStreamingStart(uint32 *tli)
LZ4F_decompressOptions_t dec_opt;
LZ4F_errorCode_t status;
- memset(&dec_opt, 0, sizeof(dec_opt));
+ memset(&dec_opt, 0, sizeof(LZ4F_decompressOptions_t));
snprintf(fullpath, sizeof(fullpath), "%s/%s", basedir, dirent->d_name);
fd = open(fullpath, O_RDONLY | PG_BINARY, 0);
@@ -567,7 +567,7 @@ StreamLog(void)
StreamCtl stream;
char *sysidentifier;
- MemSet(&stream, 0, sizeof(stream));
+ MemSet(&stream, 0, sizeof(StreamCtl));
/*
* Connect in replication mode to the server
diff --git a/src/bin/pg_basebackup/walmethods.c b/src/bin/pg_basebackup/walmethods.c
index cc292718da..6c119a6757 100644
--- a/src/bin/pg_basebackup/walmethods.c
+++ b/src/bin/pg_basebackup/walmethods.c
@@ -179,7 +179,7 @@ dir_open_for_write(const char *pathname, const char *temp_suffix, size_t pad_to_
lz4buf = pg_malloc0(lz4bufsize);
/* assign the compression level, default is 0 */
- memset(&prefs, 0, sizeof(prefs));
+ memset(&prefs, 0, sizeof(LZ4F_preferences_t));
prefs.compressionLevel = dir_data->compression_level;
/* add the header */
diff --git a/src/bin/pg_ctl/pg_ctl.c b/src/bin/pg_ctl/pg_ctl.c
index dd78e5bc66..6e31fabb8d 100644
--- a/src/bin/pg_ctl/pg_ctl.c
+++ b/src/bin/pg_ctl/pg_ctl.c
@@ -1632,7 +1632,7 @@ pgwin32_ServiceMain(DWORD argc, LPTSTR *argv)
status.dwServiceSpecificExitCode = 0;
status.dwCurrentState = SERVICE_START_PENDING;
- memset(&pi, 0, sizeof(pi));
+ memset(&pi, 0, sizeof(PROCESS_INFORMATION));
read_post_opts();
diff --git a/src/bin/pg_verifybackup/pg_verifybackup.c b/src/bin/pg_verifybackup/pg_verifybackup.c
index bd18b4491d..9bb61ba6a2 100644
--- a/src/bin/pg_verifybackup/pg_verifybackup.c
+++ b/src/bin/pg_verifybackup/pg_verifybackup.c
@@ -182,7 +182,7 @@ main(int argc, char **argv)
set_pglocale_pgservice(argv[0], PG_TEXTDOMAIN("pg_verifybackup"));
progname = get_progname(argv[0]);
- memset(&context, 0, sizeof(context));
+ memset(&context, 0, sizeof(verifier_context));
if (argc > 1)
{
diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c
index b51d28780b..00a44e3589 100644
--- a/src/bin/psql/command.c
+++ b/src/bin/psql/command.c
@@ -5172,7 +5172,7 @@ do_watch(PQExpBuffer query_buf, double sleep)
#ifdef HAVE_POSIX_DECL_SIGWAIT
/* Disable the interval timer. */
- memset(&interval, 0, sizeof(interval));
+ memset(&interval, 0, sizeof(struct itimerval));
setitimer(ITIMER_REAL, &interval, NULL);
/* Unblock SIGINT, SIGCHLD and SIGALRM. */
sigprocmask(SIG_UNBLOCK, &sigalrm_sigchld_sigint, NULL);
diff --git a/src/bin/scripts/vacuumdb.c b/src/bin/scripts/vacuumdb.c
index 92f1ffe147..b444256482 100644
--- a/src/bin/scripts/vacuumdb.c
+++ b/src/bin/scripts/vacuumdb.c
@@ -127,7 +127,7 @@ main(int argc, char *argv[])
int tbl_count = 0;
/* initialize options */
- memset(&vacopts, 0, sizeof(vacopts));
+ memset(&vacopts, 0, sizeof(vacuumingOptions));
vacopts.parallel_workers = -1;
vacopts.no_index_cleanup = false;
vacopts.force_index_cleanup = false;
diff --git a/src/common/ip.c b/src/common/ip.c
index cd73d49679..771d752a8a 100644
--- a/src/common/ip.c
+++ b/src/common/ip.c
@@ -171,7 +171,7 @@ getaddrinfo_unix(const char *path, const struct addrinfo *hintsp,
*result = NULL;
- MemSet(&hints, 0, sizeof(hints));
+ MemSet(&hints, 0, sizeof(struct addrinfo));
if (strlen(path) >= sizeof(unp->sun_path))
return EAI_FAIL;
@@ -182,7 +182,7 @@ getaddrinfo_unix(const char *path, const struct addrinfo *hintsp,
hints.ai_socktype = SOCK_STREAM;
}
else
- memcpy(&hints, hintsp, sizeof(hints));
+ memcpy(&hints, hintsp, sizeof(struct addrinfo));
if (hints.ai_socktype == 0)
hints.ai_socktype = SOCK_STREAM;
diff --git a/src/interfaces/libpq/fe-auth.c b/src/interfaces/libpq/fe-auth.c
index 0a072a36dc..9c96c94d4a 100644
--- a/src/interfaces/libpq/fe-auth.c
+++ b/src/interfaces/libpq/fe-auth.c
@@ -737,12 +737,12 @@ pg_local_sendauth(PGconn *conn)
iov.iov_base = &buf;
iov.iov_len = 1;
- memset(&msg, 0, sizeof(msg));
+ memset(&msg, 0, sizeof(struct msghdr));
msg.msg_iov = &iov;
msg.msg_iovlen = 1;
/* We must set up a message that will be filled in by kernel */
- memset(&cmsgbuf, 0, sizeof(cmsgbuf));
+ memset(&cmsgbuf, 0, sizeof(struct cmsghdr));
msg.msg_control = &cmsgbuf.buf;
msg.msg_controllen = sizeof(cmsgbuf.buf);
cmsg = CMSG_FIRSTHDR(&msg);
diff --git a/src/interfaces/libpq/fe-connect.c b/src/interfaces/libpq/fe-connect.c
index 6e936bbff3..bb70a90d5e 100644
--- a/src/interfaces/libpq/fe-connect.c
+++ b/src/interfaces/libpq/fe-connect.c
@@ -2378,7 +2378,7 @@ keep_going: /* We will come back to here until there is
ch = &conn->connhost[conn->whichhost];
/* Initialize hint structure */
- MemSet(&hint, 0, sizeof(hint));
+ MemSet(&hint, 0, sizeof(struct addrinfo));
hint.ai_socktype = SOCK_STREAM;
conn->addrlist_family = hint.ai_family = AF_UNSPEC;
diff --git a/src/pl/plperl/plperl.c b/src/pl/plperl/plperl.c
index edb93ec1c4..c7c7930951 100644
--- a/src/pl/plperl/plperl.c
+++ b/src/pl/plperl/plperl.c
@@ -1844,7 +1844,7 @@ plperl_call_handler(PG_FUNCTION_ARGS)
plperl_call_data this_call_data;
/* Initialize current-call status record */
- MemSet(&this_call_data, 0, sizeof(this_call_data));
+ MemSet(&this_call_data, 0, sizeof(plperl_call_data));
this_call_data.fcinfo = fcinfo;
PG_TRY();
@@ -1890,7 +1890,7 @@ plperl_inline_handler(PG_FUNCTION_ARGS)
ErrorContextCallback pl_error_context;
/* Initialize current-call status record */
- MemSet(&this_call_data, 0, sizeof(this_call_data));
+ MemSet(&this_call_data, 0, sizeof(plperl_call_data));
/* Set up a callback for error reporting */
pl_error_context.callback = plperl_inline_callback;
@@ -1904,8 +1904,8 @@ plperl_inline_handler(PG_FUNCTION_ARGS)
* with no arguments passed, and a result type of VOID.
*/
MemSet(fake_fcinfo, 0, SizeForFunctionCallInfo(0));
- MemSet(&flinfo, 0, sizeof(flinfo));
- MemSet(&desc, 0, sizeof(desc));
+ MemSet(&flinfo, 0, sizeof(FmgrInfo));
+ MemSet(&desc, 0, sizeof(plperl_proc_desc));
fake_fcinfo->flinfo = &flinfo;
flinfo.fn_oid = InvalidOid;
flinfo.fn_mcxt = CurrentMemoryContext;
diff --git a/src/pl/plpgsql/src/pl_handler.c b/src/pl/plpgsql/src/pl_handler.c
index 190d286f1c..2b58c3202c 100644
--- a/src/pl/plpgsql/src/pl_handler.c
+++ b/src/pl/plpgsql/src/pl_handler.c
@@ -341,7 +341,7 @@ plpgsql_inline_handler(PG_FUNCTION_ARGS)
* with no arguments passed.
*/
MemSet(fake_fcinfo, 0, SizeForFunctionCallInfo(0));
- MemSet(&flinfo, 0, sizeof(flinfo));
+ MemSet(&flinfo, 0, sizeof(FmgrInfo));
fake_fcinfo->flinfo = &flinfo;
flinfo.fn_oid = InvalidOid;
flinfo.fn_mcxt = CurrentMemoryContext;
@@ -518,19 +518,19 @@ plpgsql_validator(PG_FUNCTION_ARGS)
* plpgsql_compile().
*/
MemSet(fake_fcinfo, 0, SizeForFunctionCallInfo(0));
- MemSet(&flinfo, 0, sizeof(flinfo));
+ MemSet(&flinfo, 0, sizeof(FmgrInfo));
fake_fcinfo->flinfo = &flinfo;
flinfo.fn_oid = funcoid;
flinfo.fn_mcxt = CurrentMemoryContext;
if (is_dml_trigger)
{
- MemSet(&trigdata, 0, sizeof(trigdata));
+ MemSet(&trigdata, 0, sizeof(TriggerData));
trigdata.type = T_TriggerData;
fake_fcinfo->context = (Node *) &trigdata;
}
else if (is_event_trigger)
{
- MemSet(&etrigdata, 0, sizeof(etrigdata));
+ MemSet(&etrigdata, 0, sizeof(EventTriggerData));
etrigdata.type = T_EventTriggerData;
fake_fcinfo->context = (Node *) &etrigdata;
}
diff --git a/src/pl/plpython/plpy_main.c b/src/pl/plpython/plpy_main.c
index 0bce106495..0d84d66684 100644
--- a/src/pl/plpython/plpy_main.c
+++ b/src/pl/plpython/plpy_main.c
@@ -278,7 +278,7 @@ plpython3_inline_handler(PG_FUNCTION_ARGS)
elog(ERROR, "SPI_connect failed");
MemSet(fcinfo, 0, SizeForFunctionCallInfo(0));
- MemSet(&flinfo, 0, sizeof(flinfo));
+ MemSet(&flinfo, 0, sizeof(FmgrInfo));
fake_fcinfo->flinfo = &flinfo;
flinfo.fn_oid = InvalidOid;
flinfo.fn_mcxt = CurrentMemoryContext;
diff --git a/src/port/getaddrinfo.c b/src/port/getaddrinfo.c
index 3284c6eb52..818fc6151d 100644
--- a/src/port/getaddrinfo.c
+++ b/src/port/getaddrinfo.c
@@ -146,12 +146,12 @@ getaddrinfo(const char *node, const char *service,
if (hintp == NULL)
{
- memset(&hints, 0, sizeof(hints));
+ memset(&hints, 0, sizeof(struct addrinfo));
hints.ai_family = AF_INET;
hints.ai_socktype = SOCK_STREAM;
}
else
- memcpy(&hints, hintp, sizeof(hints));
+ memcpy(&hints, hintp, sizeof(struct addrinfo));
if (hints.ai_family != AF_INET && hints.ai_family != AF_UNSPEC)
return EAI_FAMILY;
@@ -162,7 +162,7 @@ getaddrinfo(const char *node, const char *service,
if (!node && !service)
return EAI_NONAME;
- memset(&sin, 0, sizeof(sin));
+ memset(&sin, 0, sizeof(struct sockaddr_in));
sin.sin_family = AF_INET;
diff --git a/src/test/isolation/isolationtester.c b/src/test/isolation/isolationtester.c
index 12179f2514..c409694539 100644
--- a/src/test/isolation/isolationtester.c
+++ b/src/test/isolation/isolationtester.c
@@ -1121,7 +1121,7 @@ printResultSet(PGresult *res)
{
PQprintOpt popt;
- memset(&popt, 0, sizeof(popt));
+ memset(&popt, 0, sizeof(PQprintOpt));
popt.header = true;
popt.align = true;
popt.fieldSep = "|";
diff --git a/src/test/modules/test_shm_mq/setup.c b/src/test/modules/test_shm_mq/setup.c
index 6f1f4cf9c6..6a0e40db8e 100644
--- a/src/test/modules/test_shm_mq/setup.c
+++ b/src/test/modules/test_shm_mq/setup.c
@@ -212,7 +212,7 @@ setup_background_workers(int nworkers, dsm_segment *seg)
PointerGetDatum(wstate));
/* Configure a worker. */
- memset(&worker, 0, sizeof(worker));
+ memset(&worker, 0, sizeof(BackgroundWorker));
worker.bgw_flags = BGWORKER_SHMEM_ACCESS;
worker.bgw_start_time = BgWorkerStart_ConsistentState;
worker.bgw_restart_time = BGW_NEVER_RESTART;
diff --git a/src/test/modules/worker_spi/worker_spi.c b/src/test/modules/worker_spi/worker_spi.c
index 5b541ec47f..13c6afa694 100644
--- a/src/test/modules/worker_spi/worker_spi.c
+++ b/src/test/modules/worker_spi/worker_spi.c
@@ -325,7 +325,7 @@ _PG_init(void)
MarkGUCPrefixReserved("worker_spi");
/* set up common data for all our workers */
- memset(&worker, 0, sizeof(worker));
+ memset(&worker, 0, sizeof(BackgroundWorker));
worker.bgw_flags = BGWORKER_SHMEM_ACCESS |
BGWORKER_BACKEND_DATABASE_CONNECTION;
worker.bgw_start_time = BgWorkerStart_RecoveryFinished;
@@ -359,7 +359,7 @@ worker_spi_launch(PG_FUNCTION_ARGS)
BgwHandleStatus status;
pid_t pid;
- memset(&worker, 0, sizeof(worker));
+ memset(&worker, 0, sizeof(BackgroundWorker));
worker.bgw_flags = BGWORKER_SHMEM_ACCESS |
BGWORKER_BACKEND_DATABASE_CONNECTION;
worker.bgw_start_time = BgWorkerStart_RecoveryFinished;
diff --git a/src/test/regress/pg_regress.c b/src/test/regress/pg_regress.c
index 982801e029..66e8eae77c 100644
--- a/src/test/regress/pg_regress.c
+++ b/src/test/regress/pg_regress.c
@@ -1125,7 +1125,7 @@ spawn_process(const char *cmdline)
if (comspec == NULL)
comspec = "CMD";
- memset(&pi, 0, sizeof(pi));
+ memset(&pi, 0, sizeof(PROCESS_INFORMATION));
cmdline2 = psprintf("\"%s\" /c \"%s\"", comspec, cmdline);
if ((restrictedToken =
diff --git a/src/tools/msvc/MSBuildProject.pm b/src/tools/msvc/MSBuildProject.pm
index f24d9e5348..5e2a300127 100644
--- a/src/tools/msvc/MSBuildProject.pm
+++ b/src/tools/msvc/MSBuildProject.pm
@@ -331,7 +331,7 @@ sub WriteItemDefinitionGroup
<ObjectFileName>.\\$cfgname\\$self->{name}\\</ObjectFileName>
<ProgramDataBaseFileName>.\\$cfgname\\$self->{name}\\</ProgramDataBaseFileName>
<BrowseInformation>false</BrowseInformation>
- <WarningLevel>Level3</WarningLevel>
+ <WarningLevel>Level4</WarningLevel>
<SuppressStartupBanner>true</SuppressStartupBanner>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
<CompileAs>Default</CompileAs>
On Tue, May 17, 2022 at 07:52:30PM -0300, Ranier Vilela wrote:
I found, I believe, a serious problem of incorrect usage of the memset api.
Historically, people have relied on using memset or MemSet, using the
variable name as an argument for the sizeof.
While it works correctly, for arrays, when it comes to pointers to
structures, things go awry.
Knowing how sizeof() works is required before using it - the same is true for
pointers.
So throughout the code there are these misuses.
Why do you think it's a misuse ?
Take the first one as an example. It says:
GenericCosts costs;
MemSet(&costs, 0, sizeof(costs));
You sent a patch to change it to sizeof(GenericCosts).
But it's not a pointer, so they are the same.
Is that true for every change in your patch ?
--
Justin
Ranier Vilela <ranier.vf@gmail.com> writes:
I found, I believe, a serious problem of incorrect usage of the memset api.
Historically, people have relied on using memset or MemSet, using the
variable name as an argument for the sizeof.
While it works correctly, for arrays, when it comes to pointers to
structures, things go awry.
You'll have to convince people that any of these places are in
fact incorrect. Everyone who's used C for any length of time
is well aware of the possibility of getting sizeof() wrong in
this sort of context, and I think we've been careful about it.
Also, as a stylistic matter I think it's best to write
"memset(&x, 0, sizeof(x))" where we can. Replacing sizeof(x)
with sizeof(some type name) has its own risks of error, and
therefore is not automatically an improvement.
regards, tom lane
Em ter., 17 de mai. de 2022 às 20:18, Justin Pryzby <pryzby@telsasoft.com>
escreveu:
On Tue, May 17, 2022 at 07:52:30PM -0300, Ranier Vilela wrote:
I found, I believe, a serious problem of incorrect usage of the memset
api.
Historically, people have relied on using memset or MemSet, using the
variable name as an argument for the sizeof.
While it works correctly, for arrays, when it comes to pointers to
structures, things go awry.Knowing how sizeof() works is required before using it - the same is true
for
pointers.So throughout the code there are these misuses.
Why do you think it's a misuse ?
Take the first one as an example. It says:
GenericCosts costs;
MemSet(&costs, 0, sizeof(costs));You sent a patch to change it to sizeof(GenericCosts).
But it's not a pointer, so they are the same.
Is that true for every change in your patch ?
It seems true, sorry.
Thanks Justin for pointing out my big mistake.
I hope this isn't all wasted work, but should I remove the 002 patch.
regards,
Ranier Vilela
This one caught my attention:
diff --git a/contrib/pgcrypto/crypt-blowfish.c b/contrib/pgcrypto/crypt-blowfish.c
index a663852ccf..63fcef562d 100644
--- a/contrib/pgcrypto/crypt-blowfish.c
+++ b/contrib/pgcrypto/crypt-blowfish.c
@@ -750,7 +750,7 @@ _crypt_blowfish_rn(const char *key, const char *setting,
/* Overwrite the most obvious sensitive data we have on the stack. Note
* that this does not guarantee there's no sensitive data left on the
* stack and/or in registers; I'm not aware of portable code that does. */
- px_memset(&data, 0, sizeof(data));
+ px_memset(&data, 0, sizeof(struct data));
return output;
}
The curious thing here is that sizeof(data) is correct, because it
refers to a variable defined earlier in that function, whose type is an
anonymous struct declared there. But I don't know what "struct data"
refers to, precisely because that struct is unnamed. Am I misreading it?
Also:
diff --git a/contrib/pgstattuple/pgstatindex.c b/contrib/pgstattuple/pgstatindex.c
index e1048e47ff..87be62f023 100644
--- a/contrib/pgstattuple/pgstatindex.c
+++ b/contrib/pgstattuple/pgstatindex.c
@@ -601,7 +601,7 @@ pgstathashindex(PG_FUNCTION_ARGS)
errmsg("cannot access temporary indexes of other sessions")));
/* Get the information we need from the metapage. */
- memset(&stats, 0, sizeof(stats));
+ memset(&stats, 0, sizeof(HashIndexStat));
metabuf = _hash_getbuf(rel, HASH_METAPAGE, HASH_READ, LH_META_PAGE);
metap = HashPageGetMeta(BufferGetPage(metabuf));
stats.version = metap->hashm_version;
I think the working theory here is that the original line is correct
now, and it continues to be correct if somebody edits the function and
makes variable 'stats' be of a different type. But if you change the
sizeof() to use the type name, then there are two places that you need
to edit, and they are not necessarily close together; so it is correct
now and could become a bug in the future. I don't think we're fully
consistent about this, but I think you're proposing to change it in the
opposite direction that we'd prefer.
For the case where the variable is a pointer, the developer could write
'sizeof(*variable)' instead of being forced to specify the type name,
for example (just a random one):
diff --git a/contrib/bloom/blutils.c b/contrib/bloom/blutils.c
index a434cf93ef..e92c03686f 100644
--- a/contrib/bloom/blutils.c
+++ b/contrib/bloom/blutils.c
@@ -438,7 +438,7 @@ BloomFillMetapage(Relation index, Page metaPage)
*/
BloomInitPage(metaPage, BLOOM_META);
metadata = BloomPageGetMeta(metaPage);
- memset(metadata, 0, sizeof(BloomMetaPageData));
+ memset(metadata, 0, sizeof(*metadata));
metadata->magickNumber = BLOOM_MAGICK_NUMBER;
metadata->opts = *opts;
((PageHeader) metaPage)->pd_lower += sizeof(BloomMetaPageData);
--
Álvaro Herrera Breisgau, Deutschland — https://www.EnterpriseDB.com/
Em qua., 18 de mai. de 2022 às 05:54, Alvaro Herrera <
alvherre@alvh.no-ip.org> escreveu:
This one caught my attention:
diff --git a/contrib/pgcrypto/crypt-blowfish.c b/contrib/pgcrypto/crypt-blowfish.c index a663852ccf..63fcef562d 100644 --- a/contrib/pgcrypto/crypt-blowfish.c +++ b/contrib/pgcrypto/crypt-blowfish.c @@ -750,7 +750,7 @@ _crypt_blowfish_rn(const char *key, const char *setting, /* Overwrite the most obvious sensitive data we have on the stack. Note * that this does not guarantee there's no sensitive data left on the * stack and/or in registers; I'm not aware of portable code that does. */ - px_memset(&data, 0, sizeof(data)); + px_memset(&data, 0, sizeof(struct data));return output;
}The curious thing here is that sizeof(data) is correct, because it
refers to a variable defined earlier in that function, whose type is an
anonymous struct declared there. But I don't know what "struct data"
refers to, precisely because that struct is unnamed. Am I misreading it?
No, you are right.
This is definitely wrong.
Also:
diff --git a/contrib/pgstattuple/pgstatindex.c b/contrib/pgstattuple/pgstatindex.c index e1048e47ff..87be62f023 100644 --- a/contrib/pgstattuple/pgstatindex.c +++ b/contrib/pgstattuple/pgstatindex.c @@ -601,7 +601,7 @@ pgstathashindex(PG_FUNCTION_ARGS) errmsg("cannot access temporary indexes of other sessions")));/* Get the information we need from the metapage. */ - memset(&stats, 0, sizeof(stats)); + memset(&stats, 0, sizeof(HashIndexStat)); metabuf = _hash_getbuf(rel, HASH_METAPAGE, HASH_READ, LH_META_PAGE); metap = HashPageGetMeta(BufferGetPage(metabuf)); stats.version = metap->hashm_version;I think the working theory here is that the original line is correct
now, and it continues to be correct if somebody edits the function and
makes variable 'stats' be of a different type. But if you change the
sizeof() to use the type name, then there are two places that you need
to edit, and they are not necessarily close together; so it is correct
now and could become a bug in the future. I don't think we're fully
consistent about this, but I think you're proposing to change it in the
opposite direction that we'd prefer.
Yes. I think that only advantage using the name of structure is
when you read the line of MemSet, you know what kind type
is filled.
For the case where the variable is a pointer, the developer could write
'sizeof(*variable)' instead of being forced to specify the type name,
for example (just a random one):
Could have used this style to make the patch.
But the intention was to correct a possible misinterpretation,
which in this case, showed that I was totally wrong.
Sorry by the noise.
regards,
Ranier Vilela
On 18.05.22 01:18, Justin Pryzby wrote:
Take the first one as an example. It says:
GenericCosts costs;
MemSet(&costs, 0, sizeof(costs));You sent a patch to change it to sizeof(GenericCosts).
But it's not a pointer, so they are the same.
This instance can more easily be written as
costs = {0};
Em qua., 18 de mai. de 2022 às 10:52, Peter Eisentraut <
peter.eisentraut@enterprisedb.com> escreveu:
On 18.05.22 01:18, Justin Pryzby wrote:
Take the first one as an example. It says:
GenericCosts costs;
MemSet(&costs, 0, sizeof(costs));You sent a patch to change it to sizeof(GenericCosts).
But it's not a pointer, so they are the same.
This instance can more easily be written as
costs = {0};
That would initialize the content at compilation and not at runtime,
correct?
And we would avoid MemSet/memset altogether.
There are a lot of cases using MemSet (with struct variables) and at
Windows 64 bits, long are 4 (four) bytes.
So I believe that MemSet is less efficient on Windows than on Linux.
"The size of the '_vstart' buffer is not a multiple of the element size of
the type 'long'."
message from PVS-Studio static analysis tool.
regards,
Ranier Vilela
On Thu, 19 May 2022 at 02:08, Ranier Vilela <ranier.vf@gmail.com> wrote:
That would initialize the content at compilation and not at runtime, correct?
Your mental model of compilation and run-time might be flawed here.
Here's no such thing as zeroing memory at compile time. There's only
emitting instructions that perform those tasks at run-time.
https://godbolt.org/ might help your understanding.
There are a lot of cases using MemSet (with struct variables) and at Windows 64 bits, long are 4 (four) bytes.
So I believe that MemSet is less efficient on Windows than on Linux.
"The size of the '_vstart' buffer is not a multiple of the element size of the type 'long'."
message from PVS-Studio static analysis tool.
I've been wondering for a while if we really need to have the MemSet()
macro. I see it was added in 8cb415449 (1997). I think compilers have
evolved quite a bit in the past 25 years, so it could be time to
revisit that.
Your comment on the sizeof(long) on win64 is certainly true. I wrote
the attached C program to test the performance difference.
(windows 64-bit)
cl memset.c /Ox
memset 200000000
Running 200000000 loops
MemSet: size 8: 1.833000 seconds
MemSet: size 16: 1.841000 seconds
MemSet: size 32: 1.838000 seconds
MemSet: size 64: 1.851000 seconds
MemSet: size 128: 3.228000 seconds
MemSet: size 256: 5.278000 seconds
MemSet: size 512: 3.943000 seconds
memset: size 8: 0.065000 seconds
memset: size 16: 0.131000 seconds
memset: size 32: 0.262000 seconds
memset: size 64: 0.530000 seconds
memset: size 128: 1.169000 seconds
memset: size 256: 2.950000 seconds
memset: size 512: 3.191000 seconds
It seems like there's no cases there where MemSet is faster than
memset. I was careful to only provide MemSet() with inputs that
result in it not using the memset fallback. I also provided constants
so that the decision about which method to use was known at compile
time.
It's not clear to me why 512 is faster than 256. I saw the same on a repeat run.
Changing "long" to "long long" it looks like:
memset 200000000
Running 200000000 loops
MemSet: size 8: 0.066000 seconds
MemSet: size 16: 1.978000 seconds
MemSet: size 32: 1.982000 seconds
MemSet: size 64: 1.973000 seconds
MemSet: size 128: 1.970000 seconds
MemSet: size 256: 3.225000 seconds
MemSet: size 512: 5.366000 seconds
memset: size 8: 0.069000 seconds
memset: size 16: 0.132000 seconds
memset: size 32: 0.265000 seconds
memset: size 64: 0.527000 seconds
memset: size 128: 1.161000 seconds
memset: size 256: 2.976000 seconds
memset: size 512: 3.179000 seconds
The situation is a little different on my Linux machine:
$ gcc memset.c -o memset -O2
$ ./memset 200000000
Running 200000000 loops
MemSet: size 8: 0.000002 seconds
MemSet: size 16: 0.000000 seconds
MemSet: size 32: 0.094041 seconds
MemSet: size 64: 0.184618 seconds
MemSet: size 128: 1.781503 seconds
MemSet: size 256: 2.547910 seconds
MemSet: size 512: 4.005173 seconds
memset: size 8: 0.046156 seconds
memset: size 16: 0.046123 seconds
memset: size 32: 0.092291 seconds
memset: size 64: 0.184509 seconds
memset: size 128: 1.781518 seconds
memset: size 256: 2.577104 seconds
memset: size 512: 4.004757 seconds
It looks like part of the work might be getting optimised away in the
8-16 MemSet() calls.
clang seems to have the opposite for size 8.
$ clang memset.c -o memset -O2
$ ./memset 200000000
Running 200000000 loops
MemSet: size 8: 0.007653 seconds
MemSet: size 16: 0.005771 seconds
MemSet: size 32: 0.011539 seconds
MemSet: size 64: 0.023095 seconds
MemSet: size 128: 0.046130 seconds
MemSet: size 256: 0.092269 seconds
MemSet: size 512: 0.968564 seconds
memset: size 8: 0.000000 seconds
memset: size 16: 0.005776 seconds
memset: size 32: 0.011559 seconds
memset: size 64: 0.023069 seconds
memset: size 128: 0.046129 seconds
memset: size 256: 0.092243 seconds
memset: size 512: 0.968534 seconds
There does not seem to be any significant reduction in the size of the
binary from changing the MemSet macro to directly use memset. It went
from 9865008 bytes down to 9860800 bytes (4208 bytes less).
David
Attachments:
David Rowley <dgrowleyml@gmail.com> writes:
I've been wondering for a while if we really need to have the MemSet()
macro. I see it was added in 8cb415449 (1997). I think compilers have
evolved quite a bit in the past 25 years, so it could be time to
revisit that.
Yeah, I've thought for awhile that technology has moved on from that.
Nobody's really taken the trouble to measure it though. (And no,
results from one compiler on one machine are not terribly convincing.)
The thing that makes this a bit more difficult than it might be is
the special cases we have for known-aligned and so on targets, which
are particularly critical for palloc0 and makeNode etc. So there's
more than one case to look into. But I'd argue that those special
cases are actually what we want to worry about the most: zeroing
relatively small, known-aligned node structs is THE use case.
regards, tom lane
Em qua., 18 de mai. de 2022 às 19:57, David Rowley <dgrowleyml@gmail.com>
escreveu:
On Thu, 19 May 2022 at 02:08, Ranier Vilela <ranier.vf@gmail.com> wrote:
That would initialize the content at compilation and not at runtime,
correct?
Your mental model of compilation and run-time might be flawed here.
Here's no such thing as zeroing memory at compile time. There's only
emitting instructions that perform those tasks at run-time.
https://godbolt.org/ might help your understanding.There are a lot of cases using MemSet (with struct variables) and at
Windows 64 bits, long are 4 (four) bytes.
So I believe that MemSet is less efficient on Windows than on Linux.
"The size of the '_vstart' buffer is not a multiple of the element sizeof the type 'long'."
message from PVS-Studio static analysis tool.
I've been wondering for a while if we really need to have the MemSet()
macro. I see it was added in 8cb415449 (1997). I think compilers have
evolved quite a bit in the past 25 years, so it could be time to
revisit that.
+1
All compilers currently have memset optimized.
Your comment on the sizeof(long) on win64 is certainly true. I wrote
the attached C program to test the performance difference.(windows 64-bit)
cl memset.c /Ox
memset 200000000Running 200000000 loops
MemSet: size 8: 1.833000 seconds
MemSet: size 16: 1.841000 seconds
MemSet: size 32: 1.838000 seconds
MemSet: size 64: 1.851000 seconds
MemSet: size 128: 3.228000 seconds
MemSet: size 256: 5.278000 seconds
MemSet: size 512: 3.943000 seconds
memset: size 8: 0.065000 seconds
memset: size 16: 0.131000 seconds
memset: size 32: 0.262000 seconds
memset: size 64: 0.530000 seconds
memset: size 128: 1.169000 seconds
memset: size 256: 2.950000 seconds
memset: size 512: 3.191000 secondsIt seems like there's no cases there where MemSet is faster than
memset. I was careful to only provide MemSet() with inputs that
result in it not using the memset fallback. I also provided constants
so that the decision about which method to use was known at compile
time.It's not clear to me why 512 is faster than 256.
Probably broken alignment with 256?
Another warning from PVS-Studio:
[1]: https://pvs-studio.com/en/docs/warnings/v1032/
src/contrib/postgres_fdw/connection.c (Line 1690)
MemSet(values, 0, sizeof(values));
I saw the same on a repeat run.
Changing "long" to "long long" it looks like:
memset 200000000
Running 200000000 loops
MemSet: size 8: 0.066000 seconds
MemSet: size 16: 1.978000 seconds
MemSet: size 32: 1.982000 seconds
MemSet: size 64: 1.973000 seconds
MemSet: size 128: 1.970000 seconds
MemSet: size 256: 3.225000 seconds
MemSet: size 512: 5.366000 seconds
memset: size 8: 0.069000 seconds
memset: size 16: 0.132000 seconds
memset: size 32: 0.265000 seconds
memset: size 64: 0.527000 seconds
memset: size 128: 1.161000 seconds
memset: size 256: 2.976000 seconds
memset: size 512: 3.179000 secondsThe situation is a little different on my Linux machine:
$ gcc memset.c -o memset -O2
$ ./memset 200000000
Running 200000000 loops
MemSet: size 8: 0.000002 seconds
MemSet: size 16: 0.000000 seconds
MemSet: size 32: 0.094041 seconds
MemSet: size 64: 0.184618 seconds
MemSet: size 128: 1.781503 seconds
MemSet: size 256: 2.547910 seconds
MemSet: size 512: 4.005173 seconds
memset: size 8: 0.046156 seconds
memset: size 16: 0.046123 seconds
memset: size 32: 0.092291 seconds
memset: size 64: 0.184509 seconds
memset: size 128: 1.781518 seconds
memset: size 256: 2.577104 seconds
memset: size 512: 4.004757 secondsIt looks like part of the work might be getting optimised away in the
8-16 MemSet() calls.
On linux (long) have 8 bytes.
I'm still surprised that MemSet (8/16) is faster.
clang seems to have the opposite for size 8.
$ clang memset.c -o memset -O2
$ ./memset 200000000
Running 200000000 loops
MemSet: size 8: 0.007653 seconds
MemSet: size 16: 0.005771 seconds
MemSet: size 32: 0.011539 seconds
MemSet: size 64: 0.023095 seconds
MemSet: size 128: 0.046130 seconds
MemSet: size 256: 0.092269 seconds
MemSet: size 512: 0.968564 seconds
memset: size 8: 0.000000 seconds
memset: size 16: 0.005776 seconds
memset: size 32: 0.011559 seconds
memset: size 64: 0.023069 seconds
memset: size 128: 0.046129 seconds
memset: size 256: 0.092243 seconds
memset: size 512: 0.968534 secondsThere does not seem to be any significant reduction in the size of the
binary from changing the MemSet macro to directly use memset. It went
from 9865008 bytes down to 9860800 bytes (4208 bytes less).
Anyway I think on Windows 64 bits,
it is very worthwhile to remove the MemSet macro.
regards,
Ranier Vilela
Em qua., 18 de mai. de 2022 às 20:20, Tom Lane <tgl@sss.pgh.pa.us> escreveu:
zeroing
relatively small, known-aligned node structs is THE use case.
Currently, especially on 64-bit Windows, MemSet can break alignment.
regards,
Ranier Vilela
Em qua., 18 de mai. de 2022 às 19:57, David Rowley <dgrowleyml@gmail.com>
escreveu:
On Thu, 19 May 2022 at 02:08, Ranier Vilela <ranier.vf@gmail.com> wrote:
That would initialize the content at compilation and not at runtime,
correct?
Your mental model of compilation and run-time might be flawed here.
Here's no such thing as zeroing memory at compile time. There's only
emitting instructions that perform those tasks at run-time.
https://godbolt.org/ might help your understanding.There are a lot of cases using MemSet (with struct variables) and at
Windows 64 bits, long are 4 (four) bytes.
So I believe that MemSet is less efficient on Windows than on Linux.
"The size of the '_vstart' buffer is not a multiple of the element sizeof the type 'long'."
message from PVS-Studio static analysis tool.
I've been wondering for a while if we really need to have the MemSet()
macro. I see it was added in 8cb415449 (1997). I think compilers have
evolved quite a bit in the past 25 years, so it could be time to
revisit that.Your comment on the sizeof(long) on win64 is certainly true. I wrote
the attached C program to test the performance difference.(windows 64-bit)
cl memset.c /Ox
memset 200000000Running 200000000 loops
MemSet: size 8: 1.833000 seconds
MemSet: size 16: 1.841000 seconds
MemSet: size 32: 1.838000 seconds
MemSet: size 64: 1.851000 seconds
MemSet: size 128: 3.228000 seconds
MemSet: size 256: 5.278000 seconds
MemSet: size 512: 3.943000 seconds
memset: size 8: 0.065000 seconds
memset: size 16: 0.131000 seconds
memset: size 32: 0.262000 seconds
memset: size 64: 0.530000 seconds
memset: size 128: 1.169000 seconds
memset: size 256: 2.950000 seconds
memset: size 512: 3.191000 secondsIt seems like there's no cases there where MemSet is faster than
memset. I was careful to only provide MemSet() with inputs that
result in it not using the memset fallback. I also provided constants
so that the decision about which method to use was known at compile
time.It's not clear to me why 512 is faster than 256. I saw the same on a
repeat run.Changing "long" to "long long" it looks like:
memset 200000000
Running 200000000 loops
MemSet: size 8: 0.066000 seconds
MemSet: size 16: 1.978000 seconds
MemSet: size 32: 1.982000 seconds
MemSet: size 64: 1.973000 seconds
MemSet: size 128: 1.970000 seconds
MemSet: size 256: 3.225000 seconds
MemSet: size 512: 5.366000 seconds
memset: size 8: 0.069000 seconds
memset: size 16: 0.132000 seconds
memset: size 32: 0.265000 seconds
memset: size 64: 0.527000 seconds
memset: size 128: 1.161000 seconds
memset: size 256: 2.976000 seconds
memset: size 512: 3.179000 secondsThe situation is a little different on my Linux machine:
$ gcc memset.c -o memset -O2
$ ./memset 200000000
Running 200000000 loops
MemSet: size 8: 0.000002 seconds
MemSet: size 16: 0.000000 seconds
MemSet: size 32: 0.094041 seconds
MemSet: size 64: 0.184618 seconds
MemSet: size 128: 1.781503 seconds
MemSet: size 256: 2.547910 seconds
MemSet: size 512: 4.005173 seconds
memset: size 8: 0.046156 seconds
memset: size 16: 0.046123 seconds
memset: size 32: 0.092291 seconds
memset: size 64: 0.184509 seconds
memset: size 128: 1.781518 seconds
memset: size 256: 2.577104 seconds
memset: size 512: 4.004757 secondsIt looks like part of the work might be getting optimised away in the
8-16 MemSet() calls.clang seems to have the opposite for size 8.
$ clang memset.c -o memset -O2
$ ./memset 200000000
Running 200000000 loops
MemSet: size 8: 0.007653 seconds
MemSet: size 16: 0.005771 seconds
MemSet: size 32: 0.011539 seconds
MemSet: size 64: 0.023095 seconds
MemSet: size 128: 0.046130 seconds
MemSet: size 256: 0.092269 seconds
MemSet: size 512: 0.968564 seconds
memset: size 8: 0.000000 seconds
memset: size 16: 0.005776 seconds
memset: size 32: 0.011559 seconds
memset: size 64: 0.023069 seconds
memset: size 128: 0.046129 seconds
memset: size 256: 0.092243 seconds
memset: size 512: 0.968534 seconds
The results from clang, only reinforce the argument in favor of native
memset.
There is still room for gcc to improve with 8/16 bytes and for sure at some
point they will.
Which will make memset faster on all platforms and compilers.
regards,
Ranier Vilela
Taking it a step further.
Created a new patch into commitfest, targeting 16 version.
https://commitfest.postgresql.org/38/3645/
Currently native memset is well optimized on several platforms, including
Windows 64 bits [1]https://msrc-blog.microsoft.com/2021/01/11/building-faster-amd64-memset-routines/.
However, even the native memset has problems,
I redid the David's memset.c test:
C:\usr\src\tests\memset>memset2 2000000000
Running 2000000000 loops
MemSet: size 8: 6.635000 seconds
MemSet: size 16: 6.594000 seconds
MemSet: size 32: 6.694000 seconds
MemSet: size 64: 9.002000 seconds
MemSet: size 128: 10.598000 seconds
MemSet: size 256: 25.061000 seconds
MemSet: size 512: 27.365000 seconds
memset: size 8: 0.594000 seconds
memset: size 16: 0.595000 seconds
memset: size 32: 1.189000 seconds
memset: size 64: 2.378000 seconds
memset: size 128: 4.753000 seconds
memset: size 256: 24.391000 seconds
memset: size 512: 27.064000 seconds
Both MemSet/memset perform very poorly with 256/512.
But, I believe it is worth removing the use of MemSet, because the usage is
empirical and has been mixed with memset in several places in the code,
without any criteria.
Using just memset makes the mental process of using it more simplified and
it seems like there aren't any regressions when removing the use of MemSet.
Windows 10 64 bit
msvc 2019 64 bit
RAM 8GB
SSD 256GB
Postgres (15beta1 with original configuration)
1. pgbench -c 50 -T 300 -S -n -U postgres
HEAD:
pgbench (15beta1)
transaction type: <builtin: select only>
scaling factor: 1
query mode: simple
number of clients: 50
number of threads: 1
maximum number of tries: 1
duration: 300 s
number of transactions actually processed: 10448967
number of failed transactions: 0 (0.000%)
latency average = 1.432 ms
initial connection time = 846.186 ms
tps = 34926.861987 (without initial connection time)
PATCHED (without MemSet)
pgbench (15beta1)
transaction type: <builtin: select only>
scaling factor: 1
query mode: simple
number of clients: 50
number of threads: 1
maximum number of tries: 1
duration: 300 s
number of transactions actually processed: 10655332
number of failed transactions: 0 (0.000%)
latency average = 1.404 ms
initial connection time = 866.203 ms
tps = 35621.045750 (without initial connection time)
2.
CREATE TABLE t_test (x numeric);
INSERT INTO t_test SELECT random()
FROM generate_series(1, 5000000);
ANALYZE;
SHOW work_mem;
HEAD:
postgres=# explain analyze SELECT * FROM t_test ORDER BY x;
QUERY PLAN
----------------------------------------------------------------------------------------------------------------------------------------
Gather Merge (cost=397084.73..883229.71 rows=4166666 width=11) (actual
time=1328.331..2743.310 rows=5000000 loops=1)
Workers Planned: 2
Workers Launched: 2
-> Sort (cost=396084.71..401293.04 rows=2083333 width=11) (actual
time=1278.442..1513.510 rows=1666667 loops=3)
Sort Key: x
Sort Method: external merge Disk: 25704kB
Worker 0: Sort Method: external merge Disk: 23960kB
Worker 1: Sort Method: external merge Disk: 23960kB
-> Parallel Seq Scan on t_test (cost=0.00..47861.33 rows=2083333
width=11) (actual time=0.234..128.607 rows=1666667 loops=3)
Planning Time: 0.064 ms
Execution Time: 2863.381 ms
(11 rows)
PATCHED:
postgres=# explain analyze SELECT * FROM t_test ORDER BY x;
QUERY PLAN
----------------------------------------------------------------------------------------------------------------------------------------
Gather Merge (cost=397084.73..883229.71 rows=4166666 width=11) (actual
time=1309.703..2705.027 rows=5000000 loops=1)
Workers Planned: 2
Workers Launched: 2
-> Sort (cost=396084.71..401293.04 rows=2083333 width=11) (actual
time=1281.111..1515.928 rows=1666667 loops=3)
Sort Key: x
Sort Method: external merge Disk: 24880kB
Worker 0: Sort Method: external merge Disk: 24776kB
Worker 1: Sort Method: external merge Disk: 23960kB
-> Parallel Seq Scan on t_test (cost=0.00..47861.33 rows=2083333
width=11) (actual time=0.260..130.277 rows=1666667 loops=3)
Planning Time: 0.060 ms
Execution Time: 2825.201 ms
(11 rows)
I leave MemSetAligned and MemSetLoop to another step.
regards,
Ranier Vilela
[1]: https://msrc-blog.microsoft.com/2021/01/11/building-faster-amd64-memset-routines/
https://msrc-blog.microsoft.com/2021/01/11/building-faster-amd64-memset-routines/
Attachments:
001_avoid_unecessary_memset_call.patchapplication/octet-stream; name=001_avoid_unecessary_memset_call.patchDownload
diff --git a/src/backend/utils/cache/relcache.c b/src/backend/utils/cache/relcache.c
index 60e72f9e8b..6da7a5cf7f 100644
--- a/src/backend/utils/cache/relcache.c
+++ b/src/backend/utils/cache/relcache.c
@@ -6265,7 +6265,7 @@ load_relcache_init_file(bool shared)
rel->rd_firstRelfilenodeSubid = InvalidSubTransactionId;
rel->rd_droppedSubid = InvalidSubTransactionId;
rel->rd_amcache = NULL;
- MemSet(&rel->pgstat_info, 0, sizeof(rel->pgstat_info));
+ rel->pgstat_info = NULL;002_refactoring_memset_api_usage.patchapplication/octet-stream; name=002_refactoring_memset_api_usage.patchDownload
diff --git a/contrib/amcheck/verify_heapam.c b/contrib/amcheck/verify_heapam.c
index c875f3e5a2..71defb9cc6 100644
--- a/contrib/amcheck/verify_heapam.c
+++ b/contrib/amcheck/verify_heapam.c
@@ -558,8 +558,8 @@ report_corruption_internal(Tuplestorestate *tupstore, TupleDesc tupdesc,
bool nulls[HEAPCHECK_RELATION_COLS];
HeapTuple tuple;
- MemSet(values, 0, sizeof(values));
- MemSet(nulls, 0, sizeof(nulls));
+ memset(values, 0, sizeof(values));
+ memset(nulls, 0, sizeof(nulls));
values[0] = Int64GetDatum(blkno);
values[1] = Int32GetDatum(offnum);
values[2] = Int32GetDatum(attnum);
diff --git a/contrib/bloom/blcost.c b/contrib/bloom/blcost.c
index d42e4e9628..cf3291375e 100644
--- a/contrib/bloom/blcost.c
+++ b/contrib/bloom/blcost.c
@@ -28,7 +28,7 @@ blcostestimate(PlannerInfo *root, IndexPath *path, double loop_count,
IndexOptInfo *index = path->indexinfo;
GenericCosts costs;
- MemSet(&costs, 0, sizeof(costs));
+ memset(&costs, 0, sizeof(costs));
/* We have to visit all index tuples anyway */
costs.numIndexTuples = index->tuples;
diff --git a/contrib/hstore/hstore_gist.c b/contrib/hstore/hstore_gist.c
index 102c9cea72..016bfa4a4c 100644
--- a/contrib/hstore/hstore_gist.c
+++ b/contrib/hstore/hstore_gist.c
@@ -459,7 +459,7 @@ ghstore_picksplit(PG_FUNCTION_ARGS)
if (ISALLTRUE(datum_l) || ISALLTRUE(_j))
{
if (!ISALLTRUE(datum_l))
- MemSet((void *) union_l, 0xff, siglen);
+ memset((void *) union_l, 0xff, siglen);
}
else
{
@@ -475,7 +475,7 @@ ghstore_picksplit(PG_FUNCTION_ARGS)
if (ISALLTRUE(datum_r) || ISALLTRUE(_j))
{
if (!ISALLTRUE(datum_r))
- MemSet((void *) union_r, 0xff, siglen);
+ memset((void *) union_r, 0xff, siglen);
}
else
{
diff --git a/contrib/hstore/hstore_io.c b/contrib/hstore/hstore_io.c
index b3304ff844..2c871c6d93 100644
--- a/contrib/hstore/hstore_io.c
+++ b/contrib/hstore/hstore_io.c
@@ -841,7 +841,7 @@ hstore_from_record(PG_FUNCTION_ARGS)
if (my_extra->record_type != tupType ||
my_extra->record_typmod != tupTypmod)
{
- MemSet(my_extra, 0,
+ memset(my_extra, 0,
offsetof(RecordIOData, columns) +
ncolumns * sizeof(ColumnIOData));
my_extra->record_type = tupType;
@@ -1035,7 +1035,7 @@ hstore_populate_record(PG_FUNCTION_ARGS)
if (my_extra->record_type != tupType ||
my_extra->record_typmod != tupTypmod)
{
- MemSet(my_extra, 0,
+ memset(my_extra, 0,
offsetof(RecordIOData, columns) +
ncolumns * sizeof(ColumnIOData));
my_extra->record_type = tupType;
diff --git a/contrib/intarray/_intbig_gist.c b/contrib/intarray/_intbig_gist.c
index 18ecd8cda6..c9d8f9b84d 100644
--- a/contrib/intarray/_intbig_gist.c
+++ b/contrib/intarray/_intbig_gist.c
@@ -420,7 +420,7 @@ g_intbig_picksplit(PG_FUNCTION_ARGS)
if (ISALLTRUE(datum_l) || ISALLTRUE(_j))
{
if (!ISALLTRUE(datum_l))
- MemSet((void *) union_l, 0xff, siglen);
+ memset((void *) union_l, 0xff, siglen);
}
else
{
@@ -436,7 +436,7 @@ g_intbig_picksplit(PG_FUNCTION_ARGS)
if (ISALLTRUE(datum_r) || ISALLTRUE(_j))
{
if (!ISALLTRUE(datum_r))
- MemSet((void *) union_r, 0xff, siglen);
+ memset((void *) union_r, 0xff, siglen);
}
else
{
diff --git a/contrib/ltree/_ltree_gist.c b/contrib/ltree/_ltree_gist.c
index 72516c3b6b..2dc59f8a0f 100644
--- a/contrib/ltree/_ltree_gist.c
+++ b/contrib/ltree/_ltree_gist.c
@@ -345,7 +345,7 @@ _ltree_picksplit(PG_FUNCTION_ARGS)
if (LTG_ISALLTRUE(datum_l) || LTG_ISALLTRUE(_j))
{
if (!LTG_ISALLTRUE(datum_l))
- MemSet((void *) union_l, 0xff, siglen);
+ memset((void *) union_l, 0xff, siglen);
}
else
{
@@ -361,7 +361,7 @@ _ltree_picksplit(PG_FUNCTION_ARGS)
if (LTG_ISALLTRUE(datum_r) || LTG_ISALLTRUE(_j))
{
if (!LTG_ISALLTRUE(datum_r))
- MemSet((void *) union_r, 0xff, siglen);
+ memset((void *) union_r, 0xff, siglen);
}
else
{
diff --git a/contrib/oid2name/oid2name.c b/contrib/oid2name/oid2name.c
index a62a5eedb1..a3e358bb1b 100644
--- a/contrib/oid2name/oid2name.c
+++ b/contrib/oid2name/oid2name.c
@@ -424,7 +424,7 @@ sql_exec(PGconn *conn, const char *todo, bool quiet)
}
fprintf(stdout, "\n");
pad = (char *) pg_malloc(l + 1);
- MemSet(pad, '-', l);
+ memset(pad, '-', l);
pad[l] = '\0';
fprintf(stdout, "%s\n", pad);
free(pad);
diff --git a/contrib/pageinspect/brinfuncs.c b/contrib/pageinspect/brinfuncs.c
index 879276e6de..b82cb2b5a1 100644
--- a/contrib/pageinspect/brinfuncs.c
+++ b/contrib/pageinspect/brinfuncs.c
@@ -230,7 +230,7 @@ brin_page_items(PG_FUNCTION_ARGS)
else
attno++;
- MemSet(nulls, 0, sizeof(nulls));
+ memset(nulls, 0, sizeof(nulls));
if (unusedItem)
{
@@ -354,7 +354,7 @@ brin_metapage_info(PG_FUNCTION_ARGS)
/* Extract values from the metapage */
meta = (BrinMetaPageData *) PageGetContents(page);
- MemSet(nulls, 0, sizeof(nulls));
+ memset(nulls, 0, sizeof(nulls));
values[0] = CStringGetTextDatum(psprintf("0x%08X", meta->brinMagic));
values[1] = Int32GetDatum(meta->brinVersion);
values[2] = Int32GetDatum(meta->pagesPerRange);
diff --git a/contrib/pageinspect/hashfuncs.c b/contrib/pageinspect/hashfuncs.c
index 69af7b962f..4ae6bc0518 100644
--- a/contrib/pageinspect/hashfuncs.c
+++ b/contrib/pageinspect/hashfuncs.c
@@ -261,7 +261,7 @@ hash_page_stats(PG_FUNCTION_ARGS)
elog(ERROR, "return type must be a row type");
tupleDesc = BlessTupleDesc(tupleDesc);
- MemSet(nulls, 0, sizeof(nulls));
+ memset(nulls, 0, sizeof(nulls));
j = 0;
values[j++] = Int32GetDatum(stat.live_items);
@@ -361,7 +361,7 @@ hash_page_items(PG_FUNCTION_ARGS)
itup = (IndexTuple) PageGetItem(uargs->page, id);
- MemSet(nulls, 0, sizeof(nulls));
+ memset(nulls, 0, sizeof(nulls));
j = 0;
values[j++] = Int32GetDatum((int32) uargs->offset);
@@ -495,7 +495,7 @@ hash_bitmap_info(PG_FUNCTION_ARGS)
elog(ERROR, "return type must be a row type");
tupleDesc = BlessTupleDesc(tupleDesc);
- MemSet(nulls, 0, sizeof(nulls));
+ memset(nulls, 0, sizeof(nulls));
j = 0;
values[j++] = Int64GetDatum((int64) bitmapblkno);
@@ -544,7 +544,7 @@ hash_metapage_info(PG_FUNCTION_ARGS)
metad = HashPageGetMeta(page);
- MemSet(nulls, 0, sizeof(nulls));
+ memset(nulls, 0, sizeof(nulls));
j = 0;
values[j++] = Int64GetDatum((int64) metad->hashm_magic);
diff --git a/contrib/pageinspect/heapfuncs.c b/contrib/pageinspect/heapfuncs.c
index 3dd1a9bc2a..dac5b78efe 100644
--- a/contrib/pageinspect/heapfuncs.c
+++ b/contrib/pageinspect/heapfuncs.c
@@ -531,8 +531,8 @@ heap_tuple_infomask_flags(PG_FUNCTION_ARGS)
pg_popcount((const char *) &t_infomask2, sizeof(uint16));
/* Initialize values and NULL flags arrays */
- MemSet(values, 0, sizeof(values));
- MemSet(nulls, 0, sizeof(nulls));
+ memset(values, 0, sizeof(values));
+ memset(nulls, 0, sizeof(nulls));
/* If no flags, return a set of empty arrays */
if (bitcnt <= 0)
@@ -598,7 +598,7 @@ heap_tuple_infomask_flags(PG_FUNCTION_ARGS)
* keeps the code simple.
*/
cnt = 0;
- MemSet(flags, 0, sizeof(Datum) * bitcnt);
+ memset(flags, 0, sizeof(Datum) * bitcnt);
/* decode combined masks of t_infomask */
if ((t_infomask & HEAP_XMAX_SHR_LOCK) == HEAP_XMAX_SHR_LOCK)
diff --git a/contrib/pg_prewarm/autoprewarm.c b/contrib/pg_prewarm/autoprewarm.c
index c0c4f5d9ca..9daeb06950 100644
--- a/contrib/pg_prewarm/autoprewarm.c
+++ b/contrib/pg_prewarm/autoprewarm.c
@@ -819,7 +819,7 @@ apw_start_leader_worker(void)
BgwHandleStatus status;
pid_t pid;
- MemSet(&worker, 0, sizeof(BackgroundWorker));
+ memset(&worker, 0, sizeof(BackgroundWorker));
worker.bgw_flags = BGWORKER_SHMEM_ACCESS;
worker.bgw_start_time = BgWorkerStart_ConsistentState;
strcpy(worker.bgw_library_name, "pg_prewarm");
@@ -859,7 +859,7 @@ apw_start_database_worker(void)
BackgroundWorker worker;
BackgroundWorkerHandle *handle;
- MemSet(&worker, 0, sizeof(BackgroundWorker));
+ memset(&worker, 0, sizeof(BackgroundWorker));
worker.bgw_flags =
BGWORKER_SHMEM_ACCESS | BGWORKER_BACKEND_DATABASE_CONNECTION;
worker.bgw_start_time = BgWorkerStart_ConsistentState;
diff --git a/contrib/pg_stat_statements/pg_stat_statements.c b/contrib/pg_stat_statements/pg_stat_statements.c
index 768cedd91a..cdf1267c0a 100644
--- a/contrib/pg_stat_statements/pg_stat_statements.c
+++ b/contrib/pg_stat_statements/pg_stat_statements.c
@@ -1869,8 +1869,8 @@ pg_stat_statements_info(PG_FUNCTION_ARGS)
if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE)
elog(ERROR, "return type must be a row type");
- MemSet(values, 0, sizeof(values));
- MemSet(nulls, 0, sizeof(nulls));
+ memset(values, 0, sizeof(values));
+ memset(nulls, 0, sizeof(nulls));
/* Read global statistics for pg_stat_statements */
{
diff --git a/contrib/pg_trgm/trgm_gist.c b/contrib/pg_trgm/trgm_gist.c
index 6f28db7d1e..36f4f41019 100644
--- a/contrib/pg_trgm/trgm_gist.c
+++ b/contrib/pg_trgm/trgm_gist.c
@@ -95,7 +95,7 @@ makesign(BITVECP sign, TRGM *a, int siglen)
trgm *ptr = GETARR(a);
int32 tmp = 0;
- MemSet((void *) sign, 0, siglen);
+ memset((void *) sign, 0, siglen);
SETBIT(sign, SIGLENBIT(siglen)); /* set last unused bit */
for (k = 0; k < len; k++)
{
@@ -914,7 +914,7 @@ gtrgm_picksplit(PG_FUNCTION_ARGS)
if (ISALLTRUE(datum_l) || cache[j].allistrue)
{
if (!ISALLTRUE(datum_l))
- MemSet((void *) GETSIGN(datum_l), 0xff, siglen);
+ memset((void *) GETSIGN(datum_l), 0xff, siglen);
}
else
{
@@ -930,7 +930,7 @@ gtrgm_picksplit(PG_FUNCTION_ARGS)
if (ISALLTRUE(datum_r) || cache[j].allistrue)
{
if (!ISALLTRUE(datum_r))
- MemSet((void *) GETSIGN(datum_r), 0xff, siglen);
+ memset((void *) GETSIGN(datum_r), 0xff, siglen);
}
else
{
diff --git a/contrib/pg_trgm/trgm_regexp.c b/contrib/pg_trgm/trgm_regexp.c
index 58d32ba946..0eabafdd0f 100644
--- a/contrib/pg_trgm/trgm_regexp.c
+++ b/contrib/pg_trgm/trgm_regexp.c
@@ -926,7 +926,7 @@ transformGraph(TrgmNFA *trgmNFA)
trgmNFA->nstates = 0;
/* Create initial state: ambiguous prefix, NFA's initial state */
- MemSet(&initkey, 0, sizeof(initkey));
+ memset(&initkey, 0, sizeof(initkey));
initkey.prefix.colors[0] = COLOR_UNKNOWN;
initkey.prefix.colors[1] = COLOR_UNKNOWN;
initkey.nstate = pg_reg_getinitialstate(trgmNFA->regex);
@@ -1028,7 +1028,7 @@ addKey(TrgmNFA *trgmNFA, TrgmState *state, TrgmStateKey *key)
* Ensure any pad bytes in destKey are zero, since it may get used as a
* hashtable key by getState.
*/
- MemSet(&destKey, 0, sizeof(destKey));
+ memset(&destKey, 0, sizeof(destKey));
/*
* Compare key to each existing enter key of the state to check for
@@ -1209,7 +1209,7 @@ addArcs(TrgmNFA *trgmNFA, TrgmState *state)
* Ensure any pad bytes in destKey are zero, since it may get used as a
* hashtable key by getState.
*/
- MemSet(&destKey, 0, sizeof(destKey));
+ memset(&destKey, 0, sizeof(destKey));
/*
* Iterate over enter keys associated with this expanded-graph state. This
diff --git a/contrib/pg_visibility/pg_visibility.c b/contrib/pg_visibility/pg_visibility.c
index 1853c354e3..fbb37bd003 100644
--- a/contrib/pg_visibility/pg_visibility.c
+++ b/contrib/pg_visibility/pg_visibility.c
@@ -88,7 +88,7 @@ pg_visibility_map(PG_FUNCTION_ARGS)
errmsg("invalid block number")));
tupdesc = pg_visibility_tupdesc(false, false);
- MemSet(nulls, 0, sizeof(nulls));
+ memset(nulls, 0, sizeof(nulls));
mapbits = (int32) visibilitymap_get_status(rel, blkno, &vmbuffer);
if (vmbuffer != InvalidBuffer)
@@ -130,7 +130,7 @@ pg_visibility(PG_FUNCTION_ARGS)
errmsg("invalid block number")));
tupdesc = pg_visibility_tupdesc(false, true);
- MemSet(nulls, 0, sizeof(nulls));
+ memset(nulls, 0, sizeof(nulls));
mapbits = (int32) visibilitymap_get_status(rel, blkno, &vmbuffer);
if (vmbuffer != InvalidBuffer)
@@ -191,7 +191,7 @@ pg_visibility_map_rel(PG_FUNCTION_ARGS)
bool nulls[3];
HeapTuple tuple;
- MemSet(nulls, 0, sizeof(nulls));
+ memset(nulls, 0, sizeof(nulls));
values[0] = Int64GetDatum(info->next);
values[1] = BoolGetDatum((info->bits[info->next] & (1 << 0)) != 0);
values[2] = BoolGetDatum((info->bits[info->next] & (1 << 1)) != 0);
@@ -236,7 +236,7 @@ pg_visibility_rel(PG_FUNCTION_ARGS)
bool nulls[4];
HeapTuple tuple;
- MemSet(nulls, 0, sizeof(nulls));
+ memset(nulls, 0, sizeof(nulls));
values[0] = Int64GetDatum(info->next);
values[1] = BoolGetDatum((info->bits[info->next] & (1 << 0)) != 0);
values[2] = BoolGetDatum((info->bits[info->next] & (1 << 1)) != 0);
@@ -300,7 +300,7 @@ pg_visibility_map_summary(PG_FUNCTION_ARGS)
TupleDescInitEntry(tupdesc, (AttrNumber) 2, "all_frozen", INT8OID, -1, 0);
tupdesc = BlessTupleDesc(tupdesc);
- MemSet(nulls, 0, sizeof(nulls));
+ memset(nulls, 0, sizeof(nulls));
values[0] = Int64GetDatum(all_visible);
values[1] = Int64GetDatum(all_frozen);
diff --git a/contrib/pg_walinspect/pg_walinspect.c b/contrib/pg_walinspect/pg_walinspect.c
index a082dfb331..7589f80b0e 100644
--- a/contrib/pg_walinspect/pg_walinspect.c
+++ b/contrib/pg_walinspect/pg_walinspect.c
@@ -266,8 +266,8 @@ pg_get_wal_record_info(PG_FUNCTION_ARGS)
errmsg("could not read WAL at %X/%X",
LSN_FORMAT_ARGS(first_record))));
- MemSet(values, 0, sizeof(values));
- MemSet(nulls, 0, sizeof(nulls));
+ memset(values, 0, sizeof(values));
+ memset(nulls, 0, sizeof(nulls));
GetWALRecordInfo(xlogreader, first_record, values, nulls,
PG_GET_WAL_RECORD_INFO_COLS);
@@ -343,8 +343,8 @@ GetWALRecordsInfo(FunctionCallInfo fcinfo, XLogRecPtr start_lsn,
Assert(xlogreader);
- MemSet(values, 0, sizeof(values));
- MemSet(nulls, 0, sizeof(nulls));
+ memset(values, 0, sizeof(values));
+ memset(nulls, 0, sizeof(nulls));
while (ReadNextXLogRecord(xlogreader, first_record) &&
xlogreader->EndRecPtr <= end_lsn)
@@ -565,7 +565,7 @@ GetWalStats(FunctionCallInfo fcinfo, XLogRecPtr start_lsn,
xlogreader = InitXLogReaderState(start_lsn, &first_record);
- MemSet(&stats, 0, sizeof(stats));
+ memset(&stats, 0, sizeof(stats));
while (ReadNextXLogRecord(xlogreader, first_record) &&
xlogreader->EndRecPtr <= end_lsn)
@@ -578,8 +578,8 @@ GetWalStats(FunctionCallInfo fcinfo, XLogRecPtr start_lsn,
pfree(xlogreader->private_data);
XLogReaderFree(xlogreader);
- MemSet(values, 0, sizeof(values));
- MemSet(nulls, 0, sizeof(nulls));
+ memset(values, 0, sizeof(values));
+ memset(nulls, 0, sizeof(nulls));
GetXLogSummaryStats(&stats, rsinfo, values, nulls,
PG_GET_WAL_STATS_COLS,
diff --git a/contrib/pgstattuple/pgstatindex.c b/contrib/pgstattuple/pgstatindex.c
index e1048e47ff..eae3909664 100644
--- a/contrib/pgstattuple/pgstatindex.c
+++ b/contrib/pgstattuple/pgstatindex.c
@@ -697,7 +697,7 @@ pgstathashindex(PG_FUNCTION_ARGS)
/*
* Build and return the tuple
*/
- MemSet(nulls, 0, sizeof(nulls));
+ memset(nulls, 0, sizeof(nulls));
values[0] = Int32GetDatum(stats.version);
values[1] = Int64GetDatum((int64) stats.bucket_pages);
values[2] = Int64GetDatum((int64) stats.overflow_pages);
diff --git a/contrib/postgres_fdw/connection.c b/contrib/postgres_fdw/connection.c
index 061ffaf329..aa6dbac347 100644
--- a/contrib/postgres_fdw/connection.c
+++ b/contrib/postgres_fdw/connection.c
@@ -1687,8 +1687,8 @@ postgres_fdw_get_connections(PG_FUNCTION_ARGS)
server = GetForeignServerExtended(entry->serverid, FSV_MISSING_OK);
- MemSet(values, 0, sizeof(values));
- MemSet(nulls, 0, sizeof(nulls));
+ memset(values, 0, sizeof(values));
+ memset(nulls, 0, sizeof(nulls));
/*
* The foreign server may have been dropped in current explicit
diff --git a/contrib/postgres_fdw/postgres_fdw.c b/contrib/postgres_fdw/postgres_fdw.c
index d56951153b..38b5c46f40 100644
--- a/contrib/postgres_fdw/postgres_fdw.c
+++ b/contrib/postgres_fdw/postgres_fdw.c
@@ -3332,7 +3332,7 @@ estimate_path_cost_size(PlannerInfo *root,
input_rows = ofpinfo->rows;
/* Collect statistics about aggregates for estimating costs. */
- MemSet(&aggcosts, 0, sizeof(AggClauseCosts));
+ memset(&aggcosts, 0, sizeof(AggClauseCosts));
if (root->parse->hasAggs)
{
get_agg_clause_costs(root, AGGSPLIT_SIMPLE, &aggcosts);
diff --git a/contrib/tablefunc/tablefunc.c b/contrib/tablefunc/tablefunc.c
index e308228bde..bd6f6614f6 100644
--- a/contrib/tablefunc/tablefunc.c
+++ b/contrib/tablefunc/tablefunc.c
@@ -129,7 +129,7 @@ typedef struct crosstab_cat_desc
do { \
crosstab_HashEnt *hentry; char key[MAX_CATNAME_LEN]; \
\
- MemSet(key, 0, MAX_CATNAME_LEN); \
+ memset(key, 0, MAX_CATNAME_LEN); \
snprintf(key, MAX_CATNAME_LEN - 1, "%s", CATNAME); \
hentry = (crosstab_HashEnt*) hash_search(HASHTAB, \
key, HASH_FIND, NULL); \
@@ -143,7 +143,7 @@ do { \
do { \
crosstab_HashEnt *hentry; bool found; char key[MAX_CATNAME_LEN]; \
\
- MemSet(key, 0, MAX_CATNAME_LEN); \
+ memset(key, 0, MAX_CATNAME_LEN); \
snprintf(key, MAX_CATNAME_LEN - 1, "%s", CATDESC->catname); \
hentry = (crosstab_HashEnt*) hash_search(HASHTAB, \
key, HASH_ENTER, &found); \
diff --git a/src/backend/access/common/scankey.c b/src/backend/access/common/scankey.c
index ff2b608f2e..2355ac54ef 100644
--- a/src/backend/access/common/scankey.c
+++ b/src/backend/access/common/scankey.c
@@ -51,7 +51,7 @@ ScanKeyEntryInitialize(ScanKey entry,
else
{
Assert(flags & (SK_SEARCHNULL | SK_SEARCHNOTNULL));
- MemSet(&entry->sk_func, 0, sizeof(entry->sk_func));
+ memset(&entry->sk_func, 0, sizeof(entry->sk_func));
}
}
diff --git a/src/backend/access/common/tupdesc.c b/src/backend/access/common/tupdesc.c
index 9f41b1e854..8eb8575a5d 100644
--- a/src/backend/access/common/tupdesc.c
+++ b/src/backend/access/common/tupdesc.c
@@ -611,7 +611,7 @@ TupleDescInitEntry(TupleDesc desc,
* attributes. Also, do nothing if caller wants to re-use the old attname.
*/
if (attributeName == NULL)
- MemSet(NameStr(att->attname), 0, NAMEDATALEN);
+ memset(NameStr(att->attname), 0, NAMEDATALEN);
else if (attributeName != NameStr(att->attname))
namestrcpy(&(att->attname), attributeName);
diff --git a/src/backend/access/gin/ginutil.c b/src/backend/access/gin/ginutil.c
index 3d15701a01..01a365aad6 100644
--- a/src/backend/access/gin/ginutil.c
+++ b/src/backend/access/gin/ginutil.c
@@ -98,7 +98,7 @@ initGinState(GinState *state, Relation index)
TupleDesc origTupdesc = RelationGetDescr(index);
int i;
- MemSet(state, 0, sizeof(GinState));
+ memset(state, 0, sizeof(GinState));
state->index = index;
state->oneCol = (origTupdesc->natts == 1);
diff --git a/src/backend/access/hash/hashovfl.c b/src/backend/access/hash/hashovfl.c
index e34cfc302d..86aa48d520 100644
--- a/src/backend/access/hash/hashovfl.c
+++ b/src/backend/access/hash/hashovfl.c
@@ -760,7 +760,7 @@ _hash_initbitmapbuffer(Buffer buf, uint16 bmsize, bool initpage)
/* set all of the bits to 1 */
freep = HashPageGetBitmap(pg);
- MemSet(freep, 0xFF, bmsize);
+ memset(freep, 0xFF, bmsize);
/*
* Set pd_lower just past the end of the bitmap page data. We could even
diff --git a/src/backend/access/hash/hashpage.c b/src/backend/access/hash/hashpage.c
index 39206d1942..3f31dad231 100644
--- a/src/backend/access/hash/hashpage.c
+++ b/src/backend/access/hash/hashpage.c
@@ -572,8 +572,8 @@ _hash_init_metabuffer(Buffer buf, double num_tuples, RegProcedure procid,
metap->hashm_highmask = pg_nextpower2_32(num_buckets + 1) - 1;
metap->hashm_lowmask = (metap->hashm_highmask >> 1);
- MemSet(metap->hashm_spares, 0, sizeof(metap->hashm_spares));
- MemSet(metap->hashm_mapp, 0, sizeof(metap->hashm_mapp));
+ memset(metap->hashm_spares, 0, sizeof(metap->hashm_spares));
+ memset(metap->hashm_mapp, 0, sizeof(metap->hashm_mapp));
/* Set up mapping for one spare page after the initial splitpoints */
metap->hashm_spares[spare_index] = 1;
diff --git a/src/backend/access/heap/heapam.c b/src/backend/access/heap/heapam.c
index 7421851027..dffa798aad 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -9141,7 +9141,7 @@ heap_xlog_insert(XLogReaderState *record)
data += SizeOfHeapHeader;
htup = &tbuf.hdr;
- MemSet((char *) htup, 0, SizeofHeapTupleHeader);
+ memset((char *) htup, 0, SizeofHeapTupleHeader);
/* PG73FORMAT: get bitmap [+ padding] [+ oid] + data */
memcpy((char *) htup + SizeofHeapTupleHeader,
data,
@@ -9282,7 +9282,7 @@ heap_xlog_multi_insert(XLogReaderState *record)
newlen = xlhdr->datalen;
Assert(newlen <= MaxHeapTupleSize);
htup = &tbuf.hdr;
- MemSet((char *) htup, 0, SizeofHeapTupleHeader);
+ memset((char *) htup, 0, SizeofHeapTupleHeader);
/* PG73FORMAT: get bitmap [+ padding] [+ oid] + data */
memcpy((char *) htup + SizeofHeapTupleHeader,
(char *) tupdata,
@@ -9518,7 +9518,7 @@ heap_xlog_update(XLogReaderState *record, bool hot_update)
Assert(tuplen <= MaxHeapTupleSize);
htup = &tbuf.hdr;
- MemSet((char *) htup, 0, SizeofHeapTupleHeader);
+ memset((char *) htup, 0, SizeofHeapTupleHeader);
/*
* Reconstruct the new tuple using the prefix and/or suffix from the
diff --git a/src/backend/access/heap/pruneheap.c b/src/backend/access/heap/pruneheap.c
index 9f43bbe25f..c375c01804 100644
--- a/src/backend/access/heap/pruneheap.c
+++ b/src/backend/access/heap/pruneheap.c
@@ -1113,7 +1113,7 @@ heap_get_root_tuples(Page page, OffsetNumber *root_offsets)
OffsetNumber offnum,
maxoff;
- MemSet(root_offsets, InvalidOffsetNumber,
+ memset(root_offsets, InvalidOffsetNumber,
MaxHeapTuplesPerPage * sizeof(OffsetNumber));
maxoff = PageGetMaxOffsetNumber(page);
diff --git a/src/backend/access/heap/visibilitymap.c b/src/backend/access/heap/visibilitymap.c
index e09f25a684..f3fa73df81 100644
--- a/src/backend/access/heap/visibilitymap.c
+++ b/src/backend/access/heap/visibilitymap.c
@@ -494,7 +494,7 @@ visibilitymap_prepare_truncate(Relation rel, BlockNumber nheapblocks)
START_CRIT_SECTION();
/* Clear out the unwanted bytes. */
- MemSet(&map[truncByte + 1], 0, MAPSIZE - (truncByte + 1));
+ memset(&map[truncByte + 1], 0, MAPSIZE - (truncByte + 1));
/*----
* Mask out the unwanted bits of the last remaining byte.
diff --git a/src/backend/access/nbtree/nbtpage.c b/src/backend/access/nbtree/nbtpage.c
index 20adb602a4..129c4383ae 100644
--- a/src/backend/access/nbtree/nbtpage.c
+++ b/src/backend/access/nbtree/nbtpage.c
@@ -2220,7 +2220,7 @@ _bt_mark_page_halfdead(Relation rel, Buffer leafbuf, BTStack stack)
opaque->btpo_flags |= BTP_HALF_DEAD;
Assert(PageGetMaxOffsetNumber(page) == P_HIKEY);
- MemSet(&trunctuple, 0, sizeof(IndexTupleData));
+ memset(&trunctuple, 0, sizeof(IndexTupleData));
trunctuple.t_info = sizeof(IndexTupleData);
if (topparent != leafblkno)
BTreeTupleSetTopParent(&trunctuple, topparent);
diff --git a/src/backend/access/nbtree/nbtxlog.c b/src/backend/access/nbtree/nbtxlog.c
index f9186ca233..e40b586e97 100644
--- a/src/backend/access/nbtree/nbtxlog.c
+++ b/src/backend/access/nbtree/nbtxlog.c
@@ -780,7 +780,7 @@ btree_xlog_mark_page_halfdead(uint8 info, XLogReaderState *record)
* Construct a dummy high key item that points to top parent page (value
* is InvalidBlockNumber when the top parent page is the leaf page itself)
*/
- MemSet(&trunctuple, 0, sizeof(IndexTupleData));
+ memset(&trunctuple, 0, sizeof(IndexTupleData));
trunctuple.t_info = sizeof(IndexTupleData);
BTreeTupleSetTopParent(&trunctuple, xlrec->topparent);
@@ -915,7 +915,7 @@ btree_xlog_unlink_page(uint8 info, XLogReaderState *record)
pageop->btpo_cycleid = 0;
/* Add a dummy hikey item */
- MemSet(&trunctuple, 0, sizeof(IndexTupleData));
+ memset(&trunctuple, 0, sizeof(IndexTupleData));
trunctuple.t_info = sizeof(IndexTupleData);
BTreeTupleSetTopParent(&trunctuple, xlrec->leaftopparent);
diff --git a/src/backend/access/transam/clog.c b/src/backend/access/transam/clog.c
index 3d9088a704..7e655c49b6 100644
--- a/src/backend/access/transam/clog.c
+++ b/src/backend/access/transam/clog.c
@@ -804,7 +804,7 @@ TrimCLOG(void)
/* Zero so-far-unused positions in the current byte */
*byteptr &= (1 << bshift) - 1;
/* Zero the rest of the page */
- MemSet(byteptr + 1, 0, BLCKSZ - byteno - 1);
+ memset(byteptr + 1, 0, BLCKSZ - byteno - 1);
XactCtl->shared->page_dirty[slotno] = true;
}
diff --git a/src/backend/access/transam/multixact.c b/src/backend/access/transam/multixact.c
index 8f7d12950e..8b52f73800 100644
--- a/src/backend/access/transam/multixact.c
+++ b/src/backend/access/transam/multixact.c
@@ -1872,7 +1872,7 @@ MultiXactShmemInit(void)
Assert(!found);
/* Make sure we zero out the per-backend state */
- MemSet(MultiXactState, 0, SHARED_MULTIXACT_STATE_SIZE);
+ memset(MultiXactState, 0, SHARED_MULTIXACT_STATE_SIZE);
}
else
Assert(found);
@@ -2072,7 +2072,7 @@ TrimMultiXact(void)
offptr = (MultiXactOffset *) MultiXactOffsetCtl->shared->page_buffer[slotno];
offptr += entryno;
- MemSet(offptr, 0, BLCKSZ - (entryno * sizeof(MultiXactOffset)));
+ memset(offptr, 0, BLCKSZ - (entryno * sizeof(MultiXactOffset)));
MultiXactOffsetCtl->shared->page_dirty[slotno] = true;
}
@@ -2104,7 +2104,7 @@ TrimMultiXact(void)
xidptr = (TransactionId *)
(MultiXactMemberCtl->shared->page_buffer[slotno] + memberoff);
- MemSet(xidptr, 0, BLCKSZ - memberoff);
+ memset(xidptr, 0, BLCKSZ - memberoff);
/*
* Note: we don't need to zero out the flag bits in the remaining
diff --git a/src/backend/access/transam/slru.c b/src/backend/access/transam/slru.c
index b65cb49d7f..3781af2dee 100644
--- a/src/backend/access/transam/slru.c
+++ b/src/backend/access/transam/slru.c
@@ -296,7 +296,7 @@ SimpleLruZeroPage(SlruCtl ctl, int pageno)
SlruRecentlyUsed(shared, slotno);
/* Set the buffer to zeroes */
- MemSet(shared->page_buffer[slotno], 0, BLCKSZ);
+ memset(shared->page_buffer[slotno], 0, BLCKSZ);
/* Set the LSNs for this new page to zero */
SimpleLruZeroLSNs(ctl, slotno);
@@ -326,7 +326,7 @@ SimpleLruZeroLSNs(SlruCtl ctl, int slotno)
SlruShared shared = ctl->shared;
if (shared->lsn_groups_per_page > 0)
- MemSet(&shared->group_lsn[slotno * shared->lsn_groups_per_page], 0,
+ memset(&shared->group_lsn[slotno * shared->lsn_groups_per_page], 0,
shared->lsn_groups_per_page * sizeof(XLogRecPtr));
}
@@ -712,7 +712,7 @@ SlruPhysicalReadPage(SlruCtl ctl, int pageno, int slotno)
ereport(LOG,
(errmsg("file \"%s\" doesn't exist, reading as zeroes",
path)));
- MemSet(shared->page_buffer[slotno], 0, BLCKSZ);
+ memset(shared->page_buffer[slotno], 0, BLCKSZ);
return true;
}
diff --git a/src/backend/access/transam/twophase.c b/src/backend/access/transam/twophase.c
index 75551f60cb..1fd2e20ece 100644
--- a/src/backend/access/transam/twophase.c
+++ b/src/backend/access/transam/twophase.c
@@ -459,7 +459,7 @@ MarkAsPreparingGuts(GlobalTransaction gxact, TransactionId xid, const char *gid,
proc = &ProcGlobal->allProcs[gxact->pgprocno];
/* Initialize the PGPROC entry */
- MemSet(proc, 0, sizeof(PGPROC));
+ memset(proc, 0, sizeof(PGPROC));
proc->pgprocno = gxact->pgprocno;
SHMQueueElemInit(&(proc->links));
proc->waitStatus = PROC_WAIT_STATUS_OK;
@@ -791,8 +791,8 @@ pg_prepared_xact(PG_FUNCTION_ARGS)
/*
* Form tuple with appropriate data.
*/
- MemSet(values, 0, sizeof(values));
- MemSet(nulls, 0, sizeof(nulls));
+ memset(values, 0, sizeof(values));
+ memset(nulls, 0, sizeof(nulls));
values[0] = TransactionIdGetDatum(proc->xid);
values[1] = CStringGetTextDatum(gxact->gid);
diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c
index 71136b11a2..46a24d5a73 100644
--- a/src/backend/access/transam/xlog.c
+++ b/src/backend/access/transam/xlog.c
@@ -1280,7 +1280,7 @@ CopyXLogRecordToWAL(int write_len, bool isLogSwitch, XLogRecData *rdata,
* and zero most of the page. Then we just zero the page header.
*/
currpos = GetXLogBuffer(CurrPos, tli);
- MemSet(currpos, 0, SizeOfXLogShortPHD);
+ memset(currpos, 0, SizeOfXLogShortPHD);
CurrPos += XLOG_BLCKSZ;
}
@@ -1868,7 +1868,7 @@ AdvanceXLInsertBuffer(XLogRecPtr upto, TimeLineID tli, bool opportunistic)
* Be sure to re-zero the buffer so that bytes beyond what we've
* written will look like zeroes and not valid XLOG records...
*/
- MemSet((char *) NewPage, 0, XLOG_BLCKSZ);
+ memset((char *) NewPage, 0, XLOG_BLCKSZ);
/*
* Fill the new page's header
@@ -6302,7 +6302,7 @@ CreateCheckPoint(int flags)
* checkpoint proceeds, we always accumulate stats, even if
* log_checkpoints is currently off.
*/
- MemSet(&CheckpointStats, 0, sizeof(CheckpointStats));
+ memset(&CheckpointStats, 0, sizeof(CheckpointStats));
CheckpointStats.ckpt_start_t = GetCurrentTimestamp();
/*
@@ -6327,7 +6327,7 @@ CreateCheckPoint(int flags)
}
/* Begin filling in the checkpoint WAL record */
- MemSet(&checkPoint, 0, sizeof(checkPoint));
+ memset(&checkPoint, 0, sizeof(checkPoint));
checkPoint.time = (pg_time_t) time(NULL);
/*
@@ -6999,7 +6999,7 @@ CreateRestartPoint(int flags)
* checkpoint proceeds, we always accumulate stats, even if
* log_checkpoints is currently off.
*/
- MemSet(&CheckpointStats, 0, sizeof(CheckpointStats));
+ memset(&CheckpointStats, 0, sizeof(CheckpointStats));
CheckpointStats.ckpt_start_t = GetCurrentTimestamp();
if (log_checkpoints)
diff --git a/src/backend/access/transam/xlogfuncs.c b/src/backend/access/transam/xlogfuncs.c
index 02bd919ff6..7bc2fa360a 100644
--- a/src/backend/access/transam/xlogfuncs.c
+++ b/src/backend/access/transam/xlogfuncs.c
@@ -117,8 +117,8 @@ pg_backup_stop(PG_FUNCTION_ARGS)
if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE)
elog(ERROR, "return type must be a row type");
- MemSet(values, 0, sizeof(values));
- MemSet(nulls, 0, sizeof(nulls));
+ memset(values, 0, sizeof(values));
+ memset(nulls, 0, sizeof(nulls));
if (status != SESSION_BACKUP_RUNNING)
ereport(ERROR,
diff --git a/src/backend/access/transam/xloginsert.c b/src/backend/access/transam/xloginsert.c
index 2ce9be2cc7..5255401524 100644
--- a/src/backend/access/transam/xloginsert.c
+++ b/src/backend/access/transam/xloginsert.c
@@ -204,7 +204,7 @@ XLogEnsureRecordSpace(int max_block_id, int ndatas)
* At least the padding bytes in the structs must be zeroed, because
* they are included in WAL data, but initialize it all for tidiness.
*/
- MemSet(®istered_buffers[max_registered_buffers], 0,
+ memset(®istered_buffers[max_registered_buffers], 0,
(nbuffers - max_registered_buffers) * sizeof(registered_buffer));
max_registered_buffers = nbuffers;
}
diff --git a/src/backend/access/transam/xlogreader.c b/src/backend/access/transam/xlogreader.c
index cf5db23cb8..28dc1e02c5 100644
--- a/src/backend/access/transam/xlogreader.c
+++ b/src/backend/access/transam/xlogreader.c
@@ -2093,7 +2093,7 @@ RestoreBlockImage(XLogReaderState *record, uint8 block_id, char *page)
{
memcpy(page, ptr, bkpb->hole_offset);
/* must zero-fill the hole */
- MemSet(page + bkpb->hole_offset, 0, bkpb->hole_length);
+ memset(page + bkpb->hole_offset, 0, bkpb->hole_length);
memcpy(page + (bkpb->hole_offset + bkpb->hole_length),
ptr + bkpb->hole_offset,
BLCKSZ - (bkpb->hole_offset + bkpb->hole_length));
diff --git a/src/backend/bootstrap/bootstrap.c b/src/backend/bootstrap/bootstrap.c
index 9fa8fdd4cf..9cf2f1348c 100644
--- a/src/backend/bootstrap/bootstrap.c
+++ b/src/backend/bootstrap/bootstrap.c
@@ -513,7 +513,7 @@ DefineAttr(char *name, char *type, int attnum, int nullness)
if (attrtypes[attnum] == NULL)
attrtypes[attnum] = AllocateAttribute();
- MemSet(attrtypes[attnum], 0, ATTRIBUTE_FIXED_PART_SIZE);
+ memset(attrtypes[attnum], 0, ATTRIBUTE_FIXED_PART_SIZE);
namestrcpy(&attrtypes[attnum]->attname, name);
elog(DEBUG4, "column %s %s", NameStr(attrtypes[attnum]->attname), type);
diff --git a/src/backend/catalog/aclchk.c b/src/backend/catalog/aclchk.c
index 5f1726c095..2bc981ace0 100644
--- a/src/backend/catalog/aclchk.c
+++ b/src/backend/catalog/aclchk.c
@@ -1344,9 +1344,9 @@ SetDefaultACL(InternalDefaultACL *iacls)
Oid defAclOid;
/* Prepare to insert or update pg_default_acl entry */
- MemSet(values, 0, sizeof(values));
- MemSet(nulls, false, sizeof(nulls));
- MemSet(replaces, false, sizeof(replaces));
+ memset(values, 0, sizeof(values));
+ memset(nulls, false, sizeof(nulls));
+ memset(replaces, false, sizeof(replaces));
if (isNew)
{
@@ -1745,9 +1745,9 @@ ExecGrant_Attribute(InternalGrant *istmt, Oid relOid, const char *relname,
nnewmembers = aclmembers(new_acl, &newmembers);
/* finished building new ACL value, now insert it */
- MemSet(values, 0, sizeof(values));
- MemSet(nulls, false, sizeof(nulls));
- MemSet(replaces, false, sizeof(replaces));
+ memset(values, 0, sizeof(values));
+ memset(nulls, false, sizeof(nulls));
+ memset(replaces, false, sizeof(replaces));
/*
* If the updated ACL is empty, we can set attacl to null, and maybe even
@@ -2027,9 +2027,9 @@ ExecGrant_Relation(InternalGrant *istmt)
nnewmembers = aclmembers(new_acl, &newmembers);
/* finished building new ACL value, now insert it */
- MemSet(values, 0, sizeof(values));
- MemSet(nulls, false, sizeof(nulls));
- MemSet(replaces, false, sizeof(replaces));
+ memset(values, 0, sizeof(values));
+ memset(nulls, false, sizeof(nulls));
+ memset(replaces, false, sizeof(replaces));
replaces[Anum_pg_class_relacl - 1] = true;
values[Anum_pg_class_relacl - 1] = PointerGetDatum(new_acl);
@@ -2217,9 +2217,9 @@ ExecGrant_Database(InternalGrant *istmt)
nnewmembers = aclmembers(new_acl, &newmembers);
/* finished building new ACL value, now insert it */
- MemSet(values, 0, sizeof(values));
- MemSet(nulls, false, sizeof(nulls));
- MemSet(replaces, false, sizeof(replaces));
+ memset(values, 0, sizeof(values));
+ memset(nulls, false, sizeof(nulls));
+ memset(replaces, false, sizeof(replaces));
replaces[Anum_pg_database_datacl - 1] = true;
values[Anum_pg_database_datacl - 1] = PointerGetDatum(new_acl);
@@ -2339,9 +2339,9 @@ ExecGrant_Fdw(InternalGrant *istmt)
nnewmembers = aclmembers(new_acl, &newmembers);
/* finished building new ACL value, now insert it */
- MemSet(values, 0, sizeof(values));
- MemSet(nulls, false, sizeof(nulls));
- MemSet(replaces, false, sizeof(replaces));
+ memset(values, 0, sizeof(values));
+ memset(nulls, false, sizeof(nulls));
+ memset(replaces, false, sizeof(replaces));
replaces[Anum_pg_foreign_data_wrapper_fdwacl - 1] = true;
values[Anum_pg_foreign_data_wrapper_fdwacl - 1] = PointerGetDatum(new_acl);
@@ -2465,9 +2465,9 @@ ExecGrant_ForeignServer(InternalGrant *istmt)
nnewmembers = aclmembers(new_acl, &newmembers);
/* finished building new ACL value, now insert it */
- MemSet(values, 0, sizeof(values));
- MemSet(nulls, false, sizeof(nulls));
- MemSet(replaces, false, sizeof(replaces));
+ memset(values, 0, sizeof(values));
+ memset(nulls, false, sizeof(nulls));
+ memset(replaces, false, sizeof(replaces));
replaces[Anum_pg_foreign_server_srvacl - 1] = true;
values[Anum_pg_foreign_server_srvacl - 1] = PointerGetDatum(new_acl);
@@ -2589,9 +2589,9 @@ ExecGrant_Function(InternalGrant *istmt)
nnewmembers = aclmembers(new_acl, &newmembers);
/* finished building new ACL value, now insert it */
- MemSet(values, 0, sizeof(values));
- MemSet(nulls, false, sizeof(nulls));
- MemSet(replaces, false, sizeof(replaces));
+ memset(values, 0, sizeof(values));
+ memset(nulls, false, sizeof(nulls));
+ memset(replaces, false, sizeof(replaces));
replaces[Anum_pg_proc_proacl - 1] = true;
values[Anum_pg_proc_proacl - 1] = PointerGetDatum(new_acl);
@@ -2720,9 +2720,9 @@ ExecGrant_Language(InternalGrant *istmt)
nnewmembers = aclmembers(new_acl, &newmembers);
/* finished building new ACL value, now insert it */
- MemSet(values, 0, sizeof(values));
- MemSet(nulls, false, sizeof(nulls));
- MemSet(replaces, false, sizeof(replaces));
+ memset(values, 0, sizeof(values));
+ memset(nulls, false, sizeof(nulls));
+ memset(replaces, false, sizeof(replaces));
replaces[Anum_pg_language_lanacl - 1] = true;
values[Anum_pg_language_lanacl - 1] = PointerGetDatum(new_acl);
@@ -2858,9 +2858,9 @@ ExecGrant_Largeobject(InternalGrant *istmt)
nnewmembers = aclmembers(new_acl, &newmembers);
/* finished building new ACL value, now insert it */
- MemSet(values, 0, sizeof(values));
- MemSet(nulls, false, sizeof(nulls));
- MemSet(replaces, false, sizeof(replaces));
+ memset(values, 0, sizeof(values));
+ memset(nulls, false, sizeof(nulls));
+ memset(replaces, false, sizeof(replaces));
replaces[Anum_pg_largeobject_metadata_lomacl - 1] = true;
values[Anum_pg_largeobject_metadata_lomacl - 1]
@@ -2984,9 +2984,9 @@ ExecGrant_Namespace(InternalGrant *istmt)
nnewmembers = aclmembers(new_acl, &newmembers);
/* finished building new ACL value, now insert it */
- MemSet(values, 0, sizeof(values));
- MemSet(nulls, false, sizeof(nulls));
- MemSet(replaces, false, sizeof(replaces));
+ memset(values, 0, sizeof(values));
+ memset(nulls, false, sizeof(nulls));
+ memset(replaces, false, sizeof(replaces));
replaces[Anum_pg_namespace_nspacl - 1] = true;
values[Anum_pg_namespace_nspacl - 1] = PointerGetDatum(new_acl);
@@ -3108,9 +3108,9 @@ ExecGrant_Tablespace(InternalGrant *istmt)
nnewmembers = aclmembers(new_acl, &newmembers);
/* finished building new ACL value, now insert it */
- MemSet(values, 0, sizeof(values));
- MemSet(nulls, false, sizeof(nulls));
- MemSet(replaces, false, sizeof(replaces));
+ memset(values, 0, sizeof(values));
+ memset(nulls, false, sizeof(nulls));
+ memset(replaces, false, sizeof(replaces));
replaces[Anum_pg_tablespace_spcacl - 1] = true;
values[Anum_pg_tablespace_spcacl - 1] = PointerGetDatum(new_acl);
@@ -3242,9 +3242,9 @@ ExecGrant_Type(InternalGrant *istmt)
nnewmembers = aclmembers(new_acl, &newmembers);
/* finished building new ACL value, now insert it */
- MemSet(values, 0, sizeof(values));
- MemSet(nulls, false, sizeof(nulls));
- MemSet(replaces, false, sizeof(replaces));
+ memset(values, 0, sizeof(values));
+ memset(nulls, false, sizeof(nulls));
+ memset(replaces, false, sizeof(replaces));
replaces[Anum_pg_type_typacl - 1] = true;
values[Anum_pg_type_typacl - 1] = PointerGetDatum(new_acl);
@@ -3388,9 +3388,9 @@ ExecGrant_Parameter(InternalGrant *istmt)
bool nulls[Natts_pg_parameter_acl];
bool replaces[Natts_pg_parameter_acl];
- MemSet(values, 0, sizeof(values));
- MemSet(nulls, false, sizeof(nulls));
- MemSet(replaces, false, sizeof(replaces));
+ memset(values, 0, sizeof(values));
+ memset(nulls, false, sizeof(nulls));
+ memset(replaces, false, sizeof(replaces));
replaces[Anum_pg_parameter_acl_paracl - 1] = true;
values[Anum_pg_parameter_acl_paracl - 1] = PointerGetDatum(new_acl);
@@ -6426,9 +6426,9 @@ recordExtensionInitPrivWorker(Oid objoid, Oid classoid, int objsubid, Acl *new_a
/* If we have a new ACL to set, then update the row with it. */
if (new_acl)
{
- MemSet(values, 0, sizeof(values));
- MemSet(nulls, false, sizeof(nulls));
- MemSet(replace, false, sizeof(replace));
+ memset(values, 0, sizeof(values));
+ memset(nulls, false, sizeof(nulls));
+ memset(replace, false, sizeof(replace));
values[Anum_pg_init_privs_initprivs - 1] = PointerGetDatum(new_acl);
replace[Anum_pg_init_privs_initprivs - 1] = true;
@@ -6458,7 +6458,7 @@ recordExtensionInitPrivWorker(Oid objoid, Oid classoid, int objsubid, Acl *new_a
if (new_acl)
{
/* No entry found, so add it. */
- MemSet(nulls, false, sizeof(nulls));
+ memset(nulls, false, sizeof(nulls));
values[Anum_pg_init_privs_objoid - 1] = ObjectIdGetDatum(objoid);
values[Anum_pg_init_privs_classoid - 1] = ObjectIdGetDatum(classoid);
diff --git a/src/backend/catalog/dependency.c b/src/backend/catalog/dependency.c
index de10923391..e853de5bac 100644
--- a/src/backend/catalog/dependency.c
+++ b/src/backend/catalog/dependency.c
@@ -1640,7 +1640,7 @@ recordDependencyOnSingleRelExpr(const ObjectAddress *depender,
context.addrs = new_object_addresses();
/* We gin up a rather bogus rangetable list to handle Vars */
- MemSet(&rte, 0, sizeof(rte));
+ memset(&rte, 0, sizeof(rte));
rte.type = T_RangeTblEntry;
rte.rtekind = RTE_RELATION;
rte.relid = relId;
diff --git a/src/backend/catalog/heap.c b/src/backend/catalog/heap.c
index 1803194db9..75c0610e46 100644
--- a/src/backend/catalog/heap.c
+++ b/src/backend/catalog/heap.c
@@ -1714,9 +1714,9 @@ RemoveAttributeById(Oid relid, AttrNumber attnum)
bool replacesAtt[Natts_pg_attribute];
/* update the tuple - set atthasmissing and attmissingval */
- MemSet(valuesAtt, 0, sizeof(valuesAtt));
- MemSet(nullsAtt, false, sizeof(nullsAtt));
- MemSet(replacesAtt, false, sizeof(replacesAtt));
+ memset(valuesAtt, 0, sizeof(valuesAtt));
+ memset(nullsAtt, false, sizeof(nullsAtt));
+ memset(replacesAtt, false, sizeof(replacesAtt));
valuesAtt[Anum_pg_attribute_atthasmissing - 1] =
BoolGetDatum(false);
@@ -2041,9 +2041,9 @@ SetAttrMissing(Oid relid, char *attname, char *value)
Int32GetDatum(attStruct->atttypmod));
/* update the tuple - set atthasmissing and attmissingval */
- MemSet(valuesAtt, 0, sizeof(valuesAtt));
- MemSet(nullsAtt, false, sizeof(nullsAtt));
- MemSet(replacesAtt, false, sizeof(replacesAtt));
+ memset(valuesAtt, 0, sizeof(valuesAtt));
+ memset(nullsAtt, false, sizeof(nullsAtt));
+ memset(replacesAtt, false, sizeof(replacesAtt));
valuesAtt[Anum_pg_attribute_atthasmissing - 1] = BoolGetDatum(true);
replacesAtt[Anum_pg_attribute_atthasmissing - 1] = true;
@@ -3347,7 +3347,7 @@ StorePartitionKey(Relation rel,
pg_partitioned_table = table_open(PartitionedRelationId, RowExclusiveLock);
- MemSet(nulls, false, sizeof(nulls));
+ memset(nulls, false, sizeof(nulls));
/* Only this can ever be NULL */
if (!partexprDatum)
diff --git a/src/backend/catalog/index.c b/src/backend/catalog/index.c
index bdd3c34841..99d176846c 100644
--- a/src/backend/catalog/index.c
+++ b/src/backend/catalog/index.c
@@ -309,7 +309,7 @@ ConstructTupleDescriptor(Relation heapRelation,
Form_pg_opclass opclassTup;
Oid keyType;
- MemSet(to, 0, ATTRIBUTE_FIXED_PART_SIZE);
+ memset(to, 0, ATTRIBUTE_FIXED_PART_SIZE);
to->attnum = i + 1;
to->attstattarget = -1;
to->attcacheoff = -1;
@@ -607,7 +607,7 @@ UpdateIndexRelation(Oid indexoid,
/*
* Build a pg_index tuple
*/
- MemSet(nulls, false, sizeof(nulls));
+ memset(nulls, false, sizeof(nulls));
values[Anum_pg_index_indexrelid - 1] = ObjectIdGetDatum(indexoid);
values[Anum_pg_index_indrelid - 1] = ObjectIdGetDatum(heapoid);
diff --git a/src/backend/catalog/pg_attrdef.c b/src/backend/catalog/pg_attrdef.c
index c5d4a9912e..11c61f4970 100644
--- a/src/backend/catalog/pg_attrdef.c
+++ b/src/backend/catalog/pg_attrdef.c
@@ -117,9 +117,9 @@ StoreAttrDefault(Relation rel, AttrNumber attnum,
Datum missingval = (Datum) 0;
bool missingIsNull = true;
- MemSet(valuesAtt, 0, sizeof(valuesAtt));
- MemSet(nullsAtt, false, sizeof(nullsAtt));
- MemSet(replacesAtt, false, sizeof(replacesAtt));
+ memset(valuesAtt, 0, sizeof(valuesAtt));
+ memset(nullsAtt, false, sizeof(nullsAtt));
+ memset(replacesAtt, false, sizeof(replacesAtt));
valuesAtt[Anum_pg_attribute_atthasdef - 1] = true;
replacesAtt[Anum_pg_attribute_atthasdef - 1] = true;
diff --git a/src/backend/catalog/pg_cast.c b/src/backend/catalog/pg_cast.c
index 4857f6468d..cbf49817cf 100644
--- a/src/backend/catalog/pg_cast.c
+++ b/src/backend/catalog/pg_cast.c
@@ -78,7 +78,7 @@ CastCreate(Oid sourcetypeid, Oid targettypeid, Oid funcid, char castcontext,
values[Anum_pg_cast_castcontext - 1] = CharGetDatum(castcontext);
values[Anum_pg_cast_castmethod - 1] = CharGetDatum(castmethod);
- MemSet(nulls, false, sizeof(nulls));
+ memset(nulls, false, sizeof(nulls));
tuple = heap_form_tuple(RelationGetDescr(relation), values, nulls);
diff --git a/src/backend/catalog/pg_parameter_acl.c b/src/backend/catalog/pg_parameter_acl.c
index 2decee909b..4afeb7218c 100644
--- a/src/backend/catalog/pg_parameter_acl.c
+++ b/src/backend/catalog/pg_parameter_acl.c
@@ -98,8 +98,8 @@ ParameterAclCreate(const char *parameter)
*/
rel = table_open(ParameterAclRelationId, RowExclusiveLock);
tupDesc = RelationGetDescr(rel);
- MemSet(values, 0, sizeof(values));
- MemSet(nulls, false, sizeof(nulls));
+ memset(values, 0, sizeof(values));
+ memset(nulls, false, sizeof(nulls));
parameterId = GetNewOidWithIndex(rel,
ParameterAclOidIndexId,
Anum_pg_parameter_acl_oid);
diff --git a/src/backend/catalog/pg_publication.c b/src/backend/catalog/pg_publication.c
index 8c7fca62de..7aa7a019c9 100644
--- a/src/backend/catalog/pg_publication.c
+++ b/src/backend/catalog/pg_publication.c
@@ -1168,8 +1168,8 @@ pg_get_publication_tables(PG_FUNCTION_ARGS)
/*
* Form tuple with appropriate data.
*/
- MemSet(nulls, 0, sizeof(nulls));
- MemSet(values, 0, sizeof(values));
+ memset(nulls, 0, sizeof(nulls));
+ memset(values, 0, sizeof(values));
publication = GetPublicationByName(pubname, false);
diff --git a/src/backend/catalog/storage.c b/src/backend/catalog/storage.c
index c06e414a38..b8ce4749ed 100644
--- a/src/backend/catalog/storage.c
+++ b/src/backend/catalog/storage.c
@@ -613,7 +613,7 @@ SerializePendingSyncs(Size maxSize, char *startAddress)
hash_destroy(tmphash);
terminate:
- MemSet(dest, 0, sizeof(RelFileNode));
+ memset(dest, 0, sizeof(RelFileNode));
}
/*
diff --git a/src/backend/commands/copyfromparse.c b/src/backend/commands/copyfromparse.c
index edb80e2cd5..b1d07f911d 100644
--- a/src/backend/commands/copyfromparse.c
+++ b/src/backend/commands/copyfromparse.c
@@ -867,8 +867,8 @@ NextCopyFrom(CopyFromState cstate, ExprContext *econtext,
attr_count = list_length(cstate->attnumlist);
/* Initialize all values for row to NULL */
- MemSet(values, 0, num_phys_attrs * sizeof(Datum));
- MemSet(nulls, true, num_phys_attrs * sizeof(bool));
+ memset(values, 0, num_phys_attrs * sizeof(Datum));
+ memset(nulls, true, num_phys_attrs * sizeof(bool));
if (!cstate->opts.binary)
{
diff --git a/src/backend/commands/dbcommands.c b/src/backend/commands/dbcommands.c
index f269168401..70e87ee559 100644
--- a/src/backend/commands/dbcommands.c
+++ b/src/backend/commands/dbcommands.c
@@ -1296,8 +1296,8 @@ createdb(ParseState *pstate, const CreatedbStmt *stmt)
(dblocprovider != COLLPROVIDER_ICU && !dbiculocale));
/* Form tuple */
- MemSet(new_record, 0, sizeof(new_record));
- MemSet(new_record_nulls, false, sizeof(new_record_nulls));
+ memset(new_record, 0, sizeof(new_record));
+ memset(new_record_nulls, false, sizeof(new_record_nulls));
new_record[Anum_pg_database_oid - 1] = ObjectIdGetDatum(dboid);
new_record[Anum_pg_database_datname - 1] =
@@ -2042,9 +2042,9 @@ movedb(const char *dbname, const char *tblspcname)
(errcode(ERRCODE_UNDEFINED_DATABASE),
errmsg("database \"%s\" does not exist", dbname)));
- MemSet(new_record, 0, sizeof(new_record));
- MemSet(new_record_nulls, false, sizeof(new_record_nulls));
- MemSet(new_record_repl, false, sizeof(new_record_repl));
+ memset(new_record, 0, sizeof(new_record));
+ memset(new_record_nulls, false, sizeof(new_record_nulls));
+ memset(new_record_repl, false, sizeof(new_record_repl));
new_record[Anum_pg_database_dattablespace - 1] = ObjectIdGetDatum(dst_tblspcoid);
new_record_repl[Anum_pg_database_dattablespace - 1] = true;
@@ -2305,9 +2305,9 @@ AlterDatabase(ParseState *pstate, AlterDatabaseStmt *stmt, bool isTopLevel)
/*
* Build an updated tuple, perusing the information just obtained
*/
- MemSet(new_record, 0, sizeof(new_record));
- MemSet(new_record_nulls, false, sizeof(new_record_nulls));
- MemSet(new_record_repl, false, sizeof(new_record_repl));
+ memset(new_record, 0, sizeof(new_record));
+ memset(new_record_nulls, false, sizeof(new_record_nulls));
+ memset(new_record_repl, false, sizeof(new_record_repl));
if (distemplate)
{
diff --git a/src/backend/commands/event_trigger.c b/src/backend/commands/event_trigger.c
index 4642527881..b927a3f479 100644
--- a/src/backend/commands/event_trigger.c
+++ b/src/backend/commands/event_trigger.c
@@ -1316,8 +1316,8 @@ pg_event_trigger_dropped_objects(PG_FUNCTION_ARGS)
obj = slist_container(SQLDropObject, next, iter.cur);
- MemSet(values, 0, sizeof(values));
- MemSet(nulls, 0, sizeof(nulls));
+ memset(values, 0, sizeof(values));
+ memset(nulls, 0, sizeof(nulls));
/* classid */
values[i++] = ObjectIdGetDatum(obj->address.classId);
@@ -1859,7 +1859,7 @@ pg_event_trigger_ddl_commands(PG_FUNCTION_ARGS)
!OidIsValid(cmd->d.simple.address.objectId))
continue;
- MemSet(nulls, 0, sizeof(nulls));
+ memset(nulls, 0, sizeof(nulls));
switch (cmd->type)
{
diff --git a/src/backend/commands/functioncmds.c b/src/backend/commands/functioncmds.c
index 00a6d282cf..b14cc774c0 100644
--- a/src/backend/commands/functioncmds.c
+++ b/src/backend/commands/functioncmds.c
@@ -1917,7 +1917,7 @@ CreateTransform(CreateTransformStmt *stmt)
values[Anum_pg_transform_trffromsql - 1] = ObjectIdGetDatum(fromsqlfuncid);
values[Anum_pg_transform_trftosql - 1] = ObjectIdGetDatum(tosqlfuncid);
- MemSet(nulls, false, sizeof(nulls));
+ memset(nulls, false, sizeof(nulls));
relation = table_open(TransformRelationId, RowExclusiveLock);
@@ -1935,7 +1935,7 @@ CreateTransform(CreateTransformStmt *stmt)
format_type_be(typeid),
stmt->lang)));
- MemSet(replaces, false, sizeof(replaces));
+ memset(replaces, false, sizeof(replaces));
replaces[Anum_pg_transform_trffromsql - 1] = true;
replaces[Anum_pg_transform_trftosql - 1] = true;
diff --git a/src/backend/commands/prepare.c b/src/backend/commands/prepare.c
index 80738547ed..eeb77991b0 100644
--- a/src/backend/commands/prepare.c
+++ b/src/backend/commands/prepare.c
@@ -686,7 +686,7 @@ pg_prepared_statement(PG_FUNCTION_ARGS)
Datum values[7];
bool nulls[7];
- MemSet(nulls, 0, sizeof(nulls));
+ memset(nulls, 0, sizeof(nulls));
values[0] = CStringGetTextDatum(prep_stmt->stmt_name);
values[1] = CStringGetTextDatum(prep_stmt->plansource->query_string);
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 2de0ebacec..1f180306c2 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -9112,15 +9112,15 @@ ATAddForeignKeyConstraint(List **wqueue, AlteredTableInfo *tab, Relation rel,
* Look up the referencing attributes to make sure they exist, and record
* their attnums and type OIDs.
*/
- MemSet(pkattnum, 0, sizeof(pkattnum));
- MemSet(fkattnum, 0, sizeof(fkattnum));
- MemSet(pktypoid, 0, sizeof(pktypoid));
- MemSet(fktypoid, 0, sizeof(fktypoid));
- MemSet(opclasses, 0, sizeof(opclasses));
- MemSet(pfeqoperators, 0, sizeof(pfeqoperators));
- MemSet(ppeqoperators, 0, sizeof(ppeqoperators));
- MemSet(ffeqoperators, 0, sizeof(ffeqoperators));
- MemSet(fkdelsetcols, 0, sizeof(fkdelsetcols));
+ memset(pkattnum, 0, sizeof(pkattnum));
+ memset(fkattnum, 0, sizeof(fkattnum));
+ memset(pktypoid, 0, sizeof(pktypoid));
+ memset(fktypoid, 0, sizeof(fktypoid));
+ memset(opclasses, 0, sizeof(opclasses));
+ memset(pfeqoperators, 0, sizeof(pfeqoperators));
+ memset(ppeqoperators, 0, sizeof(ppeqoperators));
+ memset(ffeqoperators, 0, sizeof(ffeqoperators));
+ memset(fkdelsetcols, 0, sizeof(fkdelsetcols));
numfks = transformColumnNameList(RelationGetRelid(rel),
fkconstraint->fk_attrs,
@@ -11508,7 +11508,7 @@ validateForeignKeyConstraint(char *conname,
/*
* Build a trigger call structure; we'll need it either way.
*/
- MemSet(&trig, 0, sizeof(trig));
+ memset(&trig, 0, sizeof(trig));
trig.tgoid = InvalidOid;
trig.tgname = conname;
trig.tgenabled = TRIGGER_FIRES_ON_ORIGIN;
@@ -11553,7 +11553,7 @@ validateForeignKeyConstraint(char *conname,
*
* No parameters are passed, but we do set a context
*/
- MemSet(fcinfo, 0, SizeForFunctionCallInfo(0));
+ memset(fcinfo, 0, SizeForFunctionCallInfo(0));
/*
* We assume RI_FKey_check_ins won't look at flinfo...
@@ -12787,9 +12787,9 @@ ATExecAlterColumnType(AlteredTableInfo *tab, Relation rel,
bool replacesAtt[Natts_pg_attribute];
HeapTuple newTup;
- MemSet(valuesAtt, 0, sizeof(valuesAtt));
- MemSet(nullsAtt, false, sizeof(nullsAtt));
- MemSet(replacesAtt, false, sizeof(replacesAtt));
+ memset(valuesAtt, 0, sizeof(valuesAtt));
+ memset(nullsAtt, false, sizeof(nullsAtt));
+ memset(replacesAtt, false, sizeof(replacesAtt));
missingval = array_get_element(missingval,
1,
@@ -19231,7 +19231,7 @@ ATDetachCheckNoForeignKeyRefs(Relation partition)
/* prevent data changes into the referencing table until commit */
rel = table_open(constrForm->conrelid, ShareLock);
- MemSet(&trig, 0, sizeof(trig));
+ memset(&trig, 0, sizeof(trig));
trig.tgoid = InvalidOid;
trig.tgname = NameStr(constrForm->conname);
trig.tgenabled = TRIGGER_FIRES_ON_ORIGIN;
diff --git a/src/backend/commands/tablespace.c b/src/backend/commands/tablespace.c
index 00ca397fe8..b55f07f092 100644
--- a/src/backend/commands/tablespace.c
+++ b/src/backend/commands/tablespace.c
@@ -340,7 +340,7 @@ CreateTableSpace(CreateTableSpaceStmt *stmt)
*/
rel = table_open(TableSpaceRelationId, RowExclusiveLock);
- MemSet(nulls, false, sizeof(nulls));
+ memset(nulls, false, sizeof(nulls));
if (IsBinaryUpgrade)
{
diff --git a/src/backend/commands/typecmds.c b/src/backend/commands/typecmds.c
index 9b92b04242..5b91f14a7e 100644
--- a/src/backend/commands/typecmds.c
+++ b/src/backend/commands/typecmds.c
@@ -2596,9 +2596,9 @@ AlterDomainDefault(List *names, Node *defaultRaw)
checkDomainOwner(tup);
/* Setup new tuple */
- MemSet(new_record, (Datum) 0, sizeof(new_record));
- MemSet(new_record_nulls, false, sizeof(new_record_nulls));
- MemSet(new_record_repl, false, sizeof(new_record_repl));
+ memset(new_record, (Datum) 0, sizeof(new_record));
+ memset(new_record_nulls, false, sizeof(new_record_nulls));
+ memset(new_record_repl, false, sizeof(new_record_repl));
/* Store the new default into the tuple */
if (defaultRaw)
diff --git a/src/backend/commands/user.c b/src/backend/commands/user.c
index 984305ba31..61a28e2098 100644
--- a/src/backend/commands/user.c
+++ b/src/backend/commands/user.c
@@ -338,8 +338,8 @@ CreateRole(ParseState *pstate, CreateRoleStmt *stmt)
/*
* Build a tuple to insert
*/
- MemSet(new_record, 0, sizeof(new_record));
- MemSet(new_record_nulls, false, sizeof(new_record_nulls));
+ memset(new_record, 0, sizeof(new_record));
+ memset(new_record_nulls, false, sizeof(new_record_nulls));
new_record[Anum_pg_authid_rolname - 1] =
DirectFunctionCall1(namein, CStringGetDatum(stmt->role));
@@ -691,9 +691,9 @@ AlterRole(ParseState *pstate, AlterRoleStmt *stmt)
/*
* Build an updated tuple, perusing the information just obtained
*/
- MemSet(new_record, 0, sizeof(new_record));
- MemSet(new_record_nulls, false, sizeof(new_record_nulls));
- MemSet(new_record_repl, false, sizeof(new_record_repl));
+ memset(new_record, 0, sizeof(new_record));
+ memset(new_record_nulls, false, sizeof(new_record_nulls));
+ memset(new_record_repl, false, sizeof(new_record_repl));
/*
* issuper/createrole/etc
@@ -1500,9 +1500,9 @@ AddRoleMems(const char *rolename, Oid roleid,
}
/* Build a tuple to insert or update */
- MemSet(new_record, 0, sizeof(new_record));
- MemSet(new_record_nulls, false, sizeof(new_record_nulls));
- MemSet(new_record_repl, false, sizeof(new_record_repl));
+ memset(new_record, 0, sizeof(new_record));
+ memset(new_record_nulls, false, sizeof(new_record_nulls));
+ memset(new_record_repl, false, sizeof(new_record_repl));
new_record[Anum_pg_auth_members_roleid - 1] = ObjectIdGetDatum(roleid);
new_record[Anum_pg_auth_members_member - 1] = ObjectIdGetDatum(memberid);
@@ -1619,9 +1619,9 @@ DelRoleMems(const char *rolename, Oid roleid,
bool new_record_repl[Natts_pg_auth_members];
/* Build a tuple to update with */
- MemSet(new_record, 0, sizeof(new_record));
- MemSet(new_record_nulls, false, sizeof(new_record_nulls));
- MemSet(new_record_repl, false, sizeof(new_record_repl));
+ memset(new_record, 0, sizeof(new_record));
+ memset(new_record_nulls, false, sizeof(new_record_nulls));
+ memset(new_record_repl, false, sizeof(new_record_repl));
new_record[Anum_pg_auth_members_admin_option - 1] = BoolGetDatum(false);
new_record_repl[Anum_pg_auth_members_admin_option - 1] = true;
diff --git a/src/backend/commands/vacuumparallel.c b/src/backend/commands/vacuumparallel.c
index 1753da6c83..6278a97106 100644
--- a/src/backend/commands/vacuumparallel.c
+++ b/src/backend/commands/vacuumparallel.c
@@ -352,7 +352,7 @@ parallel_vacuum_init(Relation rel, Relation *indrels, int nindexes,
/* Prepare shared information */
shared = (PVShared *) shm_toc_allocate(pcxt->toc, est_shared_len);
- MemSet(shared, 0, est_shared_len);
+ memset(shared, 0, est_shared_len);
shared->relid = RelationGetRelid(rel);
shared->elevel = elevel;
shared->maintenance_work_mem_worker =
@@ -372,7 +372,7 @@ parallel_vacuum_init(Relation rel, Relation *indrels, int nindexes,
est_dead_items_len);
dead_items->max_items = max_items;
dead_items->num_items = 0;
- MemSet(dead_items->items, 0, sizeof(ItemPointerData) * max_items);
+ memset(dead_items->items, 0, sizeof(ItemPointerData) * max_items);
shm_toc_insert(pcxt->toc, PARALLEL_VACUUM_KEY_DEAD_ITEMS, dead_items);
pvs->dead_items = dead_items;
diff --git a/src/backend/executor/execMain.c b/src/backend/executor/execMain.c
index ef2fd46092..6905edfa9e 100644
--- a/src/backend/executor/execMain.c
+++ b/src/backend/executor/execMain.c
@@ -1198,7 +1198,7 @@ InitResultRelInfo(ResultRelInfo *resultRelInfo,
ResultRelInfo *partition_root_rri,
int instrument_options)
{
- MemSet(resultRelInfo, 0, sizeof(ResultRelInfo));
+ memset(resultRelInfo, 0, sizeof(ResultRelInfo));
resultRelInfo->type = T_ResultRelInfo;
resultRelInfo->ri_RangeTableIndex = resultRelationIndex;
resultRelInfo->ri_RelationDesc = resultRelationDesc;
@@ -2735,7 +2735,7 @@ EvalPlanQualBegin(EPQState *epqstate)
Index rtsize = parentestate->es_range_table_size;
PlanState *rcplanstate = epqstate->recheckplanstate;
- MemSet(epqstate->relsubs_done, 0, rtsize * sizeof(bool));
+ memset(epqstate->relsubs_done, 0, rtsize * sizeof(bool));
/* Recopy current values of parent parameters */
if (parentestate->es_plannedstmt->paramExecTypes != NIL)
diff --git a/src/backend/executor/execTuples.c b/src/backend/executor/execTuples.c
index 06ac253ea0..c29309a882 100644
--- a/src/backend/executor/execTuples.c
+++ b/src/backend/executor/execTuples.c
@@ -1587,7 +1587,7 @@ ExecStoreAllNullTuple(TupleTableSlot *slot)
/*
* Fill all the columns of the virtual tuple with nulls
*/
- MemSet(slot->tts_values, 0,
+ memset(slot->tts_values, 0,
slot->tts_tupleDescriptor->natts * sizeof(Datum));
memset(slot->tts_isnull, true,
slot->tts_tupleDescriptor->natts * sizeof(bool));
diff --git a/src/backend/executor/nodeAgg.c b/src/backend/executor/nodeAgg.c
index 139b2bd5f9..7768b0168e 100644
--- a/src/backend/executor/nodeAgg.c
+++ b/src/backend/executor/nodeAgg.c
@@ -2599,7 +2599,7 @@ agg_refill_hash_table(AggState *aggstate)
* we rescan later. The expressions for sorted grouping sets will not be
* evaluated after we recompile anyway.
*/
- MemSet(aggstate->hash_pergroup, 0,
+ memset(aggstate->hash_pergroup, 0,
sizeof(AggStatePerGroup) * aggstate->num_hashes);
/* free memory and reset hash tables */
@@ -4413,8 +4413,8 @@ ExecReScanAgg(AggState *node)
ExecClearTuple(node->ss.ss_ScanTupleSlot);
/* Forget current agg values */
- MemSet(econtext->ecxt_aggvalues, 0, sizeof(Datum) * node->numaggs);
- MemSet(econtext->ecxt_aggnulls, 0, sizeof(bool) * node->numaggs);
+ memset(econtext->ecxt_aggvalues, 0, sizeof(Datum) * node->numaggs);
+ memset(econtext->ecxt_aggnulls, 0, sizeof(bool) * node->numaggs);
/*
* With AGG_HASHED/MIXED, the hash table is allocated in a sub-context of
@@ -4445,7 +4445,7 @@ ExecReScanAgg(AggState *node)
*/
for (setno = 0; setno < numGroupingSets; setno++)
{
- MemSet(node->pergroups[setno], 0,
+ memset(node->pergroups[setno], 0,
sizeof(AggStatePerGroupData) * node->numaggs);
}
diff --git a/src/backend/executor/nodeHash.c b/src/backend/executor/nodeHash.c
index 3510a4247c..f706b7510a 100644
--- a/src/backend/executor/nodeHash.c
+++ b/src/backend/executor/nodeHash.c
@@ -948,9 +948,9 @@ ExecHashIncreaseNumBatches(HashJoinTable hashtable)
repalloc(hashtable->innerBatchFile, nbatch * sizeof(BufFile *));
hashtable->outerBatchFile = (BufFile **)
repalloc(hashtable->outerBatchFile, nbatch * sizeof(BufFile *));
- MemSet(hashtable->innerBatchFile + oldnbatch, 0,
+ memset(hashtable->innerBatchFile + oldnbatch, 0,
(nbatch - oldnbatch) * sizeof(BufFile *));
- MemSet(hashtable->outerBatchFile + oldnbatch, 0,
+ memset(hashtable->outerBatchFile + oldnbatch, 0,
(nbatch - oldnbatch) * sizeof(BufFile *));
}
diff --git a/src/backend/executor/nodeIndexscan.c b/src/backend/executor/nodeIndexscan.c
index 5ef5c6930f..78774796a0 100644
--- a/src/backend/executor/nodeIndexscan.c
+++ b/src/backend/executor/nodeIndexscan.c
@@ -1437,7 +1437,7 @@ ExecIndexBuildScanKeys(PlanState *planstate, Relation index,
* We don't use ScanKeyEntryInitialize for the header because it
* isn't going to contain a valid sk_func pointer.
*/
- MemSet(this_scan_key, 0, sizeof(ScanKeyData));
+ memset(this_scan_key, 0, sizeof(ScanKeyData));
this_scan_key->sk_flags = SK_ROW_HEADER;
this_scan_key->sk_attno = first_sub_key->sk_attno;
this_scan_key->sk_strategy = rc->rctype;
diff --git a/src/backend/executor/nodeWindowAgg.c b/src/backend/executor/nodeWindowAgg.c
index 4b104c4d98..510f93f0b7 100644
--- a/src/backend/executor/nodeWindowAgg.c
+++ b/src/backend/executor/nodeWindowAgg.c
@@ -2723,8 +2723,8 @@ ExecReScanWindowAgg(WindowAggState *node)
ExecClearTuple(node->frametail_slot);
/* Forget current wfunc values */
- MemSet(econtext->ecxt_aggvalues, 0, sizeof(Datum) * node->numfuncs);
- MemSet(econtext->ecxt_aggnulls, 0, sizeof(bool) * node->numfuncs);
+ memset(econtext->ecxt_aggvalues, 0, sizeof(Datum) * node->numfuncs);
+ memset(econtext->ecxt_aggnulls, 0, sizeof(bool) * node->numfuncs);
/*
* if chgParam of subnode is not null then plan will be re-scanned by
diff --git a/src/backend/libpq/auth.c b/src/backend/libpq/auth.c
index efc53f3135..7c4494c064 100644
--- a/src/backend/libpq/auth.c
+++ b/src/backend/libpq/auth.c
@@ -3041,7 +3041,7 @@ PerformRadiusTransaction(const char *server, const char *secret, const char *por
if (identifier == NULL)
identifier = "postgresql";
- MemSet(&hint, 0, sizeof(hint));
+ memset(&hint, 0, sizeof(hint));
hint.ai_socktype = SOCK_DGRAM;
hint.ai_family = AF_UNSPEC;
port = atoi(portstr);
diff --git a/src/backend/libpq/be-fsstubs.c b/src/backend/libpq/be-fsstubs.c
index 5804532881..fc4811aa8a 100644
--- a/src/backend/libpq/be-fsstubs.c
+++ b/src/backend/libpq/be-fsstubs.c
@@ -688,7 +688,7 @@ newLOfd(void)
newsize = cookies_size * 2;
cookies = (LargeObjectDesc **)
repalloc(cookies, newsize * sizeof(LargeObjectDesc *));
- MemSet(cookies + cookies_size, 0,
+ memset(cookies + cookies_size, 0,
(newsize - cookies_size) * sizeof(LargeObjectDesc *));
cookies_size = newsize;
}
diff --git a/src/backend/libpq/hba.c b/src/backend/libpq/hba.c
index 327a4b42af..30fd58e4ca 100644
--- a/src/backend/libpq/hba.c
+++ b/src/backend/libpq/hba.c
@@ -1964,7 +1964,7 @@ parse_hba_auth_opt(char *name, char *val, HbaLine *hbaline,
/* For each entry in the list, translate it */
foreach(l, parsed_servers)
{
- MemSet(&hints, 0, sizeof(hints));
+ memset(&hints, 0, sizeof(hints));
hints.ai_socktype = SOCK_DGRAM;
hints.ai_family = AF_UNSPEC;
diff --git a/src/backend/libpq/pqcomm.c b/src/backend/libpq/pqcomm.c
index 75392a8bb7..f75304cea1 100644
--- a/src/backend/libpq/pqcomm.c
+++ b/src/backend/libpq/pqcomm.c
@@ -343,7 +343,7 @@ StreamServerPort(int family, const char *hostName, unsigned short portNumber,
#endif
/* Initialize hint structure */
- MemSet(&hint, 0, sizeof(hint));
+ memset(&hint, 0, sizeof(hint));
hint.ai_family = family;
hint.ai_flags = AI_PASSIVE;
hint.ai_socktype = SOCK_STREAM;
diff --git a/src/backend/libpq/pqmq.c b/src/backend/libpq/pqmq.c
index 4d0415e379..139bb90dc5 100644
--- a/src/backend/libpq/pqmq.c
+++ b/src/backend/libpq/pqmq.c
@@ -204,7 +204,7 @@ void
pq_parse_errornotice(StringInfo msg, ErrorData *edata)
{
/* Initialize edata with reasonable defaults. */
- MemSet(edata, 0, sizeof(ErrorData));
+ memset(edata, 0, sizeof(ErrorData));
edata->elevel = ERROR;
edata->assoc_context = CurrentMemoryContext;
diff --git a/src/backend/nodes/tidbitmap.c b/src/backend/nodes/tidbitmap.c
index a7a6b26668..dd0260512d 100644
--- a/src/backend/nodes/tidbitmap.c
+++ b/src/backend/nodes/tidbitmap.c
@@ -1230,7 +1230,7 @@ tbm_get_pageentry(TIDBitmap *tbm, BlockNumber pageno)
{
char oldstatus = page->status;
- MemSet(page, 0, sizeof(PagetableEntry));
+ memset(page, 0, sizeof(PagetableEntry));
page->status = oldstatus;
page->blockno = pageno;
/* must count it too */
@@ -1317,7 +1317,7 @@ tbm_mark_page_lossy(TIDBitmap *tbm, BlockNumber pageno)
{
char oldstatus = page->status;
- MemSet(page, 0, sizeof(PagetableEntry));
+ memset(page, 0, sizeof(PagetableEntry));
page->status = oldstatus;
page->blockno = chunk_pageno;
page->ischunk = true;
@@ -1330,7 +1330,7 @@ tbm_mark_page_lossy(TIDBitmap *tbm, BlockNumber pageno)
char oldstatus = page->status;
/* chunk header page was formerly non-lossy, make it lossy */
- MemSet(page, 0, sizeof(PagetableEntry));
+ memset(page, 0, sizeof(PagetableEntry));
page->status = oldstatus;
page->blockno = chunk_pageno;
page->ischunk = true;
diff --git a/src/backend/optimizer/path/costsize.c b/src/backend/optimizer/path/costsize.c
index ed98ba7dbd..d2da6e5f0a 100644
--- a/src/backend/optimizer/path/costsize.c
+++ b/src/backend/optimizer/path/costsize.c
@@ -2905,7 +2905,7 @@ cost_agg(Path *path, PlannerInfo *root,
if (aggcosts == NULL)
{
Assert(aggstrategy == AGG_HASHED);
- MemSet(&dummy_aggcosts, 0, sizeof(AggClauseCosts));
+ memset(&dummy_aggcosts, 0, sizeof(AggClauseCosts));
aggcosts = &dummy_aggcosts;
}
diff --git a/src/backend/optimizer/path/indxpath.c b/src/backend/optimizer/path/indxpath.c
index 0ef70ad7f1..f6c2cd8974 100644
--- a/src/backend/optimizer/path/indxpath.c
+++ b/src/backend/optimizer/path/indxpath.c
@@ -269,7 +269,7 @@ create_index_paths(PlannerInfo *root, RelOptInfo *rel)
/*
* Identify the restriction clauses that can match the index.
*/
- MemSet(&rclauseset, 0, sizeof(rclauseset));
+ memset(&rclauseset, 0, sizeof(rclauseset));
match_restriction_clauses_to_index(root, index, &rclauseset);
/*
@@ -286,7 +286,7 @@ create_index_paths(PlannerInfo *root, RelOptInfo *rel)
* step finds only "loose" join clauses that have not been merged into
* EquivalenceClasses. Also, collect join OR clauses for later.
*/
- MemSet(&jclauseset, 0, sizeof(jclauseset));
+ memset(&jclauseset, 0, sizeof(jclauseset));
match_join_clauses_to_index(root, rel, index,
&jclauseset, &joinorclauses);
@@ -294,7 +294,7 @@ create_index_paths(PlannerInfo *root, RelOptInfo *rel)
* Look for EquivalenceClasses that can generate joinclauses matching
* the index.
*/
- MemSet(&eclauseset, 0, sizeof(eclauseset));
+ memset(&eclauseset, 0, sizeof(eclauseset));
match_eclass_clauses_to_index(root, index,
&eclauseset);
@@ -616,7 +616,7 @@ get_join_index_paths(PlannerInfo *root, RelOptInfo *rel,
return;
/* Identify indexclauses usable with this relids set */
- MemSet(&clauseset, 0, sizeof(clauseset));
+ memset(&clauseset, 0, sizeof(clauseset));
for (indexcol = 0; indexcol < index->nkeycolumns; indexcol++)
{
@@ -1211,7 +1211,7 @@ build_paths_for_OR(PlannerInfo *root, RelOptInfo *rel,
/*
* Identify the restriction clauses that can match the index.
*/
- MemSet(&clauseset, 0, sizeof(clauseset));
+ memset(&clauseset, 0, sizeof(clauseset));
match_clauses_to_index(root, clauses, index, &clauseset);
/*
diff --git a/src/backend/optimizer/plan/planner.c b/src/backend/optimizer/plan/planner.c
index a0f2390334..340e902a15 100644
--- a/src/backend/optimizer/plan/planner.c
+++ b/src/backend/optimizer/plan/planner.c
@@ -3352,7 +3352,7 @@ create_grouping_paths(PlannerInfo *root,
RelOptInfo *partially_grouped_rel;
AggClauseCosts agg_costs;
- MemSet(&agg_costs, 0, sizeof(AggClauseCosts));
+ memset(&agg_costs, 0, sizeof(AggClauseCosts));
get_agg_clause_costs(root, AGGSPLIT_SIMPLE, &agg_costs);
/*
@@ -5915,12 +5915,12 @@ expression_planner_with_deps(Expr *expr,
PlannerInfo root;
/* Make up dummy planner state so we can use setrefs machinery */
- MemSet(&glob, 0, sizeof(glob));
+ memset(&glob, 0, sizeof(glob));
glob.type = T_PlannerGlobal;
glob.relationOids = NIL;
glob.invalItems = NIL;
- MemSet(&root, 0, sizeof(root));
+ memset(&root, 0, sizeof(root));
root.type = T_PlannerInfo;
root.glob = &glob;
@@ -6688,8 +6688,8 @@ create_partial_grouping_paths(PlannerInfo *root,
* Collect statistics about aggregates for estimating costs of
* performing aggregation in parallel.
*/
- MemSet(agg_partial_costs, 0, sizeof(AggClauseCosts));
- MemSet(agg_final_costs, 0, sizeof(AggClauseCosts));
+ memset(agg_partial_costs, 0, sizeof(AggClauseCosts));
+ memset(agg_final_costs, 0, sizeof(AggClauseCosts));
if (parse->hasAggs)
{
/* partial phase */
diff --git a/src/backend/optimizer/plan/setrefs.c b/src/backend/optimizer/plan/setrefs.c
index d95fd89807..3cb86fdba0 100644
--- a/src/backend/optimizer/plan/setrefs.c
+++ b/src/backend/optimizer/plan/setrefs.c
@@ -3274,14 +3274,14 @@ extract_query_dependencies(Node *query,
PlannerInfo root;
/* Make up dummy planner state so we can use this module's machinery */
- MemSet(&glob, 0, sizeof(glob));
+ memset(&glob, 0, sizeof(glob));
glob.type = T_PlannerGlobal;
glob.relationOids = NIL;
glob.invalItems = NIL;
/* Hack: we use glob.dependsOnRole to collect hasRowSecurity flags */
glob.dependsOnRole = false;
- MemSet(&root, 0, sizeof(root));
+ memset(&root, 0, sizeof(root));
root.type = T_PlannerInfo;
root.glob = &glob;
diff --git a/src/backend/optimizer/util/relnode.c b/src/backend/optimizer/util/relnode.c
index 520409f4ba..9ebe594fcb 100644
--- a/src/backend/optimizer/util/relnode.c
+++ b/src/backend/optimizer/util/relnode.c
@@ -160,13 +160,13 @@ expand_planner_arrays(PlannerInfo *root, int add_size)
root->simple_rel_array = (RelOptInfo **)
repalloc(root->simple_rel_array,
sizeof(RelOptInfo *) * new_size);
- MemSet(root->simple_rel_array + root->simple_rel_array_size,
+ memset(root->simple_rel_array + root->simple_rel_array_size,
0, sizeof(RelOptInfo *) * add_size);
root->simple_rte_array = (RangeTblEntry **)
repalloc(root->simple_rte_array,
sizeof(RangeTblEntry *) * new_size);
- MemSet(root->simple_rte_array + root->simple_rel_array_size,
+ memset(root->simple_rte_array + root->simple_rel_array_size,
0, sizeof(RangeTblEntry *) * add_size);
if (root->append_rel_array)
@@ -174,7 +174,7 @@ expand_planner_arrays(PlannerInfo *root, int add_size)
root->append_rel_array = (AppendRelInfo **)
repalloc(root->append_rel_array,
sizeof(AppendRelInfo *) * new_size);
- MemSet(root->append_rel_array + root->simple_rel_array_size,
+ memset(root->append_rel_array + root->simple_rel_array_size,
0, sizeof(AppendRelInfo *) * add_size);
}
else
diff --git a/src/backend/parser/parse_oper.c b/src/backend/parser/parse_oper.c
index cf64afbd85..084d45e7e1 100644
--- a/src/backend/parser/parse_oper.c
+++ b/src/backend/parser/parse_oper.c
@@ -958,7 +958,7 @@ make_oper_cache_key(ParseState *pstate, OprCacheKey *key, List *opname,
DeconstructQualifiedName(opname, &schemaname, &opername);
/* ensure zero-fill for stable hashing */
- MemSet(key, 0, sizeof(OprCacheKey));
+ memset(key, 0, sizeof(OprCacheKey));
/* save operator name and input types into key */
strlcpy(key->oprname, opername, NAMEDATALEN);
diff --git a/src/backend/parser/parse_param.c b/src/backend/parser/parse_param.c
index f668abfcb3..03f022d6c9 100644
--- a/src/backend/parser/parse_param.c
+++ b/src/backend/parser/parse_param.c
@@ -150,7 +150,7 @@ variable_paramref_hook(ParseState *pstate, ParamRef *pref)
else
*parstate->paramTypes = (Oid *) palloc(paramno * sizeof(Oid));
/* Zero out the previously-unreferenced slots */
- MemSet(*parstate->paramTypes + *parstate->numParams,
+ memset(*parstate->paramTypes + *parstate->numParams,
0,
(paramno - *parstate->numParams) * sizeof(Oid));
*parstate->numParams = paramno;
diff --git a/src/backend/parser/parse_target.c b/src/backend/parser/parse_target.c
index 2a1d44b813..cb3b64afde 100644
--- a/src/backend/parser/parse_target.c
+++ b/src/backend/parser/parse_target.c
@@ -1596,7 +1596,7 @@ expandRecordVariable(ParseState *pstate, Var *var, int levelsup)
*/
ParseState mypstate;
- MemSet(&mypstate, 0, sizeof(mypstate));
+ memset(&mypstate, 0, sizeof(mypstate));
mypstate.parentParseState = pstate;
mypstate.p_rtable = rte->subquery->rtable;
/* don't bother filling the rest of the fake pstate */
@@ -1652,7 +1652,7 @@ expandRecordVariable(ParseState *pstate, Var *var, int levelsup)
ParseState mypstate;
Index levelsup;
- MemSet(&mypstate, 0, sizeof(mypstate));
+ memset(&mypstate, 0, sizeof(mypstate));
/* this loop must work, since GetCTEForRTE did */
for (levelsup = 0;
levelsup < rte->ctelevelsup + netlevelsup;
diff --git a/src/backend/port/win32/timer.c b/src/backend/port/win32/timer.c
index 3405253af3..67a434ab9e 100644
--- a/src/backend/port/win32/timer.c
+++ b/src/backend/port/win32/timer.c
@@ -98,7 +98,7 @@ setitimer(int which, const struct itimerval *value, struct itimerval *ovalue)
(errmsg_internal("could not create timer event: error code %lu",
GetLastError())));
- MemSet(&timerCommArea.value, 0, sizeof(struct itimerval));
+ memset(&timerCommArea.value, 0, sizeof(struct itimerval));
InitializeCriticalSection(&timerCommArea.crit_sec);
diff --git a/src/backend/postmaster/checkpointer.c b/src/backend/postmaster/checkpointer.c
index c937c39f50..02b1d2533e 100644
--- a/src/backend/postmaster/checkpointer.c
+++ b/src/backend/postmaster/checkpointer.c
@@ -902,7 +902,7 @@ CheckpointerShmemInit(void)
* requests array; this is so that CompactCheckpointerRequestQueue can
* assume that any pad bytes in the request structs are zeroes.
*/
- MemSet(CheckpointerShmem, 0, size);
+ memset(CheckpointerShmem, 0, size);
SpinLockInit(&CheckpointerShmem->ckpt_lck);
CheckpointerShmem->max_requests = NBuffers;
ConditionVariableInit(&CheckpointerShmem->start_cv);
diff --git a/src/backend/postmaster/pgarch.c b/src/backend/postmaster/pgarch.c
index 25e31c42e1..bd673df1b0 100644
--- a/src/backend/postmaster/pgarch.c
+++ b/src/backend/postmaster/pgarch.c
@@ -169,7 +169,7 @@ PgArchShmemInit(void)
if (!found)
{
/* First time through, so initialize */
- MemSet(PgArch, 0, PgArchShmemSize());
+ memset(PgArch, 0, PgArchShmemSize());
PgArch->pgprocno = INVALID_PGPROCNO;
SpinLockInit(&PgArch->arch_lck);
}
diff --git a/src/backend/replication/basebackup.c b/src/backend/replication/basebackup.c
index 5244823ff8..ce53e628b6 100644
--- a/src/backend/replication/basebackup.c
+++ b/src/backend/replication/basebackup.c
@@ -688,7 +688,7 @@ parse_basebackup_options(List *options, basebackup_options *opt)
bool o_compression_detail = false;
char *compression_detail_str = NULL;
- MemSet(opt, 0, sizeof(*opt));
+ memset(opt, 0, sizeof(*opt));
opt->manifest = MANIFEST_OPTION_NO;
opt->manifest_checksum_type = CHECKSUM_TYPE_CRC32C;
opt->compression = PG_COMPRESSION_NONE;
@@ -1687,7 +1687,7 @@ sendFile(bbsink *sink, const char *readfilename, const char *tarfilename,
size_t remaining = statbuf->st_size - len;
size_t nbytes = Min(sink->bbs_buffer_length, remaining);
- MemSet(sink->bbs_buffer, 0, nbytes);
+ memset(sink->bbs_buffer, 0, nbytes);
if (pg_checksum_update(&checksum_ctx,
(uint8 *) sink->bbs_buffer,
nbytes) < 0)
@@ -1790,7 +1790,7 @@ _tarWritePadding(bbsink *sink, int len)
if (pad > 0)
{
- MemSet(sink->bbs_buffer, 0, pad);
+ memset(sink->bbs_buffer, 0, pad);
bbsink_archive_contents(sink, pad);
}
}
diff --git a/src/backend/replication/logical/launcher.c b/src/backend/replication/logical/launcher.c
index bd5f78cf9a..4c4ad80f9a 100644
--- a/src/backend/replication/logical/launcher.c
+++ b/src/backend/replication/logical/launcher.c
@@ -953,8 +953,8 @@ pg_stat_get_subscription(PG_FUNCTION_ARGS)
worker_pid = worker.proc->pid;
- MemSet(values, 0, sizeof(values));
- MemSet(nulls, 0, sizeof(nulls));
+ memset(values, 0, sizeof(values));
+ memset(nulls, 0, sizeof(nulls));
values[0] = ObjectIdGetDatum(worker.subid);
if (OidIsValid(worker.relid))
diff --git a/src/backend/replication/logical/origin.c b/src/backend/replication/logical/origin.c
index 21937ab2d3..f5cb766f66 100644
--- a/src/backend/replication/logical/origin.c
+++ b/src/backend/replication/logical/origin.c
@@ -524,7 +524,7 @@ ReplicationOriginShmemInit(void)
{
int i;
- MemSet(replication_states_ctl, 0, ReplicationOriginShmemSize());
+ memset(replication_states_ctl, 0, ReplicationOriginShmemSize());
replication_states_ctl->tranche_id = LWTRANCHE_REPLICATION_ORIGIN_STATE;
diff --git a/src/backend/replication/slot.c b/src/backend/replication/slot.c
index e5c2102bcd..7071d04aaa 100644
--- a/src/backend/replication/slot.c
+++ b/src/backend/replication/slot.c
@@ -147,7 +147,7 @@ ReplicationSlotsShmemInit(void)
int i;
/* First time through, so initialize */
- MemSet(ReplicationSlotCtl, 0, ReplicationSlotsShmemSize());
+ memset(ReplicationSlotCtl, 0, ReplicationSlotsShmemSize());
for (i = 0; i < max_replication_slots; i++)
{
diff --git a/src/backend/replication/walreceiver.c b/src/backend/replication/walreceiver.c
index 9452932d59..3d37c1fe62 100644
--- a/src/backend/replication/walreceiver.c
+++ b/src/backend/replication/walreceiver.c
@@ -1410,7 +1410,7 @@ pg_stat_get_wal_receiver(PG_FUNCTION_ARGS)
* see details. Other users only get the pid value to know whether it
* is a WAL receiver, but no details.
*/
- MemSet(&nulls[1], true, sizeof(bool) * (tupdesc->natts - 1));
+ memset(&nulls[1], true, sizeof(bool) * (tupdesc->natts - 1));
}
else
{
diff --git a/src/backend/replication/walreceiverfuncs.c b/src/backend/replication/walreceiverfuncs.c
index 90798b9d53..3e4ac0788e 100644
--- a/src/backend/replication/walreceiverfuncs.c
+++ b/src/backend/replication/walreceiverfuncs.c
@@ -62,7 +62,7 @@ WalRcvShmemInit(void)
if (!found)
{
/* First time through, so initialize */
- MemSet(WalRcv, 0, WalRcvShmemSize());
+ memset(WalRcv, 0, WalRcvShmemSize());
WalRcv->walRcvState = WALRCV_STOPPED;
ConditionVariableInit(&WalRcv->walRcvStoppedCV);
SpinLockInit(&WalRcv->mutex);
diff --git a/src/backend/replication/walsender.c b/src/backend/replication/walsender.c
index e42671722a..800a831c69 100644
--- a/src/backend/replication/walsender.c
+++ b/src/backend/replication/walsender.c
@@ -437,7 +437,7 @@ IdentifySystem(void)
}
dest = CreateDestReceiver(DestRemoteSimple);
- MemSet(nulls, false, sizeof(nulls));
+ memset(nulls, false, sizeof(nulls));
/* need a tuple descriptor representing four columns */
tupdesc = CreateTemplateTupleDesc(4);
@@ -495,8 +495,8 @@ ReadReplicationSlot(ReadReplicationSlotCmd *cmd)
TupleDescInitBuiltinEntry(tupdesc, (AttrNumber) 3, "restart_tli",
INT8OID, -1, 0);
- MemSet(values, 0, READ_REPLICATION_SLOT_COLS * sizeof(Datum));
- MemSet(nulls, true, READ_REPLICATION_SLOT_COLS * sizeof(bool));
+ memset(values, 0, READ_REPLICATION_SLOT_COLS * sizeof(Datum));
+ memset(nulls, true, READ_REPLICATION_SLOT_COLS * sizeof(bool));
LWLockAcquire(ReplicationSlotControlLock, LW_SHARED);
slot = SearchNamedReplicationSlot(cmd->slotname, false);
@@ -878,7 +878,7 @@ StartReplication(StartReplicationCmd *cmd)
LSN_FORMAT_ARGS(sendTimeLineValidUpto));
dest = CreateDestReceiver(DestRemoteSimple);
- MemSet(nulls, false, sizeof(nulls));
+ memset(nulls, false, sizeof(nulls));
/*
* Need a tuple descriptor representing two columns. int8 may seem
@@ -1191,7 +1191,7 @@ CreateReplicationSlot(CreateReplicationSlotCmd *cmd)
LSN_FORMAT_ARGS(MyReplicationSlot->data.confirmed_flush));
dest = CreateDestReceiver(DestRemoteSimple);
- MemSet(nulls, false, sizeof(nulls));
+ memset(nulls, false, sizeof(nulls));
/*----------
* Need a tuple descriptor representing four columns:
@@ -3285,7 +3285,7 @@ WalSndShmemInit(void)
if (!found)
{
/* First time through, so initialize */
- MemSet(WalSndCtl, 0, WalSndShmemSize());
+ memset(WalSndCtl, 0, WalSndShmemSize());
for (i = 0; i < NUM_SYNC_REP_WAIT_MODE; i++)
SHMQueueInit(&(WalSndCtl->SyncRepQueue[i]));
@@ -3550,7 +3550,7 @@ pg_stat_get_wal_senders(PG_FUNCTION_ARGS)
* can see details. Other users only get the pid value to know
* it's a walsender, but no details.
*/
- MemSet(&nulls[1], true, PG_STAT_GET_WAL_SENDERS_COLS - 1);
+ memset(&nulls[1], true, PG_STAT_GET_WAL_SENDERS_COLS - 1);
}
else
{
diff --git a/src/backend/rewrite/rewriteDefine.c b/src/backend/rewrite/rewriteDefine.c
index 185bf5fbff..862aafeab7 100644
--- a/src/backend/rewrite/rewriteDefine.c
+++ b/src/backend/rewrite/rewriteDefine.c
@@ -81,7 +81,7 @@ InsertRule(const char *rulname,
/*
* Set up *nulls and *values arrays
*/
- MemSet(nulls, false, sizeof(nulls));
+ memset(nulls, false, sizeof(nulls));
namestrcpy(&rname, rulname);
values[Anum_pg_rewrite_rulename - 1] = NameGetDatum(&rname);
@@ -115,7 +115,7 @@ InsertRule(const char *rulname,
/*
* When replacing, we don't need to replace every attribute
*/
- MemSet(replaces, false, sizeof(replaces));
+ memset(replaces, false, sizeof(replaces));
replaces[Anum_pg_rewrite_ev_type - 1] = true;
replaces[Anum_pg_rewrite_is_instead - 1] = true;
replaces[Anum_pg_rewrite_ev_qual - 1] = true;
diff --git a/src/backend/storage/buffer/bufmgr.c b/src/backend/storage/buffer/bufmgr.c
index ae13011d27..eecf64aa98 100644
--- a/src/backend/storage/buffer/bufmgr.c
+++ b/src/backend/storage/buffer/bufmgr.c
@@ -981,7 +981,7 @@ ReadBuffer_common(SMgrRelation smgr, char relpersistence, ForkNumber forkNum,
if (isExtend)
{
/* new buffers are zero-filled */
- MemSet((char *) bufBlock, 0, BLCKSZ);
+ memset((char *) bufBlock, 0, BLCKSZ);
/* don't set checksum for all-zero page */
smgrextend(smgr, forkNum, blockNum, (char *) bufBlock, false);
@@ -999,7 +999,7 @@ ReadBuffer_common(SMgrRelation smgr, char relpersistence, ForkNumber forkNum,
* just wants us to allocate a buffer.
*/
if (mode == RBM_ZERO_AND_LOCK || mode == RBM_ZERO_AND_CLEANUP_LOCK)
- MemSet((char *) bufBlock, 0, BLCKSZ);
+ memset((char *) bufBlock, 0, BLCKSZ);
else
{
instr_time io_start,
@@ -1029,7 +1029,7 @@ ReadBuffer_common(SMgrRelation smgr, char relpersistence, ForkNumber forkNum,
errmsg("invalid page in block %u of relation %s; zeroing out page",
blockNum,
relpath(smgr->smgr_rnode, forkNum))));
- MemSet((char *) bufBlock, 0, BLCKSZ);
+ memset((char *) bufBlock, 0, BLCKSZ);
}
else
ereport(ERROR,
diff --git a/src/backend/storage/file/fd.c b/src/backend/storage/file/fd.c
index 24704b6a02..b13cbd18ae 100644
--- a/src/backend/storage/file/fd.c
+++ b/src/backend/storage/file/fd.c
@@ -891,7 +891,7 @@ InitFileAccess(void)
(errcode(ERRCODE_OUT_OF_MEMORY),
errmsg("out of memory")));
- MemSet((char *) &(VfdCache[0]), 0, sizeof(Vfd));
+ memset((char *) &(VfdCache[0]), 0, sizeof(Vfd));
VfdCache->fd = VFD_CLOSED;
SizeVfdCache = 1;
@@ -1439,7 +1439,7 @@ AllocateVfd(void)
*/
for (i = SizeVfdCache; i < newCacheSize; i++)
{
- MemSet((char *) &(VfdCache[i]), 0, sizeof(Vfd));
+ memset((char *) &(VfdCache[i]), 0, sizeof(Vfd));
VfdCache[i].nextFree = i + 1;
VfdCache[i].fd = VFD_CLOSED;
}
diff --git a/src/backend/storage/ipc/pmsignal.c b/src/backend/storage/ipc/pmsignal.c
index 1c668d183c..b8d40ad5f7 100644
--- a/src/backend/storage/ipc/pmsignal.c
+++ b/src/backend/storage/ipc/pmsignal.c
@@ -141,7 +141,7 @@ PMSignalShmemInit(void)
if (!found)
{
/* initialize all flags to zeroes */
- MemSet(unvolatize(PMSignalData *, PMSignalState), 0, PMSignalShmemSize());
+ memset(unvolatize(PMSignalData *, PMSignalState), 0, PMSignalShmemSize());
PMSignalState->num_child_flags = MaxLivePostmasterChildren();
}
}
diff --git a/src/backend/storage/ipc/procsignal.c b/src/backend/storage/ipc/procsignal.c
index 21a9fc0fdd..ac5fcdc6ed 100644
--- a/src/backend/storage/ipc/procsignal.c
+++ b/src/backend/storage/ipc/procsignal.c
@@ -142,7 +142,7 @@ ProcSignalShmemInit(void)
ProcSignalSlot *slot = &ProcSignal->psh_slot[i];
slot->pss_pid = 0;
- MemSet(slot->pss_signalFlags, 0, sizeof(slot->pss_signalFlags));
+ memset(slot->pss_signalFlags, 0, sizeof(slot->pss_signalFlags));
pg_atomic_init_u64(&slot->pss_barrierGeneration, PG_UINT64_MAX);
pg_atomic_init_u32(&slot->pss_barrierCheckMask, 0);
ConditionVariableInit(&slot->pss_barrierCV);
@@ -173,7 +173,7 @@ ProcSignalInit(int pss_idx)
MyProcPid, pss_idx);
/* Clear out any leftover signal reasons */
- MemSet(slot->pss_signalFlags, 0, NUM_PROCSIGNALS * sizeof(sig_atomic_t));
+ memset(slot->pss_signalFlags, 0, NUM_PROCSIGNALS * sizeof(sig_atomic_t));
/*
* Initialize barrier state. Since we're a brand-new process, there
diff --git a/src/backend/storage/large_object/inv_api.c b/src/backend/storage/large_object/inv_api.c
index d204482a61..bf5016bbbf 100644
--- a/src/backend/storage/large_object/inv_api.c
+++ b/src/backend/storage/large_object/inv_api.c
@@ -546,7 +546,7 @@ inv_read(LargeObjectDesc *obj_desc, char *buf, int nbytes)
{
n = pageoff - obj_desc->offset;
n = (n <= (nbytes - nread)) ? n : (nbytes - nread);
- MemSet(buf + nread, 0, n);
+ memset(buf + nread, 0, n);
nread += n;
obj_desc->offset += n;
}
@@ -689,7 +689,7 @@ inv_write(LargeObjectDesc *obj_desc, const char *buf, int nbytes)
*/
off = (int) (obj_desc->offset % LOBLKSIZE);
if (off > len)
- MemSet(workb + len, 0, off - len);
+ memset(workb + len, 0, off - len);
/*
* Insert appropriate portion of new data
@@ -734,7 +734,7 @@ inv_write(LargeObjectDesc *obj_desc, const char *buf, int nbytes)
*/
off = (int) (obj_desc->offset % LOBLKSIZE);
if (off > 0)
- MemSet(workb, 0, off);
+ memset(workb, 0, off);
/*
* Insert appropriate portion of new data
@@ -874,7 +874,7 @@ inv_truncate(LargeObjectDesc *obj_desc, int64 len)
*/
off = len % LOBLKSIZE;
if (off > pagelen)
- MemSet(workb + pagelen, 0, off - pagelen);
+ memset(workb + pagelen, 0, off - pagelen);
/* compute length of new page */
SET_VARSIZE(&workbuf.hdr, off + VARHDRSZ);
@@ -913,7 +913,7 @@ inv_truncate(LargeObjectDesc *obj_desc, int64 len)
*/
off = len % LOBLKSIZE;
if (off > 0)
- MemSet(workb, 0, off);
+ memset(workb, 0, off);
/* compute length of new page */
SET_VARSIZE(&workbuf.hdr, off + VARHDRSZ);
diff --git a/src/backend/storage/lmgr/deadlock.c b/src/backend/storage/lmgr/deadlock.c
index cd9c0418ec..6c6c1eb167 100644
--- a/src/backend/storage/lmgr/deadlock.c
+++ b/src/backend/storage/lmgr/deadlock.c
@@ -918,8 +918,8 @@ TopoSort(LOCK *lock,
* present. If so, the constraint is relevant to this wait queue; if not,
* it isn't.
*/
- MemSet(beforeConstraints, 0, queue_size * sizeof(int));
- MemSet(afterConstraints, 0, queue_size * sizeof(int));
+ memset(beforeConstraints, 0, queue_size * sizeof(int));
+ memset(afterConstraints, 0, queue_size * sizeof(int));
for (i = 0; i < nConstraints; i++)
{
/*
diff --git a/src/backend/storage/lmgr/lock.c b/src/backend/storage/lmgr/lock.c
index 5f5803f681..ec2ea6c42e 100644
--- a/src/backend/storage/lmgr/lock.c
+++ b/src/backend/storage/lmgr/lock.c
@@ -603,7 +603,7 @@ LockHeldByMe(const LOCKTAG *locktag, LOCKMODE lockmode)
/*
* See if there is a LOCALLOCK entry for this lock and lockmode
*/
- MemSet(&localtag, 0, sizeof(localtag)); /* must clear padding */
+ memset(&localtag, 0, sizeof(localtag)); /* must clear padding */
localtag.lock = *locktag;
localtag.mode = lockmode;
@@ -658,7 +658,7 @@ LockHasWaiters(const LOCKTAG *locktag, LOCKMODE lockmode, bool sessionLock)
/*
* Find the LOCALLOCK entry for this lock and lockmode
*/
- MemSet(&localtag, 0, sizeof(localtag)); /* must clear padding */
+ memset(&localtag, 0, sizeof(localtag)); /* must clear padding */
localtag.lock = *locktag;
localtag.mode = lockmode;
@@ -820,7 +820,7 @@ LockAcquireExtended(const LOCKTAG *locktag,
/*
* Find or create a LOCALLOCK entry for this lock and lockmode
*/
- MemSet(&localtag, 0, sizeof(localtag)); /* must clear padding */
+ memset(&localtag, 0, sizeof(localtag)); /* must clear padding */
localtag.lock = *locktag;
localtag.mode = lockmode;
@@ -1198,8 +1198,8 @@ SetupLockInTable(LockMethod lockMethodTable, PGPROC *proc,
ProcQueueInit(&(lock->waitProcs));
lock->nRequested = 0;
lock->nGranted = 0;
- MemSet(lock->requested, 0, sizeof(int) * MAX_LOCKMODES);
- MemSet(lock->granted, 0, sizeof(int) * MAX_LOCKMODES);
+ memset(lock->requested, 0, sizeof(int) * MAX_LOCKMODES);
+ memset(lock->granted, 0, sizeof(int) * MAX_LOCKMODES);
LOCK_PRINT("LockAcquire: new", lock, lockmode);
}
else
@@ -1999,7 +1999,7 @@ LockRelease(const LOCKTAG *locktag, LOCKMODE lockmode, bool sessionLock)
/*
* Find the LOCALLOCK entry for this lock and lockmode
*/
- MemSet(&localtag, 0, sizeof(localtag)); /* must clear padding */
+ memset(&localtag, 0, sizeof(localtag)); /* must clear padding */
localtag.lock = *locktag;
localtag.mode = lockmode;
@@ -4271,8 +4271,8 @@ lock_twophase_recover(TransactionId xid, uint16 info,
ProcQueueInit(&(lock->waitProcs));
lock->nRequested = 0;
lock->nGranted = 0;
- MemSet(lock->requested, 0, sizeof(int) * MAX_LOCKMODES);
- MemSet(lock->granted, 0, sizeof(int) * MAX_LOCKMODES);
+ memset(lock->requested, 0, sizeof(int) * MAX_LOCKMODES);
+ memset(lock->granted, 0, sizeof(int) * MAX_LOCKMODES);
LOCK_PRINT("lock_twophase_recover: new", lock, lockmode);
}
else
diff --git a/src/backend/storage/lmgr/lwlock.c b/src/backend/storage/lmgr/lwlock.c
index 8aef909037..c09b127cf6 100644
--- a/src/backend/storage/lmgr/lwlock.c
+++ b/src/backend/storage/lmgr/lwlock.c
@@ -397,7 +397,7 @@ get_lwlock_stats_entry(LWLock *lock)
return &lwlock_stats_dummy;
/* Fetch or create the entry. */
- MemSet(&key, 0, sizeof(key));
+ memset(&key, 0, sizeof(key));
key.tranche = lock->tranche;
key.instance = lock;
lwstats = hash_search(lwlock_stats_htab, &key, HASH_ENTER, &found);
diff --git a/src/backend/storage/lmgr/proc.c b/src/backend/storage/lmgr/proc.c
index 37aaab1338..e732d61220 100644
--- a/src/backend/storage/lmgr/proc.c
+++ b/src/backend/storage/lmgr/proc.c
@@ -192,7 +192,7 @@ InitProcGlobal(void)
* between groups.
*/
procs = (PGPROC *) ShmemAlloc(TotalProcs * sizeof(PGPROC));
- MemSet(procs, 0, TotalProcs * sizeof(PGPROC));
+ memset(procs, 0, TotalProcs * sizeof(PGPROC));
ProcGlobal->allProcs = procs;
/* XXX allProcCount isn't really all of them; it excludes prepared xacts */
ProcGlobal->allProcCount = MaxBackends + NUM_AUXILIARY_PROCS;
@@ -206,11 +206,11 @@ InitProcGlobal(void)
*/
ProcGlobal->xids =
(TransactionId *) ShmemAlloc(TotalProcs * sizeof(*ProcGlobal->xids));
- MemSet(ProcGlobal->xids, 0, TotalProcs * sizeof(*ProcGlobal->xids));
+ memset(ProcGlobal->xids, 0, TotalProcs * sizeof(*ProcGlobal->xids));
ProcGlobal->subxidStates = (XidCacheStatus *) ShmemAlloc(TotalProcs * sizeof(*ProcGlobal->subxidStates));
- MemSet(ProcGlobal->subxidStates, 0, TotalProcs * sizeof(*ProcGlobal->subxidStates));
+ memset(ProcGlobal->subxidStates, 0, TotalProcs * sizeof(*ProcGlobal->subxidStates));
ProcGlobal->statusFlags = (uint8 *) ShmemAlloc(TotalProcs * sizeof(*ProcGlobal->statusFlags));
- MemSet(ProcGlobal->statusFlags, 0, TotalProcs * sizeof(*ProcGlobal->statusFlags));
+ memset(ProcGlobal->statusFlags, 0, TotalProcs * sizeof(*ProcGlobal->statusFlags));
for (i = 0; i < TotalProcs; i++)
{
diff --git a/src/backend/storage/page/bufpage.c b/src/backend/storage/page/bufpage.c
index a3d367db51..b75cb7e943 100644
--- a/src/backend/storage/page/bufpage.c
+++ b/src/backend/storage/page/bufpage.c
@@ -49,14 +49,14 @@ PageInit(Page page, Size pageSize, Size specialSize)
Assert(pageSize > specialSize + SizeOfPageHeaderData);
/* Make sure all fields of page are zero, as well as unused space */
- MemSet(p, 0, pageSize);
+ memset(p, 0, pageSize);
p->pd_flags = 0;
p->pd_lower = SizeOfPageHeaderData;
p->pd_upper = pageSize - specialSize;
p->pd_special = pageSize - specialSize;
PageSetPageSizeAndVersion(page, pageSize, PG_PAGE_LAYOUT_VERSION);
- /* p->pd_prune_xid = InvalidTransactionId; done by above MemSet */
+ /* p->pd_prune_xid = InvalidTransactionId; done by above memset */
}
diff --git a/src/backend/storage/smgr/md.c b/src/backend/storage/smgr/md.c
index 43edaf5d87..4aae2decbb 100644
--- a/src/backend/storage/smgr/md.c
+++ b/src/backend/storage/smgr/md.c
@@ -684,7 +684,7 @@ mdread(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum,
* update a block that was later truncated away.
*/
if (zero_damaged_pages || InRecovery)
- MemSet(buffer, 0, BLCKSZ);
+ memset(buffer, 0, BLCKSZ);
else
ereport(ERROR,
(errcode(ERRCODE_DATA_CORRUPTED),
diff --git a/src/backend/tcop/fastpath.c b/src/backend/tcop/fastpath.c
index d429aa4663..c6ec536463 100644
--- a/src/backend/tcop/fastpath.c
+++ b/src/backend/tcop/fastpath.c
@@ -131,7 +131,7 @@ fetch_fp_info(Oid func_id, struct fp_info *fip)
* time. [No longer really an issue since we don't save the struct
* fp_info across transactions anymore, but keep it anyway.]
*/
- MemSet(fip, 0, sizeof(struct fp_info));
+ memset(fip, 0, sizeof(struct fp_info));
fip->funcid = InvalidOid;
func_htp = SearchSysCache1(PROCOID, ObjectIdGetDatum(func_id));
diff --git a/src/backend/utils/activity/backend_progress.c b/src/backend/utils/activity/backend_progress.c
index f29199725b..d12402a050 100644
--- a/src/backend/utils/activity/backend_progress.c
+++ b/src/backend/utils/activity/backend_progress.c
@@ -33,7 +33,7 @@ pgstat_progress_start_command(ProgressCommandType cmdtype, Oid relid)
PGSTAT_BEGIN_WRITE_ACTIVITY(beentry);
beentry->st_progress_command = cmdtype;
beentry->st_progress_command_target = relid;
- MemSet(&beentry->st_progress_param, 0, sizeof(beentry->st_progress_param));
+ memset(&beentry->st_progress_param, 0, sizeof(beentry->st_progress_param));
PGSTAT_END_WRITE_ACTIVITY(beentry);
}
diff --git a/src/backend/utils/activity/backend_status.c b/src/backend/utils/activity/backend_status.c
index c7ed1e6d7a..96f0a815c1 100644
--- a/src/backend/utils/activity/backend_status.c
+++ b/src/backend/utils/activity/backend_status.c
@@ -131,7 +131,7 @@ CreateSharedBackendStatus(void)
/*
* We're the first - initialize.
*/
- MemSet(BackendStatusArray, 0, size);
+ memset(BackendStatusArray, 0, size);
}
/* Create or attach to the shared appname buffer */
@@ -141,7 +141,7 @@ CreateSharedBackendStatus(void)
if (!found)
{
- MemSet(BackendAppnameBuffer, 0, size);
+ memset(BackendAppnameBuffer, 0, size);
/* Initialize st_appname pointers. */
buffer = BackendAppnameBuffer;
@@ -159,7 +159,7 @@ CreateSharedBackendStatus(void)
if (!found)
{
- MemSet(BackendClientHostnameBuffer, 0, size);
+ memset(BackendClientHostnameBuffer, 0, size);
/* Initialize st_clienthostname pointers. */
buffer = BackendClientHostnameBuffer;
@@ -180,7 +180,7 @@ CreateSharedBackendStatus(void)
if (!found)
{
- MemSet(BackendActivityBuffer, 0, BackendActivityBufferSize);
+ memset(BackendActivityBuffer, 0, BackendActivityBufferSize);
/* Initialize st_activity pointers. */
buffer = BackendActivityBuffer;
@@ -201,7 +201,7 @@ CreateSharedBackendStatus(void)
{
PgBackendSSLStatus *ptr;
- MemSet(BackendSslStatusBuffer, 0, size);
+ memset(BackendSslStatusBuffer, 0, size);
/* Initialize st_sslstatus pointers. */
ptr = BackendSslStatusBuffer;
@@ -223,7 +223,7 @@ CreateSharedBackendStatus(void)
{
PgBackendGSSStatus *ptr;
- MemSet(BackendGssStatusBuffer, 0, size);
+ memset(BackendGssStatusBuffer, 0, size);
/* Initialize st_gssstatus pointers. */
ptr = BackendGssStatusBuffer;
@@ -355,7 +355,7 @@ pgstat_bestart(void)
memcpy(&lbeentry.st_clientaddr, &MyProcPort->raddr,
sizeof(lbeentry.st_clientaddr));
else
- MemSet(&lbeentry.st_clientaddr, 0, sizeof(lbeentry.st_clientaddr));
+ memset(&lbeentry.st_clientaddr, 0, sizeof(lbeentry.st_clientaddr));
#ifdef USE_SSL
if (MyProcPort && MyProcPort->ssl_in_use)
diff --git a/src/backend/utils/activity/pgstat_bgwriter.c b/src/backend/utils/activity/pgstat_bgwriter.c
index fbb1edc527..ced6e10a2a 100644
--- a/src/backend/utils/activity/pgstat_bgwriter.c
+++ b/src/backend/utils/activity/pgstat_bgwriter.c
@@ -55,7 +55,7 @@ pgstat_report_bgwriter(void)
/*
* Clear out the statistics buffer, so it can be re-used.
*/
- MemSet(&PendingBgWriterStats, 0, sizeof(PendingBgWriterStats));
+ memset(&PendingBgWriterStats, 0, sizeof(PendingBgWriterStats));
}
/*
diff --git a/src/backend/utils/activity/pgstat_checkpointer.c b/src/backend/utils/activity/pgstat_checkpointer.c
index af8d513e7b..ba64aec5c5 100644
--- a/src/backend/utils/activity/pgstat_checkpointer.c
+++ b/src/backend/utils/activity/pgstat_checkpointer.c
@@ -61,7 +61,7 @@ pgstat_report_checkpointer(void)
/*
* Clear out the statistics buffer, so it can be re-used.
*/
- MemSet(&PendingCheckpointerStats, 0, sizeof(PendingCheckpointerStats));
+ memset(&PendingCheckpointerStats, 0, sizeof(PendingCheckpointerStats));
}
/*
diff --git a/src/backend/utils/activity/pgstat_slru.c b/src/backend/utils/activity/pgstat_slru.c
index d0b85b62a5..0c1eb70251 100644
--- a/src/backend/utils/activity/pgstat_slru.c
+++ b/src/backend/utils/activity/pgstat_slru.c
@@ -185,7 +185,7 @@ pgstat_slru_flush(bool nowait)
}
/* done, clear the pending entry */
- MemSet(pending_SLRUStats, 0, sizeof(pending_SLRUStats));
+ memset(pending_SLRUStats, 0, sizeof(pending_SLRUStats));
LWLockRelease(&stats_shmem->lock);
diff --git a/src/backend/utils/activity/pgstat_wal.c b/src/backend/utils/activity/pgstat_wal.c
index 5a878bd115..d6f9866ba7 100644
--- a/src/backend/utils/activity/pgstat_wal.c
+++ b/src/backend/utils/activity/pgstat_wal.c
@@ -117,7 +117,7 @@ pgstat_flush_wal(bool nowait)
/*
* Clear out the statistics buffer, so it can be re-used.
*/
- MemSet(&PendingWalStats, 0, sizeof(PendingWalStats));
+ memset(&PendingWalStats, 0, sizeof(PendingWalStats));
return false;
}
diff --git a/src/backend/utils/adt/acl.c b/src/backend/utils/adt/acl.c
index 772c04155c..2ee786dc6b 100644
--- a/src/backend/utils/adt/acl.c
+++ b/src/backend/utils/adt/acl.c
@@ -1819,7 +1819,7 @@ aclexplode(PG_FUNCTION_ARGS)
values[2] = CStringGetTextDatum(convert_aclright_to_string(priv_bit));
values[3] = BoolGetDatum((ACLITEM_GET_GOPTIONS(*aidata) & priv_bit) != 0);
- MemSet(nulls, 0, sizeof(nulls));
+ memset(nulls, 0, sizeof(nulls));
tuple = heap_form_tuple(funcctx->tuple_desc, values, nulls);
result = HeapTupleGetDatum(tuple);
diff --git a/src/backend/utils/adt/arrayfuncs.c b/src/backend/utils/adt/arrayfuncs.c
index 2570e5e630..14b7532b67 100644
--- a/src/backend/utils/adt/arrayfuncs.c
+++ b/src/backend/utils/adt/arrayfuncs.c
@@ -746,7 +746,7 @@ ReadArrayStr(char *arrayStr,
prod[MAXDIM];
mda_get_prod(ndim, dim, prod);
- MemSet(indx, 0, sizeof(indx));
+ memset(indx, 0, sizeof(indx));
/* Initialize is-null markers to true */
memset(nulls, true, nitems * sizeof(bool));
@@ -2460,7 +2460,7 @@ array_set_element(Datum arraydatum,
bits8 *newnullbitmap = ARR_NULLBITMAP(newarray);
/* Zero the bitmap to take care of marking inserted positions null */
- MemSet(newnullbitmap, 0, (newnitems + 7) / 8);
+ memset(newnullbitmap, 0, (newnitems + 7) / 8);
/* Fix the inserted value */
if (addedafter)
array_set_isnull(newnullbitmap, newnitems - 1, isNull);
@@ -3077,7 +3077,7 @@ array_set_slice(Datum arraydatum,
bits8 *oldnullbitmap = ARR_NULLBITMAP(array);
/* Zero the bitmap to handle marking inserted positions null */
- MemSet(newnullbitmap, 0, (nitems + 7) / 8);
+ memset(newnullbitmap, 0, (nitems + 7) / 8);
array_bitmap_copy(newnullbitmap, addedbefore,
oldnullbitmap, 0,
itemsbefore);
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 4c12c4d663..99ef3df049 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -5011,7 +5011,7 @@ pg_timezone_abbrevs(PG_FUNCTION_ARGS)
break;
}
- MemSet(nulls, 0, sizeof(nulls));
+ memset(nulls, 0, sizeof(nulls));
/*
* Convert name to text, using upcasing conversion that is the inverse of
@@ -5024,7 +5024,7 @@ pg_timezone_abbrevs(PG_FUNCTION_ARGS)
values[0] = CStringGetTextDatum(buffer);
/* Convert offset (in seconds) to an interval; can't overflow */
- MemSet(&itm_in, 0, sizeof(struct pg_itm_in));
+ memset(&itm_in, 0, sizeof(struct pg_itm_in));
itm_in.tm_usec = (int64) gmtoffset * USECS_PER_SEC;
resInterval = (Interval *) palloc(sizeof(Interval));
(void) itmin2interval(&itm_in, resInterval);
@@ -5088,13 +5088,13 @@ pg_timezone_names(PG_FUNCTION_ARGS)
if (tzn && strlen(tzn) > 31)
continue;
- MemSet(nulls, 0, sizeof(nulls));
+ memset(nulls, 0, sizeof(nulls));
values[0] = CStringGetTextDatum(pg_get_timezone_name(tz));
values[1] = CStringGetTextDatum(tzn ? tzn : "");
/* Convert tzoff to an interval; can't overflow */
- MemSet(&itm_in, 0, sizeof(struct pg_itm_in));
+ memset(&itm_in, 0, sizeof(struct pg_itm_in));
itm_in.tm_usec = (int64) -tzoff * USECS_PER_SEC;
resInterval = (Interval *) palloc(sizeof(Interval));
(void) itmin2interval(&itm_in, resInterval);
diff --git a/src/backend/utils/adt/formatting.c b/src/backend/utils/adt/formatting.c
index e909c1a200..31105b9519 100644
--- a/src/backend/utils/adt/formatting.c
+++ b/src/backend/utils/adt/formatting.c
@@ -5626,7 +5626,7 @@ NUM_processor(FormatNode *node, NUMDesc *Num, char *inout,
const char *pattern;
int pattern_len;
- MemSet(Np, 0, sizeof(NUMProc));
+ memset(Np, 0, sizeof(NUMProc));
Np->Num = Num;
Np->is_to_char = is_to_char;
diff --git a/src/backend/utils/adt/jsonfuncs.c b/src/backend/utils/adt/jsonfuncs.c
index d427bdfbe0..52ff421e36 100644
--- a/src/backend/utils/adt/jsonfuncs.c
+++ b/src/backend/utils/adt/jsonfuncs.c
@@ -3190,7 +3190,7 @@ allocate_record_info(MemoryContext mcxt, int ncolumns)
data->record_type = InvalidOid;
data->record_typmod = 0;
data->ncolumns = ncolumns;
- MemSet(data->columns, 0, sizeof(ColumnIOData) * ncolumns);
+ memset(data->columns, 0, sizeof(ColumnIOData) * ncolumns);
return data;
}
@@ -3254,7 +3254,7 @@ populate_record(TupleDesc tupdesc,
if (record->record_type != tupdesc->tdtypeid ||
record->record_typmod != tupdesc->tdtypmod)
{
- MemSet(record, 0, offsetof(RecordIOData, columns) +
+ memset(record, 0, offsetof(RecordIOData, columns) +
ncolumns * sizeof(ColumnIOData));
record->record_type = tupdesc->tdtypeid;
record->record_typmod = tupdesc->tdtypmod;
diff --git a/src/backend/utils/adt/lockfuncs.c b/src/backend/utils/adt/lockfuncs.c
index 023a004ac8..6c5f9ebaee 100644
--- a/src/backend/utils/adt/lockfuncs.c
+++ b/src/backend/utils/adt/lockfuncs.c
@@ -230,8 +230,8 @@ pg_lock_status(PG_FUNCTION_ARGS)
/*
* Form tuple with appropriate data.
*/
- MemSet(values, 0, sizeof(values));
- MemSet(nulls, false, sizeof(nulls));
+ memset(values, 0, sizeof(values));
+ memset(nulls, false, sizeof(nulls));
if (instance->locktag.locktag_type <= LOCKTAG_LAST_TYPE)
locktypename = LockTagTypeNames[instance->locktag.locktag_type];
@@ -369,8 +369,8 @@ pg_lock_status(PG_FUNCTION_ARGS)
/*
* Form tuple with appropriate data.
*/
- MemSet(values, 0, sizeof(values));
- MemSet(nulls, false, sizeof(nulls));
+ memset(values, 0, sizeof(values));
+ memset(nulls, false, sizeof(nulls));
/* lock type */
lockType = GET_PREDICATELOCKTARGETTAG_TYPE(*predTag);
diff --git a/src/backend/utils/adt/partitionfuncs.c b/src/backend/utils/adt/partitionfuncs.c
index 0243bc061f..468bd7b34f 100644
--- a/src/backend/utils/adt/partitionfuncs.c
+++ b/src/backend/utils/adt/partitionfuncs.c
@@ -126,8 +126,8 @@ pg_partition_tree(PG_FUNCTION_ARGS)
/*
* Form tuple with appropriate data.
*/
- MemSet(nulls, 0, sizeof(nulls));
- MemSet(values, 0, sizeof(values));
+ memset(nulls, 0, sizeof(nulls));
+ memset(values, 0, sizeof(values));
/* relid */
values[0] = ObjectIdGetDatum(relid);
diff --git a/src/backend/utils/adt/pgstatfuncs.c b/src/backend/utils/adt/pgstatfuncs.c
index 893690dad5..94db404d02 100644
--- a/src/backend/utils/adt/pgstatfuncs.c
+++ b/src/backend/utils/adt/pgstatfuncs.c
@@ -492,8 +492,8 @@ pg_stat_get_progress_info(PG_FUNCTION_ARGS)
bool nulls[PG_STAT_GET_PROGRESS_COLS];
int i;
- MemSet(values, 0, sizeof(values));
- MemSet(nulls, 0, sizeof(nulls));
+ memset(values, 0, sizeof(values));
+ memset(nulls, 0, sizeof(nulls));
local_beentry = pgstat_fetch_stat_local_beentry(curr_backend);
@@ -559,8 +559,8 @@ pg_stat_get_activity(PG_FUNCTION_ARGS)
const char *wait_event_type = NULL;
const char *wait_event = NULL;
- MemSet(values, 0, sizeof(values));
- MemSet(nulls, 0, sizeof(nulls));
+ memset(values, 0, sizeof(values));
+ memset(nulls, 0, sizeof(nulls));
/* Get the next one in the list */
local_beentry = pgstat_fetch_stat_local_beentry(curr_backend);
@@ -1753,8 +1753,8 @@ pg_stat_get_wal(PG_FUNCTION_ARGS)
PgStat_WalStats *wal_stats;
/* Initialise values and NULL flags arrays */
- MemSet(values, 0, sizeof(values));
- MemSet(nulls, 0, sizeof(nulls));
+ memset(values, 0, sizeof(values));
+ memset(nulls, 0, sizeof(nulls));
/* Initialise attributes information in the tuple descriptor */
tupdesc = CreateTemplateTupleDesc(PG_STAT_GET_WAL_COLS);
@@ -1837,8 +1837,8 @@ pg_stat_get_slru(PG_FUNCTION_ARGS)
break;
stat = stats[i];
- MemSet(values, 0, sizeof(values));
- MemSet(nulls, 0, sizeof(nulls));
+ memset(values, 0, sizeof(values));
+ memset(nulls, 0, sizeof(nulls));
values[0] = PointerGetDatum(cstring_to_text(name));
values[1] = Int64GetDatum(stat.blocks_zeroed);
@@ -2206,8 +2206,8 @@ pg_stat_get_archiver(PG_FUNCTION_ARGS)
PgStat_ArchiverStats *archiver_stats;
/* Initialise values and NULL flags arrays */
- MemSet(values, 0, sizeof(values));
- MemSet(nulls, 0, sizeof(nulls));
+ memset(values, 0, sizeof(values));
+ memset(nulls, 0, sizeof(nulls));
/* Initialise attributes information in the tuple descriptor */
tupdesc = CreateTemplateTupleDesc(7);
@@ -2280,8 +2280,8 @@ pg_stat_get_replication_slot(PG_FUNCTION_ARGS)
PgStat_StatReplSlotEntry allzero;
/* Initialise values and NULL flags arrays */
- MemSet(values, 0, sizeof(values));
- MemSet(nulls, 0, sizeof(nulls));
+ memset(values, 0, sizeof(values));
+ memset(nulls, 0, sizeof(nulls));
/* Initialise attributes information in the tuple descriptor */
tupdesc = CreateTemplateTupleDesc(PG_STAT_GET_REPLICATION_SLOT_COLS);
@@ -2369,8 +2369,8 @@ pg_stat_get_subscription_stats(PG_FUNCTION_ARGS)
BlessTupleDesc(tupdesc);
/* Initialise values and NULL flags arrays */
- MemSet(values, 0, sizeof(values));
- MemSet(nulls, 0, sizeof(nulls));
+ memset(values, 0, sizeof(values));
+ memset(nulls, 0, sizeof(nulls));
if (!subentry)
{
diff --git a/src/backend/utils/adt/rowtypes.c b/src/backend/utils/adt/rowtypes.c
index db843a0fbf..7c9eefc741 100644
--- a/src/backend/utils/adt/rowtypes.c
+++ b/src/backend/utils/adt/rowtypes.c
@@ -132,7 +132,7 @@ record_in(PG_FUNCTION_ARGS)
if (my_extra->record_type != tupType ||
my_extra->record_typmod != tupTypmod)
{
- MemSet(my_extra, 0,
+ memset(my_extra, 0,
offsetof(RecordIOData, columns) +
ncolumns * sizeof(ColumnIOData));
my_extra->record_type = tupType;
@@ -349,7 +349,7 @@ record_out(PG_FUNCTION_ARGS)
if (my_extra->record_type != tupType ||
my_extra->record_typmod != tupTypmod)
{
- MemSet(my_extra, 0,
+ memset(my_extra, 0,
offsetof(RecordIOData, columns) +
ncolumns * sizeof(ColumnIOData));
my_extra->record_type = tupType;
@@ -505,7 +505,7 @@ record_recv(PG_FUNCTION_ARGS)
if (my_extra->record_type != tupType ||
my_extra->record_typmod != tupTypmod)
{
- MemSet(my_extra, 0,
+ memset(my_extra, 0,
offsetof(RecordIOData, columns) +
ncolumns * sizeof(ColumnIOData));
my_extra->record_type = tupType;
@@ -716,7 +716,7 @@ record_send(PG_FUNCTION_ARGS)
if (my_extra->record_type != tupType ||
my_extra->record_typmod != tupTypmod)
{
- MemSet(my_extra, 0,
+ memset(my_extra, 0,
offsetof(RecordIOData, columns) +
ncolumns * sizeof(ColumnIOData));
my_extra->record_type = tupType;
@@ -876,7 +876,7 @@ record_cmp(FunctionCallInfo fcinfo)
my_extra->record2_type != tupType2 ||
my_extra->record2_typmod != tupTypmod2)
{
- MemSet(my_extra->columns, 0, ncols * sizeof(ColumnCompareData));
+ memset(my_extra->columns, 0, ncols * sizeof(ColumnCompareData));
my_extra->record1_type = tupType1;
my_extra->record1_typmod = tupTypmod1;
my_extra->record2_type = tupType2;
@@ -1120,7 +1120,7 @@ record_eq(PG_FUNCTION_ARGS)
my_extra->record2_type != tupType2 ||
my_extra->record2_typmod != tupTypmod2)
{
- MemSet(my_extra->columns, 0, ncols * sizeof(ColumnCompareData));
+ memset(my_extra->columns, 0, ncols * sizeof(ColumnCompareData));
my_extra->record1_type = tupType1;
my_extra->record1_typmod = tupTypmod1;
my_extra->record2_type = tupType2;
@@ -1382,7 +1382,7 @@ record_image_cmp(FunctionCallInfo fcinfo)
my_extra->record2_type != tupType2 ||
my_extra->record2_typmod != tupTypmod2)
{
- MemSet(my_extra->columns, 0, ncols * sizeof(ColumnCompareData));
+ memset(my_extra->columns, 0, ncols * sizeof(ColumnCompareData));
my_extra->record1_type = tupType1;
my_extra->record1_typmod = tupTypmod1;
my_extra->record2_type = tupType2;
@@ -1628,7 +1628,7 @@ record_image_eq(PG_FUNCTION_ARGS)
my_extra->record2_type != tupType2 ||
my_extra->record2_typmod != tupTypmod2)
{
- MemSet(my_extra->columns, 0, ncols * sizeof(ColumnCompareData));
+ memset(my_extra->columns, 0, ncols * sizeof(ColumnCompareData));
my_extra->record1_type = tupType1;
my_extra->record1_typmod = tupTypmod1;
my_extra->record2_type = tupType2;
@@ -1822,7 +1822,7 @@ hash_record(PG_FUNCTION_ARGS)
if (my_extra->record1_type != tupType ||
my_extra->record1_typmod != tupTypmod)
{
- MemSet(my_extra->columns, 0, ncolumns * sizeof(ColumnCompareData));
+ memset(my_extra->columns, 0, ncolumns * sizeof(ColumnCompareData));
my_extra->record1_type = tupType;
my_extra->record1_typmod = tupTypmod;
}
@@ -1943,7 +1943,7 @@ hash_record_extended(PG_FUNCTION_ARGS)
if (my_extra->record1_type != tupType ||
my_extra->record1_typmod != tupTypmod)
{
- MemSet(my_extra->columns, 0, ncolumns * sizeof(ColumnCompareData));
+ memset(my_extra->columns, 0, ncolumns * sizeof(ColumnCompareData));
my_extra->record1_type = tupType;
my_extra->record1_typmod = tupTypmod;
}
diff --git a/src/backend/utils/adt/selfuncs.c b/src/backend/utils/adt/selfuncs.c
index fa1f589fad..243feb2340 100644
--- a/src/backend/utils/adt/selfuncs.c
+++ b/src/backend/utils/adt/selfuncs.c
@@ -4992,7 +4992,7 @@ examine_variable(PlannerInfo *root, Node *node, int varRelid,
RelOptInfo *onerel;
/* Make sure we don't return dangling pointers in vardata */
- MemSet(vardata, 0, sizeof(VariableStatData));
+ memset(vardata, 0, sizeof(VariableStatData));
/* Save the exposed type of the expression */
vardata->vartype = exprType(node);
@@ -6797,7 +6797,7 @@ btcostestimate(PlannerInfo *root, IndexPath *path, double loop_count,
/*
* Now do generic index cost estimation.
*/
- MemSet(&costs, 0, sizeof(costs));
+ memset(&costs, 0, sizeof(costs));
costs.numIndexTuples = numIndexTuples;
genericcostestimate(root, path, loop_count, &costs);
@@ -6842,7 +6842,7 @@ btcostestimate(PlannerInfo *root, IndexPath *path, double loop_count,
* ordering, but don't negate it entirely. Before 8.0 we divided the
* correlation by the number of columns, but that seems too strong.)
*/
- MemSet(&vardata, 0, sizeof(vardata));
+ memset(&vardata, 0, sizeof(vardata));
if (index->indexkeys[0] != 0)
{
@@ -6949,7 +6949,7 @@ hashcostestimate(PlannerInfo *root, IndexPath *path, double loop_count,
{
GenericCosts costs;
- MemSet(&costs, 0, sizeof(costs));
+ memset(&costs, 0, sizeof(costs));
genericcostestimate(root, path, loop_count, &costs);
@@ -6995,7 +6995,7 @@ gistcostestimate(PlannerInfo *root, IndexPath *path, double loop_count,
GenericCosts costs;
Cost descentCost;
- MemSet(&costs, 0, sizeof(costs));
+ memset(&costs, 0, sizeof(costs));
genericcostestimate(root, path, loop_count, &costs);
@@ -7052,7 +7052,7 @@ spgcostestimate(PlannerInfo *root, IndexPath *path, double loop_count,
GenericCosts costs;
Cost descentCost;
- MemSet(&costs, 0, sizeof(costs));
+ memset(&costs, 0, sizeof(costs));
genericcostestimate(root, path, loop_count, &costs);
diff --git a/src/backend/utils/adt/timestamp.c b/src/backend/utils/adt/timestamp.c
index f70f829d83..0821a4e639 100644
--- a/src/backend/utils/adt/timestamp.c
+++ b/src/backend/utils/adt/timestamp.c
@@ -5800,7 +5800,7 @@ generate_series_timestamp(PG_FUNCTION_ARGS)
fctx->step = *step;
/* Determine sign of the interval */
- MemSet(&interval_zero, 0, sizeof(Interval));
+ memset(&interval_zero, 0, sizeof(Interval));
fctx->step_sign = interval_cmp_internal(&fctx->step, &interval_zero);
if (fctx->step_sign == 0)
@@ -5880,7 +5880,7 @@ generate_series_timestamptz(PG_FUNCTION_ARGS)
fctx->step = *step;
/* Determine sign of the interval */
- MemSet(&interval_zero, 0, sizeof(Interval));
+ memset(&interval_zero, 0, sizeof(Interval));
fctx->step_sign = interval_cmp_internal(&fctx->step, &interval_zero);
if (fctx->step_sign == 0)
diff --git a/src/backend/utils/adt/tsgistidx.c b/src/backend/utils/adt/tsgistidx.c
index b8fd96dd7b..9b73030fa8 100644
--- a/src/backend/utils/adt/tsgistidx.c
+++ b/src/backend/utils/adt/tsgistidx.c
@@ -141,7 +141,7 @@ makesign(BITVECP sign, SignTSVector *a, int siglen)
len = ARRNELEM(a);
int32 *ptr = GETARR(a);
- MemSet((void *) sign, 0, siglen);
+ memset((void *) sign, 0, siglen);
for (k = 0; k < len; k++)
HASH(sign, ptr[k], siglen);
}
@@ -753,7 +753,7 @@ gtsvector_picksplit(PG_FUNCTION_ARGS)
if (ISALLTRUE(datum_l) || cache[j].allistrue)
{
if (!ISALLTRUE(datum_l))
- MemSet((void *) GETSIGN(datum_l), 0xff, siglen);
+ memset((void *) GETSIGN(datum_l), 0xff, siglen);
}
else
{
@@ -769,7 +769,7 @@ gtsvector_picksplit(PG_FUNCTION_ARGS)
if (ISALLTRUE(datum_r) || cache[j].allistrue)
{
if (!ISALLTRUE(datum_r))
- MemSet((void *) GETSIGN(datum_r), 0xff, siglen);
+ memset((void *) GETSIGN(datum_r), 0xff, siglen);
}
else
{
diff --git a/src/backend/utils/adt/tsrank.c b/src/backend/utils/adt/tsrank.c
index 3858fc5928..da8a777fad 100644
--- a/src/backend/utils/adt/tsrank.c
+++ b/src/backend/utils/adt/tsrank.c
@@ -883,7 +883,7 @@ calc_rank_cd(const float4 *arrdata, TSVector txt, TSQuery query, int method)
return 0.0;
}
- MemSet(&ext, 0, sizeof(CoverExt));
+ memset(&ext, 0, sizeof(CoverExt));
while (Cover(doc, doclen, &qr, &ext))
{
double Cpos = 0.0;
diff --git a/src/backend/utils/adt/varbit.c b/src/backend/utils/adt/varbit.c
index 73e41e0808..b3541908e2 100644
--- a/src/backend/utils/adt/varbit.c
+++ b/src/backend/utils/adt/varbit.c
@@ -1419,7 +1419,7 @@ bitshiftleft(PG_FUNCTION_ARGS)
/* If we shifted all the bits out, return an all-zero string */
if (shft >= VARBITLEN(arg))
{
- MemSet(r, 0, VARBITBYTES(arg));
+ memset(r, 0, VARBITBYTES(arg));
PG_RETURN_VARBIT_P(result);
}
@@ -1432,7 +1432,7 @@ bitshiftleft(PG_FUNCTION_ARGS)
/* Special case: we can do a memcpy */
len = VARBITBYTES(arg) - byte_shift;
memcpy(r, p, len);
- MemSet(r + len, 0, byte_shift);
+ memset(r + len, 0, byte_shift);
}
else
{
@@ -1486,7 +1486,7 @@ bitshiftright(PG_FUNCTION_ARGS)
/* If we shifted all the bits out, return an all-zero string */
if (shft >= VARBITLEN(arg))
{
- MemSet(r, 0, VARBITBYTES(arg));
+ memset(r, 0, VARBITBYTES(arg));
PG_RETURN_VARBIT_P(result);
}
@@ -1495,7 +1495,7 @@ bitshiftright(PG_FUNCTION_ARGS)
p = VARBITS(arg);
/* Set the first part of the result to 0 */
- MemSet(r, 0, byte_shift);
+ memset(r, 0, byte_shift);
r += byte_shift;
if (ishift == 0)
diff --git a/src/backend/utils/cache/relfilenodemap.c b/src/backend/utils/cache/relfilenodemap.c
index 70c323c720..5dbf3c0b7d 100644
--- a/src/backend/utils/cache/relfilenodemap.c
+++ b/src/backend/utils/cache/relfilenodemap.c
@@ -95,7 +95,7 @@ InitializeRelfilenodeMap(void)
CreateCacheMemoryContext();
/* build skey */
- MemSet(&relfilenode_skey, 0, sizeof(relfilenode_skey));
+ memset(&relfilenode_skey, 0, sizeof(relfilenode_skey));
for (i = 0; i < 2; i++)
{
@@ -153,7 +153,7 @@ RelidByRelfilenode(Oid reltablespace, Oid relfilenode)
if (reltablespace == MyDatabaseTableSpace)
reltablespace = 0;
- MemSet(&key, 0, sizeof(key));
+ memset(&key, 0, sizeof(key));
key.reltablespace = reltablespace;
key.relfilenode = relfilenode;
diff --git a/src/backend/utils/cache/ts_cache.c b/src/backend/utils/cache/ts_cache.c
index 24808dfbb1..fbb4df7bf2 100644
--- a/src/backend/utils/cache/ts_cache.c
+++ b/src/backend/utils/cache/ts_cache.c
@@ -176,7 +176,7 @@ lookup_ts_parser_cache(Oid prsId)
Assert(!found); /* it wasn't there a moment ago */
}
- MemSet(entry, 0, sizeof(TSParserCacheEntry));
+ memset(entry, 0, sizeof(TSParserCacheEntry));
entry->prsId = prsId;
entry->startOid = prs->prsstart;
entry->tokenOid = prs->prstoken;
@@ -306,7 +306,7 @@ lookup_ts_dictionary_cache(Oid dictId)
MemoryContextCopyAndSetIdentifier(saveCtx, NameStr(dict->dictname));
}
- MemSet(entry, 0, sizeof(TSDictionaryCacheEntry));
+ memset(entry, 0, sizeof(TSDictionaryCacheEntry));
entry->dictId = dictId;
entry->dictCtx = saveCtx;
@@ -455,7 +455,7 @@ lookup_ts_config_cache(Oid cfgId)
}
}
- MemSet(entry, 0, sizeof(TSConfigCacheEntry));
+ memset(entry, 0, sizeof(TSConfigCacheEntry));
entry->cfgId = cfgId;
entry->prsId = cfg->cfgparser;
@@ -468,7 +468,7 @@ lookup_ts_config_cache(Oid cfgId)
* see the entries in maptokentype order, and in mapseqno order for
* each token type, even though we didn't explicitly ask for that.
*/
- MemSet(maplists, 0, sizeof(maplists));
+ memset(maplists, 0, sizeof(maplists));
maxtokentype = 0;
ndicts = 0;
diff --git a/src/backend/utils/cache/typcache.c b/src/backend/utils/cache/typcache.c
index 808f9ebd0d..0fe0255b02 100644
--- a/src/backend/utils/cache/typcache.c
+++ b/src/backend/utils/cache/typcache.c
@@ -396,7 +396,7 @@ lookup_type_cache(Oid type_id, int flags)
HASH_ENTER, &found);
Assert(!found); /* it wasn't there a moment ago */
- MemSet(typentry, 0, sizeof(TypeCacheEntry));
+ memset(typentry, 0, sizeof(TypeCacheEntry));
/* These fields can never change, by definition */
typentry->type_id = type_id;
diff --git a/src/backend/utils/error/elog.c b/src/backend/utils/error/elog.c
index 55ee5423af..e1f4aa302b 100644
--- a/src/backend/utils/error/elog.c
+++ b/src/backend/utils/error/elog.c
@@ -443,7 +443,7 @@ errstart(int elevel, const char *domain)
/* Initialize data for this error frame */
edata = &errordata[errordata_stack_depth];
- MemSet(edata, 0, sizeof(ErrorData));
+ memset(edata, 0, sizeof(ErrorData));
edata->elevel = elevel;
edata->output_to_server = output_to_server;
edata->output_to_client = output_to_client;
@@ -1476,7 +1476,7 @@ format_elog_string(const char *fmt,...)
/* Initialize a mostly-dummy error frame */
edata = &errdata;
- MemSet(edata, 0, sizeof(ErrorData));
+ memset(edata, 0, sizeof(ErrorData));
/* the default text domain is the backend's */
edata->domain = save_format_domain ? save_format_domain : PG_TEXTDOMAIN("postgres");
/* set the errno to be used to interpret %m */
@@ -1872,7 +1872,7 @@ GetErrorContextStack(void)
* Things look good so far, so initialize our error frame
*/
edata = &errordata[errordata_stack_depth];
- MemSet(edata, 0, sizeof(ErrorData));
+ memset(edata, 0, sizeof(ErrorData));
/*
* Set up assoc_context to be the caller's context, so any allocations
diff --git a/src/backend/utils/fmgr/dfmgr.c b/src/backend/utils/fmgr/dfmgr.c
index 7f9ea97280..ee69dc8bf2 100644
--- a/src/backend/utils/fmgr/dfmgr.c
+++ b/src/backend/utils/fmgr/dfmgr.c
@@ -228,7 +228,7 @@ internal_load_library(const char *libname)
(errcode(ERRCODE_OUT_OF_MEMORY),
errmsg("out of memory")));
- MemSet(file_scanner, 0, offsetof(DynamicFileList, filename));
+ memset(file_scanner, 0, offsetof(DynamicFileList, filename));
strcpy(file_scanner->filename, libname);
file_scanner->device = stat_buf.st_dev;
#ifndef WIN32
diff --git a/src/backend/utils/hash/dynahash.c b/src/backend/utils/hash/dynahash.c
index 3babde8d70..27c5f3e80f 100644
--- a/src/backend/utils/hash/dynahash.c
+++ b/src/backend/utils/hash/dynahash.c
@@ -388,7 +388,7 @@ hash_create(const char *tabname, long nelem, const HASHCTL *info, int flags)
/* Initialize the hash header, plus a copy of the table name */
hashp = (HTAB *) DynaHashAlloc(sizeof(HTAB) + strlen(tabname) + 1);
- MemSet(hashp, 0, sizeof(HTAB));
+ memset(hashp, 0, sizeof(HTAB));
hashp->tabname = (char *) (hashp + 1);
strcpy(hashp->tabname, tabname);
@@ -627,7 +627,7 @@ hdefault(HTAB *hashp)
{
HASHHDR *hctl = hashp->hctl;
- MemSet(hctl, 0, sizeof(HASHHDR));
+ memset(hctl, 0, sizeof(HASHHDR));
hctl->dsize = DEF_DIRSIZE;
hctl->nsegs = 0;
@@ -1666,7 +1666,7 @@ dir_realloc(HTAB *hashp)
if (p != NULL)
{
memcpy(p, old_p, old_dirsize);
- MemSet(((char *) p) + old_dirsize, 0, new_dirsize - old_dirsize);
+ memset(((char *) p) + old_dirsize, 0, new_dirsize - old_dirsize);
hashp->dir = p;
hashp->hctl->dsize = new_dsize;
@@ -1692,7 +1692,7 @@ seg_alloc(HTAB *hashp)
if (!segp)
return NULL;
- MemSet(segp, 0, sizeof(HASHBUCKET) * hashp->ssize);
+ memset(segp, 0, sizeof(HASHBUCKET) * hashp->ssize);
return segp;
}
diff --git a/src/backend/utils/misc/guc.c b/src/backend/utils/misc/guc.c
index 8e9b71375c..2169604b02 100644
--- a/src/backend/utils/misc/guc.c
+++ b/src/backend/utils/misc/guc.c
@@ -11936,7 +11936,7 @@ check_wal_consistency_checking(char **newval, void **extra, GucSource source)
bool newwalconsistency[RM_MAX_ID + 1];
/* Initialize the array */
- MemSet(newwalconsistency, 0, (RM_MAX_ID + 1) * sizeof(bool));
+ memset(newwalconsistency, 0, (RM_MAX_ID + 1) * sizeof(bool));
/* Need a modifiable copy of string */
rawstring = pstrdup(*newval);
diff --git a/src/backend/utils/misc/ps_status.c b/src/backend/utils/misc/ps_status.c
index ec314c03f5..ca05b180c9 100644
--- a/src/backend/utils/misc/ps_status.c
+++ b/src/backend/utils/misc/ps_status.c
@@ -393,7 +393,7 @@ set_ps_display(const char *activity)
#ifdef PS_USE_CLOBBER_ARGV
/* pad unused memory; need only clobber remainder of old status string */
if (last_status_len > ps_buffer_cur_len)
- MemSet(ps_buffer + ps_buffer_cur_len, PS_PADDING,
+ memset(ps_buffer + ps_buffer_cur_len, PS_PADDING,
last_status_len - ps_buffer_cur_len);
last_status_len = ps_buffer_cur_len;
#endif /* PS_USE_CLOBBER_ARGV */
diff --git a/src/backend/utils/misc/timeout.c b/src/backend/utils/misc/timeout.c
index 6f5e08bc30..16ff6250b1 100644
--- a/src/backend/utils/misc/timeout.c
+++ b/src/backend/utils/misc/timeout.c
@@ -216,7 +216,7 @@ schedule_alarm(TimestampTz now)
long secs;
int usecs;
- MemSet(&timeval, 0, sizeof(struct itimerval));
+ memset(&timeval, 0, sizeof(struct itimerval));
/*
* If we think there's a signal pending, but current time is more than
diff --git a/src/backend/utils/mmgr/portalmem.c b/src/backend/utils/mmgr/portalmem.c
index d549f66d4a..25ced094b9 100644
--- a/src/backend/utils/mmgr/portalmem.c
+++ b/src/backend/utils/mmgr/portalmem.c
@@ -1152,7 +1152,7 @@ pg_cursor(PG_FUNCTION_ARGS)
if (!portal->visible)
continue;
- MemSet(nulls, 0, sizeof(nulls));
+ memset(nulls, 0, sizeof(nulls));
values[0] = CStringGetTextDatum(portal->name);
values[1] = CStringGetTextDatum(portal->sourceText);
diff --git a/src/backend/utils/sort/logtape.c b/src/backend/utils/sort/logtape.c
index c384f98e13..4a6dbb91ca 100644
--- a/src/backend/utils/sort/logtape.c
+++ b/src/backend/utils/sort/logtape.c
@@ -254,7 +254,7 @@ ltsWriteBlock(LogicalTapeSet *lts, long blocknum, void *buffer)
{
PGAlignedBlock zerobuf;
- MemSet(zerobuf.data, 0, sizeof(zerobuf));
+ memset(zerobuf.data, 0, sizeof(zerobuf));
ltsWriteBlock(lts, lts->nBlocksWritten, zerobuf.data);
}
diff --git a/src/bin/pg_basebackup/pg_basebackup.c b/src/bin/pg_basebackup/pg_basebackup.c
index 4adb170d46..3f112e8082 100644
--- a/src/bin/pg_basebackup/pg_basebackup.c
+++ b/src/bin/pg_basebackup/pg_basebackup.c
@@ -457,7 +457,7 @@ reached_end_position(XLogRecPtr segendpos, uint32 timeline,
FD_ZERO(&fds);
FD_SET(bgpipe[0], &fds);
- MemSet(&tv, 0, sizeof(tv));
+ memset(&tv, 0, sizeof(tv));
r = select(bgpipe[0] + 1, &fds, NULL, NULL, &tv);
if (r == 1)
@@ -466,7 +466,7 @@ reached_end_position(XLogRecPtr segendpos, uint32 timeline,
uint32 hi,
lo;
- MemSet(xlogend, 0, sizeof(xlogend));
+ memset(xlogend, 0, sizeof(xlogend));
r = read(bgpipe[0], xlogend, sizeof(xlogend) - 1);
if (r < 0)
pg_fatal("could not read from ready pipe: %m");
@@ -532,7 +532,7 @@ LogStreamerMain(logstreamer_param *param)
in_log_streamer = true;
- MemSet(&stream, 0, sizeof(stream));
+ memset(&stream, 0, sizeof(stream));
stream.startpos = param->startptr;
stream.timeline = param->timeline;
stream.sysidentifier = param->sysidentifier;
@@ -1961,7 +1961,7 @@ BaseBackup(char *compression_algorithm, char *compression_detail,
else
starttli = latesttli;
PQclear(res);
- MemSet(xlogend, 0, sizeof(xlogend));
+ memset(xlogend, 0, sizeof(xlogend));
if (verbose && includewal != NO_WAL)
pg_log_info("write-ahead log start point: %s on timeline %u",
diff --git a/src/bin/pg_basebackup/pg_receivewal.c b/src/bin/pg_basebackup/pg_receivewal.c
index ea3902c971..c621588ceb 100644
--- a/src/bin/pg_basebackup/pg_receivewal.c
+++ b/src/bin/pg_basebackup/pg_receivewal.c
@@ -567,7 +567,7 @@ StreamLog(void)
StreamCtl stream;
char *sysidentifier;
- MemSet(&stream, 0, sizeof(stream));
+ memset(&stream, 0, sizeof(stream));
/*
* Connect in replication mode to the server
diff --git a/src/bin/pg_basebackup/walmethods.c b/src/bin/pg_basebackup/walmethods.c
index cc292718da..bf838ef80e 100644
--- a/src/bin/pg_basebackup/walmethods.c
+++ b/src/bin/pg_basebackup/walmethods.c
@@ -1114,7 +1114,7 @@ tar_close(Walfile f, WalCloseMethod method)
{
char zerobuf[TAR_BLOCK_SIZE];
- MemSet(zerobuf, 0, padding);
+ memset(zerobuf, 0, padding);
if (tar_write(f, zerobuf, padding) != padding)
return -1;
}
@@ -1234,7 +1234,7 @@ tar_finish(void)
}
/* A tarfile always ends with two empty blocks */
- MemSet(zerobuf, 0, sizeof(zerobuf));
+ memset(zerobuf, 0, sizeof(zerobuf));
if (tar_data->compression_algorithm == PG_COMPRESSION_NONE)
{
errno = 0;
diff --git a/src/common/fe_memutils.c b/src/common/fe_memutils.c
index 21fcce5430..9e433db245 100644
--- a/src/common/fe_memutils.c
+++ b/src/common/fe_memutils.c
@@ -39,7 +39,7 @@ pg_malloc_internal(size_t size, int flags)
}
if ((flags & MCXT_ALLOC_ZERO) != 0)
- MemSet(tmp, 0, size);
+ memset(tmp, 0, size);
return tmp;
}
diff --git a/src/common/ip.c b/src/common/ip.c
index cd73d49679..a574b58de2 100644
--- a/src/common/ip.c
+++ b/src/common/ip.c
@@ -171,7 +171,7 @@ getaddrinfo_unix(const char *path, const struct addrinfo *hintsp,
*result = NULL;
- MemSet(&hints, 0, sizeof(hints));
+ memset(&hints, 0, sizeof(hints));
if (strlen(path) >= sizeof(unp->sun_path))
return EAI_FAIL;
diff --git a/src/interfaces/libpq/fe-connect.c b/src/interfaces/libpq/fe-connect.c
index 6e936bbff3..5cdfc0bb40 100644
--- a/src/interfaces/libpq/fe-connect.c
+++ b/src/interfaces/libpq/fe-connect.c
@@ -2378,7 +2378,7 @@ keep_going: /* We will come back to here until there is
ch = &conn->connhost[conn->whichhost];
/* Initialize hint structure */
- MemSet(&hint, 0, sizeof(hint));
+ memset(&hint, 0, sizeof(hint));
hint.ai_socktype = SOCK_STREAM;
conn->addrlist_family = hint.ai_family = AF_UNSPEC;
@@ -3977,7 +3977,7 @@ makeEmptyPGconn(void)
return conn;
/* Zero all pointers and booleans */
- MemSet(conn, 0, sizeof(PGconn));
+ memset(conn, 0, sizeof(PGconn));
/* install default notice hooks */
conn->noticeHooks.noticeRec = defaultNoticeReceiver;
@@ -5545,7 +5545,7 @@ conninfo_init(PQExpBuffer errorMessage)
memcpy(opt_dest, cur_opt, sizeof(PQconninfoOption));
opt_dest++;
}
- MemSet(opt_dest, 0, sizeof(PQconninfoOption));
+ memset(opt_dest, 0, sizeof(PQconninfoOption));
return options;
}
diff --git a/src/interfaces/libpq/fe-lobj.c b/src/interfaces/libpq/fe-lobj.c
index 075a5ed85b..b59df84baf 100644
--- a/src/interfaces/libpq/fe-lobj.c
+++ b/src/interfaces/libpq/fe-lobj.c
@@ -884,7 +884,7 @@ lo_initialize(PGconn *conn)
libpq_gettext("out of memory\n"));
return -1;
}
- MemSet((char *) lobjfuncs, 0, sizeof(PGlobjfuncs));
+ memset((char *) lobjfuncs, 0, sizeof(PGlobjfuncs));
/*
* Execute the query to get all the functions at once. (Not all of them
diff --git a/src/interfaces/libpq/fe-protocol3.c b/src/interfaces/libpq/fe-protocol3.c
index 10c76daf6e..a8321fae0a 100644
--- a/src/interfaces/libpq/fe-protocol3.c
+++ b/src/interfaces/libpq/fe-protocol3.c
@@ -557,7 +557,7 @@ getRowDescriptions(PGconn *conn, int msgLength)
errmsg = NULL; /* means "out of memory", see below */
goto advance_and_error;
}
- MemSet(result->attDescs, 0, nfields * sizeof(PGresAttDesc));
+ memset(result->attDescs, 0, nfields * sizeof(PGresAttDesc));
}
/* result->binary is true only if ALL columns are binary */
@@ -703,7 +703,7 @@ getParamDescriptions(PGconn *conn, int msgLength)
pqResultAlloc(result, nparams * sizeof(PGresParamDesc), true);
if (!result->paramDescs)
goto advance_and_error;
- MemSet(result->paramDescs, 0, nparams * sizeof(PGresParamDesc));
+ memset(result->paramDescs, 0, nparams * sizeof(PGresParamDesc));
}
/* get parameter info */
@@ -1529,7 +1529,7 @@ getCopyStart(PGconn *conn, ExecStatusType copytype)
pqResultAlloc(result, nfields * sizeof(PGresAttDesc), true);
if (!result->attDescs)
goto failure;
- MemSet(result->attDescs, 0, nfields * sizeof(PGresAttDesc));
+ memset(result->attDescs, 0, nfields * sizeof(PGresAttDesc));
}
for (i = 0; i < nfields; i++)
diff --git a/src/pl/plperl/plperl.c b/src/pl/plperl/plperl.c
index edb93ec1c4..25d98a81c8 100644
--- a/src/pl/plperl/plperl.c
+++ b/src/pl/plperl/plperl.c
@@ -1844,7 +1844,7 @@ plperl_call_handler(PG_FUNCTION_ARGS)
plperl_call_data this_call_data;
/* Initialize current-call status record */
- MemSet(&this_call_data, 0, sizeof(this_call_data));
+ memset(&this_call_data, 0, sizeof(this_call_data));
this_call_data.fcinfo = fcinfo;
PG_TRY();
@@ -1890,7 +1890,7 @@ plperl_inline_handler(PG_FUNCTION_ARGS)
ErrorContextCallback pl_error_context;
/* Initialize current-call status record */
- MemSet(&this_call_data, 0, sizeof(this_call_data));
+ memset(&this_call_data, 0, sizeof(this_call_data));
/* Set up a callback for error reporting */
pl_error_context.callback = plperl_inline_callback;
@@ -1903,9 +1903,9 @@ plperl_inline_handler(PG_FUNCTION_ARGS)
* plperl_call_perl_func(). In particular note that this sets things up
* with no arguments passed, and a result type of VOID.
*/
- MemSet(fake_fcinfo, 0, SizeForFunctionCallInfo(0));
- MemSet(&flinfo, 0, sizeof(flinfo));
- MemSet(&desc, 0, sizeof(desc));
+ memset(fake_fcinfo, 0, SizeForFunctionCallInfo(0));
+ memset(&flinfo, 0, sizeof(flinfo));
+ memset(&desc, 0, sizeof(desc));
fake_fcinfo->flinfo = &flinfo;
flinfo.fn_oid = InvalidOid;
flinfo.fn_mcxt = CurrentMemoryContext;
diff --git a/src/pl/plpgsql/src/pl_comp.c b/src/pl/plpgsql/src/pl_comp.c
index b791c23f06..d7053ad914 100644
--- a/src/pl/plpgsql/src/pl_comp.c
+++ b/src/pl/plpgsql/src/pl_comp.c
@@ -2455,7 +2455,7 @@ compute_function_hashkey(FunctionCallInfo fcinfo,
bool forValidator)
{
/* Make sure any unused bytes of the struct are zero */
- MemSet(hashkey, 0, sizeof(PLpgSQL_func_hashkey));
+ memset(hashkey, 0, sizeof(PLpgSQL_func_hashkey));
/* get function OID */
hashkey->funcOid = fcinfo->flinfo->fn_oid;
diff --git a/src/pl/plpgsql/src/pl_handler.c b/src/pl/plpgsql/src/pl_handler.c
index 190d286f1c..d51de407e1 100644
--- a/src/pl/plpgsql/src/pl_handler.c
+++ b/src/pl/plpgsql/src/pl_handler.c
@@ -340,8 +340,8 @@ plpgsql_inline_handler(PG_FUNCTION_ARGS)
* plpgsql_exec_function(). In particular note that this sets things up
* with no arguments passed.
*/
- MemSet(fake_fcinfo, 0, SizeForFunctionCallInfo(0));
- MemSet(&flinfo, 0, sizeof(flinfo));
+ memset(fake_fcinfo, 0, SizeForFunctionCallInfo(0));
+ memset(&flinfo, 0, sizeof(flinfo));
fake_fcinfo->flinfo = &flinfo;
flinfo.fn_oid = InvalidOid;
flinfo.fn_mcxt = CurrentMemoryContext;
@@ -517,20 +517,20 @@ plpgsql_validator(PG_FUNCTION_ARGS)
* Set up a fake fcinfo with just enough info to satisfy
* plpgsql_compile().
*/
- MemSet(fake_fcinfo, 0, SizeForFunctionCallInfo(0));
- MemSet(&flinfo, 0, sizeof(flinfo));
+ memset(fake_fcinfo, 0, SizeForFunctionCallInfo(0));
+ memset(&flinfo, 0, sizeof(flinfo));
fake_fcinfo->flinfo = &flinfo;
flinfo.fn_oid = funcoid;
flinfo.fn_mcxt = CurrentMemoryContext;
if (is_dml_trigger)
{
- MemSet(&trigdata, 0, sizeof(trigdata));
+ memset(&trigdata, 0, sizeof(trigdata));
trigdata.type = T_TriggerData;
fake_fcinfo->context = (Node *) &trigdata;
}
else if (is_event_trigger)
{
- MemSet(&etrigdata, 0, sizeof(etrigdata));
+ memset(&etrigdata, 0, sizeof(etrigdata));
etrigdata.type = T_EventTriggerData;
fake_fcinfo->context = (Node *) &etrigdata;
}
diff --git a/src/pl/plpython/plpy_main.c b/src/pl/plpython/plpy_main.c
index 0bce106495..dc707da034 100644
--- a/src/pl/plpython/plpy_main.c
+++ b/src/pl/plpython/plpy_main.c
@@ -277,13 +277,13 @@ plpython3_inline_handler(PG_FUNCTION_ARGS)
if (SPI_connect_ext(codeblock->atomic ? 0 : SPI_OPT_NONATOMIC) != SPI_OK_CONNECT)
elog(ERROR, "SPI_connect failed");
- MemSet(fcinfo, 0, SizeForFunctionCallInfo(0));
- MemSet(&flinfo, 0, sizeof(flinfo));
+ memset(fcinfo, 0, SizeForFunctionCallInfo(0));
+ memset(&flinfo, 0, sizeof(flinfo));
fake_fcinfo->flinfo = &flinfo;
flinfo.fn_oid = InvalidOid;
flinfo.fn_mcxt = CurrentMemoryContext;
- MemSet(&proc, 0, sizeof(PLyProcedure));
+ memset(&proc, 0, sizeof(PLyProcedure));
proc.mcxt = AllocSetContextCreate(TopMemoryContext,
"__plpython_inline_block",
ALLOCSET_DEFAULT_SIZES);
diff --git a/src/port/snprintf.c b/src/port/snprintf.c
index abb1c59770..2e929e4e8e 100644
--- a/src/port/snprintf.c
+++ b/src/port/snprintf.c
@@ -761,7 +761,7 @@ find_arguments(const char *format, va_list args,
/* Initialize to "no dollar arguments known" */
last_dollar = 0;
- MemSet(argtypes, 0, sizeof(argtypes));
+ memset(argtypes, 0, sizeof(argtypes));
/*
* This loop must accept the same format strings as the one in dopr().
diff --git a/src/test/modules/test_predtest/test_predtest.c b/src/test/modules/test_predtest/test_predtest.c
index 3b19e0eadc..1d2b1d4956 100644
--- a/src/test/modules/test_predtest/test_predtest.c
+++ b/src/test/modules/test_predtest/test_predtest.c
@@ -204,7 +204,7 @@ test_predtest(PG_FUNCTION_ARGS)
"w_r_holds", BOOLOID, -1, 0);
tupdesc = BlessTupleDesc(tupdesc);
- MemSet(nulls, 0, sizeof(nulls));
+ memset(nulls, 0, sizeof(nulls));
values[0] = BoolGetDatum(strong_implied_by);
values[1] = BoolGetDatum(weak_implied_by);
values[2] = BoolGetDatum(strong_refuted_by);
diff --git a/src/test/regress/regress.c b/src/test/regress/regress.c
index ba3532a51e..e13db0d683 100644
--- a/src/test/regress/regress.c
+++ b/src/test/regress/regress.c
@@ -1199,7 +1199,7 @@ test_enc_conversion(PG_FUNCTION_ARGS)
pfree(dst);
}
- MemSet(nulls, 0, sizeof(nulls));
+ memset(nulls, 0, sizeof(nulls));
values[0] = Int32GetDatum(convertedbytes);
values[1] = PointerGetDatum(retval);
tuple = heap_form_tuple(tupdesc, values, nulls);
On Thu, 19 May 2022 at 11:20, Tom Lane <tgl@sss.pgh.pa.us> wrote:
The thing that makes this a bit more difficult than it might be is
the special cases we have for known-aligned and so on targets, which
are particularly critical for palloc0 and makeNode etc. So there's
more than one case to look into. But I'd argue that those special
cases are actually what we want to worry about the most: zeroing
relatively small, known-aligned node structs is THE use case.
I think the makeNode() trickery would be harder to get rid of, or for
that matter, anything where the size/alignment is unknown at compile
time. I think the more interesting ones that we might be able to get
rid of are the ones where the alignment and size *are* known at
compile time. Also probably anything that passes a compile-time const
that's not 0 will fallback on memset anyway, so might as well be
removed to tidy things up.
It just all seems a bit untidy when you look at functions like
ExecStoreAllNullTuple() which use a mix of memset and MemSet without
any apparent explanation of why. That particular one is likely that
way due to the first size guaranteed to be multiples of sizeof(Datum)
and the latter not.
Naturally, we'd need to run enough benchmarks to prove to ourselves
that we're not causing any slowdowns. The intention of memset.c was
to try to put something out there that people could test so we could
get an idea if there are any machines/compilers that we might need to
be concerned about.
David
On 19.05.22 18:09, Ranier Vilela wrote:
Taking it a step further.
Created a new patch into commitfest, targeting 16 version.
https://commitfest.postgresql.org/38/3645/
<https://commitfest.postgresql.org/38/3645/>
I have committed your 001 patch, which was clearly a (harmless) mistake.
I have also committed a patch that gets rid of MemSet() calls where the
value is a constant not-0, because that just falls back to memset() anyway.
I'm on board with trying to get rid of MemSet(), but first I need to
analyze all the performance numbers and arguments that were shown in
this thread.
Em qui., 30 de jun. de 2022 às 19:37, Peter Eisentraut <
peter.eisentraut@enterprisedb.com> escreveu:
On 19.05.22 18:09, Ranier Vilela wrote:
Taking it a step further.
Created a new patch into commitfest, targeting 16 version.
https://commitfest.postgresql.org/38/3645/
<https://commitfest.postgresql.org/38/3645/>I have committed your 001 patch, which was clearly a (harmless) mistake.
Thank you.
I have also committed a patch that gets rid of MemSet() calls where the
value is a constant not-0, because that just falls back to memset() anyway.I'm on board with trying to get rid of MemSet(), but first I need to
analyze all the performance numbers and arguments that were shown in
this thread.
One good argument is that using memset, allows to compiler
analyze and remove completely memset call if he understands
that can do it, which with MemSet is not possible.
regards,
Ranier Vilela
Em qui., 30 de jun. de 2022 às 19:37, Peter Eisentraut <
peter.eisentraut@enterprisedb.com> escreveu:
I have also committed a patch that gets rid of MemSet() calls where the
value is a constant not-0, because that just falls back to memset() anyway.
Peter there are some missing paths in this commit.
Despite having included the attached patch, there is no need to credit me
as the author, just as a report.
regards,
Ranier Vilela
Attachments:
001-avoid-unecessary-MemSet-calls.patchapplication/octet-stream; name=001-avoid-unecessary-MemSet-calls.patchDownload
diff --git a/src/backend/commands/copyfromparse.c b/src/backend/commands/copyfromparse.c
index 57813b3458..cef0f2c279 100644
--- a/src/backend/commands/copyfromparse.c
+++ b/src/backend/commands/copyfromparse.c
@@ -869,7 +869,7 @@ NextCopyFrom(CopyFromState cstate, ExprContext *econtext,
/* Initialize all values for row to NULL */
MemSet(values, 0, num_phys_attrs * sizeof(Datum));
- MemSet(nulls, true, num_phys_attrs * sizeof(bool));
+ memset(nulls, true, num_phys_attrs * sizeof(bool));
if (!cstate->opts.binary)
{
diff --git a/src/backend/replication/walsender.c b/src/backend/replication/walsender.c
index e42671722a..55ee8d455a 100644
--- a/src/backend/replication/walsender.c
+++ b/src/backend/replication/walsender.c
@@ -496,7 +496,7 @@ ReadReplicationSlot(ReadReplicationSlotCmd *cmd)
INT8OID, -1, 0);
MemSet(values, 0, READ_REPLICATION_SLOT_COLS * sizeof(Datum));
- MemSet(nulls, true, READ_REPLICATION_SLOT_COLS * sizeof(bool));
+ memset(nulls, true, READ_REPLICATION_SLOT_COLS * sizeof(bool));
LWLockAcquire(ReplicationSlotControlLock, LW_SHARED);
slot = SearchNamedReplicationSlot(cmd->slotname, false);
@@ -3550,7 +3550,7 @@ pg_stat_get_wal_senders(PG_FUNCTION_ARGS)
* can see details. Other users only get the pid value to know
* it's a walsender, but no details.
*/
- MemSet(&nulls[1], true, PG_STAT_GET_WAL_SENDERS_COLS - 1);
+ memset(&nulls[1], true, PG_STAT_GET_WAL_SENDERS_COLS - 1);
}
else
{
diff --git a/src/backend/utils/misc/ps_status.c b/src/backend/utils/misc/ps_status.c
index ec314c03f5..ca05b180c9 100644
--- a/src/backend/utils/misc/ps_status.c
+++ b/src/backend/utils/misc/ps_status.c
@@ -393,7 +393,7 @@ set_ps_display(const char *activity)
#ifdef PS_USE_CLOBBER_ARGV
/* pad unused memory; need only clobber remainder of old status string */
if (last_status_len > ps_buffer_cur_len)
- MemSet(ps_buffer + ps_buffer_cur_len, PS_PADDING,
+ memset(ps_buffer + ps_buffer_cur_len, PS_PADDING,
last_status_len - ps_buffer_cur_len);
last_status_len = ps_buffer_cur_len;
#endif /* PS_USE_CLOBBER_ARGV */On 18.05.22 15:52, Peter Eisentraut wrote:
On 18.05.22 01:18, Justin Pryzby wrote:
Take the first one as an example. It says:
GenericCosts costs;
MemSet(&costs, 0, sizeof(costs));You sent a patch to change it to sizeof(GenericCosts).
But it's not a pointer, so they are the same.
This instance can more easily be written as
costs = {0};
The attached patch replaces all MemSet() calls with struct
initialization where that is easily possible. (For example, some cases
have to worry about padding bits, so I left those.)
This reduces the number of MemSet() calls from about 400 to about 200.
Maybe this can help simplify the investigation of the merits of the
remaining calls.
Attachments:
0001-WIP-Replace-MemSet-calls-with-struct-initialization.patchtext/plain; charset=UTF-8; name=0001-WIP-Replace-MemSet-calls-with-struct-initialization.patchDownload
From fa58a89f37c920691872e60eafd171a3bd064fba Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <peter@eisentraut.org>
Date: Thu, 7 Jul 2022 12:49:10 +0200
Subject: [PATCH] WIP: Replace MemSet calls with struct initialization
---
contrib/amcheck/verify_heapam.c | 6 +-
contrib/bloom/blcost.c | 4 +-
contrib/pageinspect/brinfuncs.c | 7 +-
contrib/pageinspect/hashfuncs.c | 16 +-
contrib/pageinspect/heapfuncs.c | 8 +-
contrib/pg_prewarm/autoprewarm.c | 6 +-
.../pg_stat_statements/pg_stat_statements.c | 7 +-
contrib/pg_visibility/pg_visibility.c | 15 +-
contrib/pg_walinspect/pg_walinspect.c | 25 +--
contrib/pgstattuple/pgstatindex.c | 3 +-
contrib/postgres_fdw/connection.c | 7 +-
contrib/postgres_fdw/postgres_fdw.c | 3 +-
src/backend/access/transam/twophase.c | 6 +-
src/backend/access/transam/xlogfuncs.c | 7 +-
src/backend/catalog/aclchk.c | 146 ++++++------------
src/backend/catalog/dependency.c | 3 +-
src/backend/catalog/heap.c | 24 +--
src/backend/catalog/index.c | 4 +-
src/backend/catalog/pg_attrdef.c | 9 +-
src/backend/catalog/pg_cast.c | 4 +-
src/backend/catalog/pg_parameter_acl.c | 6 +-
src/backend/catalog/pg_publication.c | 6 +-
src/backend/commands/dbcommands.c | 35 ++---
src/backend/commands/event_trigger.c | 11 +-
src/backend/commands/functioncmds.c | 7 +-
src/backend/commands/prepare.c | 4 +-
src/backend/commands/tablecmds.c | 44 ++----
src/backend/commands/tablespace.c | 4 +-
src/backend/commands/typecmds.c | 9 +-
src/backend/commands/user.c | 37 ++---
src/backend/optimizer/path/costsize.c | 3 +-
src/backend/parser/parse_target.c | 3 +-
src/backend/replication/logical/launcher.c | 7 +-
src/backend/replication/walsender.c | 17 +-
src/backend/rewrite/rewriteDefine.c | 8 +-
src/backend/utils/adt/acl.c | 4 +-
src/backend/utils/adt/arrayfuncs.c | 3 +-
src/backend/utils/adt/datetime.c | 8 +-
src/backend/utils/adt/lockfuncs.c | 12 +-
src/backend/utils/adt/partitionfuncs.c | 6 +-
src/backend/utils/adt/pgstatfuncs.c | 52 ++-----
src/backend/utils/adt/selfuncs.c | 19 +--
src/backend/utils/adt/timestamp.c | 8 +-
src/backend/utils/mmgr/portalmem.c | 4 +-
src/bin/pg_basebackup/pg_basebackup.c | 11 +-
src/bin/pg_basebackup/pg_receivewal.c | 4 +-
src/bin/pg_basebackup/walmethods.c | 6 +-
src/common/ip.c | 4 +-
src/port/snprintf.c | 7 +-
.../modules/test_predtest/test_predtest.c | 3 +-
src/test/regress/regress.c | 3 +-
51 files changed, 199 insertions(+), 466 deletions(-)
diff --git a/contrib/amcheck/verify_heapam.c b/contrib/amcheck/verify_heapam.c
index e488f5e234..d33f33f170 100644
--- a/contrib/amcheck/verify_heapam.c
+++ b/contrib/amcheck/verify_heapam.c
@@ -554,12 +554,10 @@ report_corruption_internal(Tuplestorestate *tupstore, TupleDesc tupdesc,
BlockNumber blkno, OffsetNumber offnum,
AttrNumber attnum, char *msg)
{
- Datum values[HEAPCHECK_RELATION_COLS];
- bool nulls[HEAPCHECK_RELATION_COLS];
+ Datum values[HEAPCHECK_RELATION_COLS] = {0};
+ bool nulls[HEAPCHECK_RELATION_COLS] = {0};
HeapTuple tuple;
- MemSet(values, 0, sizeof(values));
- MemSet(nulls, 0, sizeof(nulls));
values[0] = Int64GetDatum(blkno);
values[1] = Int32GetDatum(offnum);
values[2] = Int32GetDatum(attnum);
diff --git a/contrib/bloom/blcost.c b/contrib/bloom/blcost.c
index d42e4e9628..d4b1c76303 100644
--- a/contrib/bloom/blcost.c
+++ b/contrib/bloom/blcost.c
@@ -26,9 +26,7 @@ blcostestimate(PlannerInfo *root, IndexPath *path, double loop_count,
double *indexPages)
{
IndexOptInfo *index = path->indexinfo;
- GenericCosts costs;
-
- MemSet(&costs, 0, sizeof(costs));
+ GenericCosts costs = {0};
/* We have to visit all index tuples anyway */
costs.numIndexTuples = index->tuples;
diff --git a/contrib/pageinspect/brinfuncs.c b/contrib/pageinspect/brinfuncs.c
index 879276e6de..f4c959ecab 100644
--- a/contrib/pageinspect/brinfuncs.c
+++ b/contrib/pageinspect/brinfuncs.c
@@ -202,7 +202,7 @@ brin_page_items(PG_FUNCTION_ARGS)
for (;;)
{
Datum values[7];
- bool nulls[7];
+ bool nulls[7] = {0};
/*
* This loop is called once for every attribute of every tuple in the
@@ -230,8 +230,6 @@ brin_page_items(PG_FUNCTION_ARGS)
else
attno++;
- MemSet(nulls, 0, sizeof(nulls));
-
if (unusedItem)
{
values[0] = UInt16GetDatum(offset);
@@ -334,7 +332,7 @@ brin_metapage_info(PG_FUNCTION_ARGS)
BrinMetaPageData *meta;
TupleDesc tupdesc;
Datum values[4];
- bool nulls[4];
+ bool nulls[4] = {0};
HeapTuple htup;
if (!superuser())
@@ -354,7 +352,6 @@ brin_metapage_info(PG_FUNCTION_ARGS)
/* Extract values from the metapage */
meta = (BrinMetaPageData *) PageGetContents(page);
- MemSet(nulls, 0, sizeof(nulls));
values[0] = CStringGetTextDatum(psprintf("0x%08X", meta->brinMagic));
values[1] = Int32GetDatum(meta->brinVersion);
values[2] = Int32GetDatum(meta->pagesPerRange);
diff --git a/contrib/pageinspect/hashfuncs.c b/contrib/pageinspect/hashfuncs.c
index 5287dbe1a3..81815392d7 100644
--- a/contrib/pageinspect/hashfuncs.c
+++ b/contrib/pageinspect/hashfuncs.c
@@ -238,7 +238,7 @@ hash_page_stats(PG_FUNCTION_ARGS)
Page page;
int j;
Datum values[9];
- bool nulls[9];
+ bool nulls[9] = {0};
HashPageStat stat;
HeapTuple tuple;
TupleDesc tupleDesc;
@@ -261,8 +261,6 @@ hash_page_stats(PG_FUNCTION_ARGS)
elog(ERROR, "return type must be a row type");
tupleDesc = BlessTupleDesc(tupleDesc);
- MemSet(nulls, 0, sizeof(nulls));
-
j = 0;
values[j++] = Int32GetDatum(stat.live_items);
values[j++] = Int32GetDatum(stat.dead_items);
@@ -303,7 +301,7 @@ hash_page_items(PG_FUNCTION_ARGS)
Page page;
Datum result;
Datum values[3];
- bool nulls[3];
+ bool nulls[3] = {0};
uint32 hashkey;
HeapTuple tuple;
FuncCallContext *fctx;
@@ -361,8 +359,6 @@ hash_page_items(PG_FUNCTION_ARGS)
itup = (IndexTuple) PageGetItem(uargs->page, id);
- MemSet(nulls, 0, sizeof(nulls));
-
j = 0;
values[j++] = Int32GetDatum((int32) uargs->offset);
values[j++] = PointerGetDatum(&itup->t_tid);
@@ -409,7 +405,7 @@ hash_bitmap_info(PG_FUNCTION_ARGS)
int i,
j;
Datum values[3];
- bool nulls[3];
+ bool nulls[3] = {0};
uint32 *freep;
if (!superuser())
@@ -495,8 +491,6 @@ hash_bitmap_info(PG_FUNCTION_ARGS)
elog(ERROR, "return type must be a row type");
tupleDesc = BlessTupleDesc(tupleDesc);
- MemSet(nulls, 0, sizeof(nulls));
-
j = 0;
values[j++] = Int64GetDatum((int64) bitmapblkno);
values[j++] = Int32GetDatum(bitmapbit);
@@ -526,7 +520,7 @@ hash_metapage_info(PG_FUNCTION_ARGS)
int i,
j;
Datum values[16];
- bool nulls[16];
+ bool nulls[16] = {0};
Datum spares[HASH_MAX_SPLITPOINTS];
Datum mapp[HASH_MAX_BITMAPS];
@@ -544,8 +538,6 @@ hash_metapage_info(PG_FUNCTION_ARGS)
metad = HashPageGetMeta(page);
- MemSet(nulls, 0, sizeof(nulls));
-
j = 0;
values[j++] = Int64GetDatum((int64) metad->hashm_magic);
values[j++] = Int64GetDatum((int64) metad->hashm_version);
diff --git a/contrib/pageinspect/heapfuncs.c b/contrib/pageinspect/heapfuncs.c
index a654234c6b..2ff70405cf 100644
--- a/contrib/pageinspect/heapfuncs.c
+++ b/contrib/pageinspect/heapfuncs.c
@@ -507,8 +507,8 @@ Datum
heap_tuple_infomask_flags(PG_FUNCTION_ARGS)
{
#define HEAP_TUPLE_INFOMASK_COLS 2
- Datum values[HEAP_TUPLE_INFOMASK_COLS];
- bool nulls[HEAP_TUPLE_INFOMASK_COLS];
+ Datum values[HEAP_TUPLE_INFOMASK_COLS] = {0};
+ bool nulls[HEAP_TUPLE_INFOMASK_COLS] = {0};
uint16 t_infomask = PG_GETARG_INT16(0);
uint16 t_infomask2 = PG_GETARG_INT16(1);
int cnt = 0;
@@ -530,10 +530,6 @@ heap_tuple_infomask_flags(PG_FUNCTION_ARGS)
bitcnt = pg_popcount((const char *) &t_infomask, sizeof(uint16)) +
pg_popcount((const char *) &t_infomask2, sizeof(uint16));
- /* Initialize values and NULL flags arrays */
- MemSet(values, 0, sizeof(values));
- MemSet(nulls, 0, sizeof(nulls));
-
/* If no flags, return a set of empty arrays */
if (bitcnt <= 0)
{
diff --git a/contrib/pg_prewarm/autoprewarm.c b/contrib/pg_prewarm/autoprewarm.c
index 13eee4a137..ee20e9b085 100644
--- a/contrib/pg_prewarm/autoprewarm.c
+++ b/contrib/pg_prewarm/autoprewarm.c
@@ -814,12 +814,11 @@ apw_detach_shmem(int code, Datum arg)
static void
apw_start_leader_worker(void)
{
- BackgroundWorker worker;
+ BackgroundWorker worker = {0};
BackgroundWorkerHandle *handle;
BgwHandleStatus status;
pid_t pid;
- MemSet(&worker, 0, sizeof(BackgroundWorker));
worker.bgw_flags = BGWORKER_SHMEM_ACCESS;
worker.bgw_start_time = BgWorkerStart_ConsistentState;
strcpy(worker.bgw_library_name, "pg_prewarm");
@@ -856,10 +855,9 @@ apw_start_leader_worker(void)
static void
apw_start_database_worker(void)
{
- BackgroundWorker worker;
+ BackgroundWorker worker = {0};
BackgroundWorkerHandle *handle;
- MemSet(&worker, 0, sizeof(BackgroundWorker));
worker.bgw_flags =
BGWORKER_SHMEM_ACCESS | BGWORKER_BACKEND_DATABASE_CONNECTION;
worker.bgw_start_time = BgWorkerStart_ConsistentState;
diff --git a/contrib/pg_stat_statements/pg_stat_statements.c b/contrib/pg_stat_statements/pg_stat_statements.c
index 4acfddcdb8..b4d4231dc6 100644
--- a/contrib/pg_stat_statements/pg_stat_statements.c
+++ b/contrib/pg_stat_statements/pg_stat_statements.c
@@ -1854,8 +1854,8 @@ pg_stat_statements_info(PG_FUNCTION_ARGS)
{
pgssGlobalStats stats;
TupleDesc tupdesc;
- Datum values[PG_STAT_STATEMENTS_INFO_COLS];
- bool nulls[PG_STAT_STATEMENTS_INFO_COLS];
+ Datum values[PG_STAT_STATEMENTS_INFO_COLS] = {0};
+ bool nulls[PG_STAT_STATEMENTS_INFO_COLS] = {0};
if (!pgss || !pgss_hash)
ereport(ERROR,
@@ -1866,9 +1866,6 @@ pg_stat_statements_info(PG_FUNCTION_ARGS)
if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE)
elog(ERROR, "return type must be a row type");
- MemSet(values, 0, sizeof(values));
- MemSet(nulls, 0, sizeof(nulls));
-
/* Read global statistics for pg_stat_statements */
{
volatile pgssSharedState *s = (volatile pgssSharedState *) pgss;
diff --git a/contrib/pg_visibility/pg_visibility.c b/contrib/pg_visibility/pg_visibility.c
index 4e2e9ea9bb..a95f73ec79 100644
--- a/contrib/pg_visibility/pg_visibility.c
+++ b/contrib/pg_visibility/pg_visibility.c
@@ -75,7 +75,7 @@ pg_visibility_map(PG_FUNCTION_ARGS)
Buffer vmbuffer = InvalidBuffer;
TupleDesc tupdesc;
Datum values[2];
- bool nulls[2];
+ bool nulls[2] = {0};
rel = relation_open(relid, AccessShareLock);
@@ -88,7 +88,6 @@ pg_visibility_map(PG_FUNCTION_ARGS)
errmsg("invalid block number")));
tupdesc = pg_visibility_tupdesc(false, false);
- MemSet(nulls, 0, sizeof(nulls));
mapbits = (int32) visibilitymap_get_status(rel, blkno, &vmbuffer);
if (vmbuffer != InvalidBuffer)
@@ -117,7 +116,7 @@ pg_visibility(PG_FUNCTION_ARGS)
Page page;
TupleDesc tupdesc;
Datum values[3];
- bool nulls[3];
+ bool nulls[3] = {0};
rel = relation_open(relid, AccessShareLock);
@@ -130,7 +129,6 @@ pg_visibility(PG_FUNCTION_ARGS)
errmsg("invalid block number")));
tupdesc = pg_visibility_tupdesc(false, true);
- MemSet(nulls, 0, sizeof(nulls));
mapbits = (int32) visibilitymap_get_status(rel, blkno, &vmbuffer);
if (vmbuffer != InvalidBuffer)
@@ -188,10 +186,9 @@ pg_visibility_map_rel(PG_FUNCTION_ARGS)
if (info->next < info->count)
{
Datum values[3];
- bool nulls[3];
+ bool nulls[3] = {0};
HeapTuple tuple;
- MemSet(nulls, 0, sizeof(nulls));
values[0] = Int64GetDatum(info->next);
values[1] = BoolGetDatum((info->bits[info->next] & (1 << 0)) != 0);
values[2] = BoolGetDatum((info->bits[info->next] & (1 << 1)) != 0);
@@ -233,10 +230,9 @@ pg_visibility_rel(PG_FUNCTION_ARGS)
if (info->next < info->count)
{
Datum values[4];
- bool nulls[4];
+ bool nulls[4] = {0};
HeapTuple tuple;
- MemSet(nulls, 0, sizeof(nulls));
values[0] = Int64GetDatum(info->next);
values[1] = BoolGetDatum((info->bits[info->next] & (1 << 0)) != 0);
values[2] = BoolGetDatum((info->bits[info->next] & (1 << 1)) != 0);
@@ -266,7 +262,7 @@ pg_visibility_map_summary(PG_FUNCTION_ARGS)
int64 all_frozen = 0;
TupleDesc tupdesc;
Datum values[2];
- bool nulls[2];
+ bool nulls[2] = {0};
rel = relation_open(relid, AccessShareLock);
@@ -300,7 +296,6 @@ pg_visibility_map_summary(PG_FUNCTION_ARGS)
TupleDescInitEntry(tupdesc, (AttrNumber) 2, "all_frozen", INT8OID, -1, 0);
tupdesc = BlessTupleDesc(tupdesc);
- MemSet(nulls, 0, sizeof(nulls));
values[0] = Int64GetDatum(all_visible);
values[1] = Int64GetDatum(all_frozen);
diff --git a/contrib/pg_walinspect/pg_walinspect.c b/contrib/pg_walinspect/pg_walinspect.c
index a082dfb331..9081787634 100644
--- a/contrib/pg_walinspect/pg_walinspect.c
+++ b/contrib/pg_walinspect/pg_walinspect.c
@@ -229,8 +229,8 @@ pg_get_wal_record_info(PG_FUNCTION_ARGS)
{
#define PG_GET_WAL_RECORD_INFO_COLS 11
Datum result;
- Datum values[PG_GET_WAL_RECORD_INFO_COLS];
- bool nulls[PG_GET_WAL_RECORD_INFO_COLS];
+ Datum values[PG_GET_WAL_RECORD_INFO_COLS] = {0};
+ bool nulls[PG_GET_WAL_RECORD_INFO_COLS] = {0};
XLogRecPtr lsn;
XLogRecPtr curr_lsn;
XLogRecPtr first_record;
@@ -266,9 +266,6 @@ pg_get_wal_record_info(PG_FUNCTION_ARGS)
errmsg("could not read WAL at %X/%X",
LSN_FORMAT_ARGS(first_record))));
- MemSet(values, 0, sizeof(values));
- MemSet(nulls, 0, sizeof(nulls));
-
GetWALRecordInfo(xlogreader, first_record, values, nulls,
PG_GET_WAL_RECORD_INFO_COLS);
@@ -334,8 +331,8 @@ GetWALRecordsInfo(FunctionCallInfo fcinfo, XLogRecPtr start_lsn,
XLogRecPtr first_record;
XLogReaderState *xlogreader;
ReturnSetInfo *rsinfo = (ReturnSetInfo *) fcinfo->resultinfo;
- Datum values[PG_GET_WAL_RECORDS_INFO_COLS];
- bool nulls[PG_GET_WAL_RECORDS_INFO_COLS];
+ Datum values[PG_GET_WAL_RECORDS_INFO_COLS] = {0};
+ bool nulls[PG_GET_WAL_RECORDS_INFO_COLS] = {0};
SetSingleFuncCall(fcinfo, 0);
@@ -343,9 +340,6 @@ GetWALRecordsInfo(FunctionCallInfo fcinfo, XLogRecPtr start_lsn,
Assert(xlogreader);
- MemSet(values, 0, sizeof(values));
- MemSet(nulls, 0, sizeof(nulls));
-
while (ReadNextXLogRecord(xlogreader, first_record) &&
xlogreader->EndRecPtr <= end_lsn)
{
@@ -556,17 +550,15 @@ GetWalStats(FunctionCallInfo fcinfo, XLogRecPtr start_lsn,
#define PG_GET_WAL_STATS_COLS 9
XLogRecPtr first_record;
XLogReaderState *xlogreader;
- XLogStats stats;
+ XLogStats stats = {0};
ReturnSetInfo *rsinfo = (ReturnSetInfo *) fcinfo->resultinfo;
- Datum values[PG_GET_WAL_STATS_COLS];
- bool nulls[PG_GET_WAL_STATS_COLS];
+ Datum values[PG_GET_WAL_STATS_COLS] = {0};
+ bool nulls[PG_GET_WAL_STATS_COLS] = {0};
SetSingleFuncCall(fcinfo, 0);
xlogreader = InitXLogReaderState(start_lsn, &first_record);
- MemSet(&stats, 0, sizeof(stats));
-
while (ReadNextXLogRecord(xlogreader, first_record) &&
xlogreader->EndRecPtr <= end_lsn)
{
@@ -578,9 +570,6 @@ GetWalStats(FunctionCallInfo fcinfo, XLogRecPtr start_lsn,
pfree(xlogreader->private_data);
XLogReaderFree(xlogreader);
- MemSet(values, 0, sizeof(values));
- MemSet(nulls, 0, sizeof(nulls));
-
GetXLogSummaryStats(&stats, rsinfo, values, nulls,
PG_GET_WAL_STATS_COLS,
stats_per_record);
diff --git a/contrib/pgstattuple/pgstatindex.c b/contrib/pgstattuple/pgstatindex.c
index e1048e47ff..d69ac1c93d 100644
--- a/contrib/pgstattuple/pgstatindex.c
+++ b/contrib/pgstattuple/pgstatindex.c
@@ -575,7 +575,7 @@ pgstathashindex(PG_FUNCTION_ARGS)
HeapTuple tuple;
TupleDesc tupleDesc;
Datum values[8];
- bool nulls[8];
+ bool nulls[8] = {0};
Buffer metabuf;
HashMetaPage metap;
float8 free_percent;
@@ -697,7 +697,6 @@ pgstathashindex(PG_FUNCTION_ARGS)
/*
* Build and return the tuple
*/
- MemSet(nulls, 0, sizeof(nulls));
values[0] = Int32GetDatum(stats.version);
values[1] = Int64GetDatum((int64) stats.bucket_pages);
values[2] = Int64GetDatum((int64) stats.overflow_pages);
diff --git a/contrib/postgres_fdw/connection.c b/contrib/postgres_fdw/connection.c
index cffb6f8310..939d114f02 100644
--- a/contrib/postgres_fdw/connection.c
+++ b/contrib/postgres_fdw/connection.c
@@ -1678,8 +1678,8 @@ postgres_fdw_get_connections(PG_FUNCTION_ARGS)
while ((entry = (ConnCacheEntry *) hash_seq_search(&scan)))
{
ForeignServer *server;
- Datum values[POSTGRES_FDW_GET_CONNECTIONS_COLS];
- bool nulls[POSTGRES_FDW_GET_CONNECTIONS_COLS];
+ Datum values[POSTGRES_FDW_GET_CONNECTIONS_COLS] = {0};
+ bool nulls[POSTGRES_FDW_GET_CONNECTIONS_COLS] = {0};
/* We only look for open remote connections */
if (!entry->conn)
@@ -1687,9 +1687,6 @@ postgres_fdw_get_connections(PG_FUNCTION_ARGS)
server = GetForeignServerExtended(entry->serverid, FSV_MISSING_OK);
- MemSet(values, 0, sizeof(values));
- MemSet(nulls, 0, sizeof(nulls));
-
/*
* The foreign server may have been dropped in current explicit
* transaction. It is not possible to drop the server from another
diff --git a/contrib/postgres_fdw/postgres_fdw.c b/contrib/postgres_fdw/postgres_fdw.c
index 955a428e3d..cfac539008 100644
--- a/contrib/postgres_fdw/postgres_fdw.c
+++ b/contrib/postgres_fdw/postgres_fdw.c
@@ -3307,7 +3307,7 @@ estimate_path_cost_size(PlannerInfo *root,
{
RelOptInfo *outerrel = fpinfo->outerrel;
PgFdwRelationInfo *ofpinfo;
- AggClauseCosts aggcosts;
+ AggClauseCosts aggcosts = {0};
double input_rows;
int numGroupCols;
double numGroups = 1;
@@ -3331,7 +3331,6 @@ estimate_path_cost_size(PlannerInfo *root,
input_rows = ofpinfo->rows;
/* Collect statistics about aggregates for estimating costs. */
- MemSet(&aggcosts, 0, sizeof(AggClauseCosts));
if (root->parse->hasAggs)
{
get_agg_clause_costs(root, AGGSPLIT_SIMPLE, &aggcosts);
diff --git a/src/backend/access/transam/twophase.c b/src/backend/access/transam/twophase.c
index 41b31c5c6f..803d169f57 100644
--- a/src/backend/access/transam/twophase.c
+++ b/src/backend/access/transam/twophase.c
@@ -780,8 +780,8 @@ pg_prepared_xact(PG_FUNCTION_ARGS)
{
GlobalTransaction gxact = &status->array[status->currIdx++];
PGPROC *proc = &ProcGlobal->allProcs[gxact->pgprocno];
- Datum values[5];
- bool nulls[5];
+ Datum values[5] = {0};
+ bool nulls[5] = {0};
HeapTuple tuple;
Datum result;
@@ -791,8 +791,6 @@ pg_prepared_xact(PG_FUNCTION_ARGS)
/*
* Form tuple with appropriate data.
*/
- MemSet(values, 0, sizeof(values));
- MemSet(nulls, 0, sizeof(nulls));
values[0] = TransactionIdGetDatum(proc->xid);
values[1] = CStringGetTextDatum(gxact->gid);
diff --git a/src/backend/access/transam/xlogfuncs.c b/src/backend/access/transam/xlogfuncs.c
index 02bd919ff6..61e0f4a29c 100644
--- a/src/backend/access/transam/xlogfuncs.c
+++ b/src/backend/access/transam/xlogfuncs.c
@@ -106,8 +106,8 @@ pg_backup_stop(PG_FUNCTION_ARGS)
{
#define PG_STOP_BACKUP_V2_COLS 3
TupleDesc tupdesc;
- Datum values[PG_STOP_BACKUP_V2_COLS];
- bool nulls[PG_STOP_BACKUP_V2_COLS];
+ Datum values[PG_STOP_BACKUP_V2_COLS] = {0};
+ bool nulls[PG_STOP_BACKUP_V2_COLS] = {0};
bool waitforarchive = PG_GETARG_BOOL(0);
XLogRecPtr stoppoint;
@@ -117,9 +117,6 @@ pg_backup_stop(PG_FUNCTION_ARGS)
if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE)
elog(ERROR, "return type must be a row type");
- MemSet(values, 0, sizeof(values));
- MemSet(nulls, 0, sizeof(nulls));
-
if (status != SESSION_BACKUP_RUNNING)
ereport(ERROR,
(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
diff --git a/src/backend/catalog/aclchk.c b/src/backend/catalog/aclchk.c
index 5f1726c095..17ff617fba 100644
--- a/src/backend/catalog/aclchk.c
+++ b/src/backend/catalog/aclchk.c
@@ -1188,9 +1188,6 @@ SetDefaultACL(InternalDefaultACL *iacls)
Acl *old_acl;
Acl *new_acl;
HeapTuple newtuple;
- Datum values[Natts_pg_default_acl];
- bool nulls[Natts_pg_default_acl];
- bool replaces[Natts_pg_default_acl];
int noldmembers;
int nnewmembers;
Oid *oldmembers;
@@ -1341,13 +1338,11 @@ SetDefaultACL(InternalDefaultACL *iacls)
}
else
{
+ Datum values[Natts_pg_default_acl] = {0};
+ bool nulls[Natts_pg_default_acl] = {0};
+ bool replaces[Natts_pg_default_acl] = {0};
Oid defAclOid;
- /* Prepare to insert or update pg_default_acl entry */
- MemSet(values, 0, sizeof(values));
- MemSet(nulls, false, sizeof(nulls));
- MemSet(replaces, false, sizeof(replaces));
-
if (isNew)
{
/* insert new entry */
@@ -1662,9 +1657,9 @@ ExecGrant_Attribute(InternalGrant *istmt, Oid relOid, const char *relname,
AclMode avail_goptions;
bool need_update;
HeapTuple newtuple;
- Datum values[Natts_pg_attribute];
- bool nulls[Natts_pg_attribute];
- bool replaces[Natts_pg_attribute];
+ Datum values[Natts_pg_attribute] = {0};
+ bool nulls[Natts_pg_attribute] = {0};
+ bool replaces[Natts_pg_attribute] = {0};
int noldmembers;
int nnewmembers;
Oid *oldmembers;
@@ -1745,9 +1740,6 @@ ExecGrant_Attribute(InternalGrant *istmt, Oid relOid, const char *relname,
nnewmembers = aclmembers(new_acl, &newmembers);
/* finished building new ACL value, now insert it */
- MemSet(values, 0, sizeof(values));
- MemSet(nulls, false, sizeof(nulls));
- MemSet(replaces, false, sizeof(replaces));
/*
* If the updated ACL is empty, we can set attacl to null, and maybe even
@@ -1975,9 +1967,9 @@ ExecGrant_Relation(InternalGrant *istmt)
Acl *new_acl;
Oid grantorId;
HeapTuple newtuple;
- Datum values[Natts_pg_class];
- bool nulls[Natts_pg_class];
- bool replaces[Natts_pg_class];
+ Datum values[Natts_pg_class] = {0};
+ bool nulls[Natts_pg_class] = {0};
+ bool replaces[Natts_pg_class] = {0};
int nnewmembers;
Oid *newmembers;
ObjectType objtype;
@@ -2027,10 +2019,6 @@ ExecGrant_Relation(InternalGrant *istmt)
nnewmembers = aclmembers(new_acl, &newmembers);
/* finished building new ACL value, now insert it */
- MemSet(values, 0, sizeof(values));
- MemSet(nulls, false, sizeof(nulls));
- MemSet(replaces, false, sizeof(replaces));
-
replaces[Anum_pg_class_relacl - 1] = true;
values[Anum_pg_class_relacl - 1] = PointerGetDatum(new_acl);
@@ -2150,9 +2138,9 @@ ExecGrant_Database(InternalGrant *istmt)
Oid grantorId;
Oid ownerId;
HeapTuple newtuple;
- Datum values[Natts_pg_database];
- bool nulls[Natts_pg_database];
- bool replaces[Natts_pg_database];
+ Datum values[Natts_pg_database] = {0};
+ bool nulls[Natts_pg_database] = {0};
+ bool replaces[Natts_pg_database] = {0};
int noldmembers;
int nnewmembers;
Oid *oldmembers;
@@ -2217,10 +2205,6 @@ ExecGrant_Database(InternalGrant *istmt)
nnewmembers = aclmembers(new_acl, &newmembers);
/* finished building new ACL value, now insert it */
- MemSet(values, 0, sizeof(values));
- MemSet(nulls, false, sizeof(nulls));
- MemSet(replaces, false, sizeof(replaces));
-
replaces[Anum_pg_database_datacl - 1] = true;
values[Anum_pg_database_datacl - 1] = PointerGetDatum(new_acl);
@@ -2271,9 +2255,9 @@ ExecGrant_Fdw(InternalGrant *istmt)
Oid ownerId;
HeapTuple tuple;
HeapTuple newtuple;
- Datum values[Natts_pg_foreign_data_wrapper];
- bool nulls[Natts_pg_foreign_data_wrapper];
- bool replaces[Natts_pg_foreign_data_wrapper];
+ Datum values[Natts_pg_foreign_data_wrapper] = {0};
+ bool nulls[Natts_pg_foreign_data_wrapper] = {0};
+ bool replaces[Natts_pg_foreign_data_wrapper] = {0};
int noldmembers;
int nnewmembers;
Oid *oldmembers;
@@ -2339,10 +2323,6 @@ ExecGrant_Fdw(InternalGrant *istmt)
nnewmembers = aclmembers(new_acl, &newmembers);
/* finished building new ACL value, now insert it */
- MemSet(values, 0, sizeof(values));
- MemSet(nulls, false, sizeof(nulls));
- MemSet(replaces, false, sizeof(replaces));
-
replaces[Anum_pg_foreign_data_wrapper_fdwacl - 1] = true;
values[Anum_pg_foreign_data_wrapper_fdwacl - 1] = PointerGetDatum(new_acl);
@@ -2398,9 +2378,9 @@ ExecGrant_ForeignServer(InternalGrant *istmt)
Oid ownerId;
HeapTuple tuple;
HeapTuple newtuple;
- Datum values[Natts_pg_foreign_server];
- bool nulls[Natts_pg_foreign_server];
- bool replaces[Natts_pg_foreign_server];
+ Datum values[Natts_pg_foreign_server] = {0};
+ bool nulls[Natts_pg_foreign_server] = {0};
+ bool replaces[Natts_pg_foreign_server] = {0};
int noldmembers;
int nnewmembers;
Oid *oldmembers;
@@ -2465,10 +2445,6 @@ ExecGrant_ForeignServer(InternalGrant *istmt)
nnewmembers = aclmembers(new_acl, &newmembers);
/* finished building new ACL value, now insert it */
- MemSet(values, 0, sizeof(values));
- MemSet(nulls, false, sizeof(nulls));
- MemSet(replaces, false, sizeof(replaces));
-
replaces[Anum_pg_foreign_server_srvacl - 1] = true;
values[Anum_pg_foreign_server_srvacl - 1] = PointerGetDatum(new_acl);
@@ -2523,9 +2499,9 @@ ExecGrant_Function(InternalGrant *istmt)
Oid ownerId;
HeapTuple tuple;
HeapTuple newtuple;
- Datum values[Natts_pg_proc];
- bool nulls[Natts_pg_proc];
- bool replaces[Natts_pg_proc];
+ Datum values[Natts_pg_proc] = {0};
+ bool nulls[Natts_pg_proc] = {0};
+ bool replaces[Natts_pg_proc] = {0};
int noldmembers;
int nnewmembers;
Oid *oldmembers;
@@ -2589,10 +2565,6 @@ ExecGrant_Function(InternalGrant *istmt)
nnewmembers = aclmembers(new_acl, &newmembers);
/* finished building new ACL value, now insert it */
- MemSet(values, 0, sizeof(values));
- MemSet(nulls, false, sizeof(nulls));
- MemSet(replaces, false, sizeof(replaces));
-
replaces[Anum_pg_proc_proacl - 1] = true;
values[Anum_pg_proc_proacl - 1] = PointerGetDatum(new_acl);
@@ -2646,9 +2618,9 @@ ExecGrant_Language(InternalGrant *istmt)
Oid ownerId;
HeapTuple tuple;
HeapTuple newtuple;
- Datum values[Natts_pg_language];
- bool nulls[Natts_pg_language];
- bool replaces[Natts_pg_language];
+ Datum values[Natts_pg_language] = {0};
+ bool nulls[Natts_pg_language] = {0};
+ bool replaces[Natts_pg_language] = {0};
int noldmembers;
int nnewmembers;
Oid *oldmembers;
@@ -2720,10 +2692,6 @@ ExecGrant_Language(InternalGrant *istmt)
nnewmembers = aclmembers(new_acl, &newmembers);
/* finished building new ACL value, now insert it */
- MemSet(values, 0, sizeof(values));
- MemSet(nulls, false, sizeof(nulls));
- MemSet(replaces, false, sizeof(replaces));
-
replaces[Anum_pg_language_lanacl - 1] = true;
values[Anum_pg_language_lanacl - 1] = PointerGetDatum(new_acl);
@@ -2778,9 +2746,9 @@ ExecGrant_Largeobject(InternalGrant *istmt)
Oid grantorId;
Oid ownerId;
HeapTuple newtuple;
- Datum values[Natts_pg_largeobject_metadata];
- bool nulls[Natts_pg_largeobject_metadata];
- bool replaces[Natts_pg_largeobject_metadata];
+ Datum values[Natts_pg_largeobject_metadata] = {0};
+ bool nulls[Natts_pg_largeobject_metadata] = {0};
+ bool replaces[Natts_pg_largeobject_metadata] = {0};
int noldmembers;
int nnewmembers;
Oid *oldmembers;
@@ -2858,10 +2826,6 @@ ExecGrant_Largeobject(InternalGrant *istmt)
nnewmembers = aclmembers(new_acl, &newmembers);
/* finished building new ACL value, now insert it */
- MemSet(values, 0, sizeof(values));
- MemSet(nulls, false, sizeof(nulls));
- MemSet(replaces, false, sizeof(replaces));
-
replaces[Anum_pg_largeobject_metadata_lomacl - 1] = true;
values[Anum_pg_largeobject_metadata_lomacl - 1]
= PointerGetDatum(new_acl);
@@ -2917,9 +2881,9 @@ ExecGrant_Namespace(InternalGrant *istmt)
Oid ownerId;
HeapTuple tuple;
HeapTuple newtuple;
- Datum values[Natts_pg_namespace];
- bool nulls[Natts_pg_namespace];
- bool replaces[Natts_pg_namespace];
+ Datum values[Natts_pg_namespace] = {0};
+ bool nulls[Natts_pg_namespace] = {0};
+ bool replaces[Natts_pg_namespace] = {0};
int noldmembers;
int nnewmembers;
Oid *oldmembers;
@@ -2984,10 +2948,6 @@ ExecGrant_Namespace(InternalGrant *istmt)
nnewmembers = aclmembers(new_acl, &newmembers);
/* finished building new ACL value, now insert it */
- MemSet(values, 0, sizeof(values));
- MemSet(nulls, false, sizeof(nulls));
- MemSet(replaces, false, sizeof(replaces));
-
replaces[Anum_pg_namespace_nspacl - 1] = true;
values[Anum_pg_namespace_nspacl - 1] = PointerGetDatum(new_acl);
@@ -3040,9 +3000,9 @@ ExecGrant_Tablespace(InternalGrant *istmt)
Oid grantorId;
Oid ownerId;
HeapTuple newtuple;
- Datum values[Natts_pg_tablespace];
- bool nulls[Natts_pg_tablespace];
- bool replaces[Natts_pg_tablespace];
+ Datum values[Natts_pg_tablespace] = {0};
+ bool nulls[Natts_pg_tablespace] = {0};
+ bool replaces[Natts_pg_tablespace] = {0};
int noldmembers;
int nnewmembers;
Oid *oldmembers;
@@ -3108,10 +3068,6 @@ ExecGrant_Tablespace(InternalGrant *istmt)
nnewmembers = aclmembers(new_acl, &newmembers);
/* finished building new ACL value, now insert it */
- MemSet(values, 0, sizeof(values));
- MemSet(nulls, false, sizeof(nulls));
- MemSet(replaces, false, sizeof(replaces));
-
replaces[Anum_pg_tablespace_spcacl - 1] = true;
values[Anum_pg_tablespace_spcacl - 1] = PointerGetDatum(new_acl);
@@ -3160,9 +3116,9 @@ ExecGrant_Type(InternalGrant *istmt)
Oid grantorId;
Oid ownerId;
HeapTuple newtuple;
- Datum values[Natts_pg_type];
- bool nulls[Natts_pg_type];
- bool replaces[Natts_pg_type];
+ Datum values[Natts_pg_type] = {0};
+ bool nulls[Natts_pg_type] = {0};
+ bool replaces[Natts_pg_type] = {0};
int noldmembers;
int nnewmembers;
Oid *oldmembers;
@@ -3242,10 +3198,6 @@ ExecGrant_Type(InternalGrant *istmt)
nnewmembers = aclmembers(new_acl, &newmembers);
/* finished building new ACL value, now insert it */
- MemSet(values, 0, sizeof(values));
- MemSet(nulls, false, sizeof(nulls));
- MemSet(replaces, false, sizeof(replaces));
-
replaces[Anum_pg_type_typacl - 1] = true;
values[Anum_pg_type_typacl - 1] = PointerGetDatum(new_acl);
@@ -3384,13 +3336,9 @@ ExecGrant_Parameter(InternalGrant *istmt)
{
/* finished building new ACL value, now insert it */
HeapTuple newtuple;
- Datum values[Natts_pg_parameter_acl];
- bool nulls[Natts_pg_parameter_acl];
- bool replaces[Natts_pg_parameter_acl];
-
- MemSet(values, 0, sizeof(values));
- MemSet(nulls, false, sizeof(nulls));
- MemSet(replaces, false, sizeof(replaces));
+ Datum values[Natts_pg_parameter_acl] = {0};
+ bool nulls[Natts_pg_parameter_acl] = {0};
+ bool replaces[Natts_pg_parameter_acl] = {0};
replaces[Anum_pg_parameter_acl_paracl - 1] = true;
values[Anum_pg_parameter_acl_paracl - 1] = PointerGetDatum(new_acl);
@@ -6419,17 +6367,13 @@ recordExtensionInitPrivWorker(Oid objoid, Oid classoid, int objsubid, Acl *new_a
/* If we find an entry, update it with the latest ACL. */
if (HeapTupleIsValid(oldtuple))
{
- Datum values[Natts_pg_init_privs];
- bool nulls[Natts_pg_init_privs];
- bool replace[Natts_pg_init_privs];
+ Datum values[Natts_pg_init_privs] = {0};
+ bool nulls[Natts_pg_init_privs] = {0};
+ bool replace[Natts_pg_init_privs] = {0};
/* If we have a new ACL to set, then update the row with it. */
if (new_acl)
{
- MemSet(values, 0, sizeof(values));
- MemSet(nulls, false, sizeof(nulls));
- MemSet(replace, false, sizeof(replace));
-
values[Anum_pg_init_privs_initprivs - 1] = PointerGetDatum(new_acl);
replace[Anum_pg_init_privs_initprivs - 1] = true;
@@ -6446,8 +6390,8 @@ recordExtensionInitPrivWorker(Oid objoid, Oid classoid, int objsubid, Acl *new_a
}
else
{
- Datum values[Natts_pg_init_privs];
- bool nulls[Natts_pg_init_privs];
+ Datum values[Natts_pg_init_privs] = {0};
+ bool nulls[Natts_pg_init_privs] = {0};
/*
* Only add a new entry if the new ACL is non-NULL.
@@ -6458,8 +6402,6 @@ recordExtensionInitPrivWorker(Oid objoid, Oid classoid, int objsubid, Acl *new_a
if (new_acl)
{
/* No entry found, so add it. */
- MemSet(nulls, false, sizeof(nulls));
-
values[Anum_pg_init_privs_objoid - 1] = ObjectIdGetDatum(objoid);
values[Anum_pg_init_privs_classoid - 1] = ObjectIdGetDatum(classoid);
values[Anum_pg_init_privs_objsubid - 1] = Int32GetDatum(objsubid);
diff --git a/src/backend/catalog/dependency.c b/src/backend/catalog/dependency.c
index de10923391..5cbd72ce10 100644
--- a/src/backend/catalog/dependency.c
+++ b/src/backend/catalog/dependency.c
@@ -1635,12 +1635,11 @@ recordDependencyOnSingleRelExpr(const ObjectAddress *depender,
bool reverse_self)
{
find_expr_references_context context;
- RangeTblEntry rte;
+ RangeTblEntry rte = {0};
context.addrs = new_object_addresses();
/* We gin up a rather bogus rangetable list to handle Vars */
- MemSet(&rte, 0, sizeof(rte));
rte.type = T_RangeTblEntry;
rte.rtekind = RTE_RELATION;
rte.relid = relId;
diff --git a/src/backend/catalog/heap.c b/src/backend/catalog/heap.c
index e770ea6eb8..9b03579e6e 100644
--- a/src/backend/catalog/heap.c
+++ b/src/backend/catalog/heap.c
@@ -1709,15 +1709,11 @@ RemoveAttributeById(Oid relid, AttrNumber attnum)
/* clear the missing value if any */
if (attStruct->atthasmissing)
{
- Datum valuesAtt[Natts_pg_attribute];
- bool nullsAtt[Natts_pg_attribute];
- bool replacesAtt[Natts_pg_attribute];
+ Datum valuesAtt[Natts_pg_attribute] = {0};
+ bool nullsAtt[Natts_pg_attribute] = {0};
+ bool replacesAtt[Natts_pg_attribute] = {0};
/* update the tuple - set atthasmissing and attmissingval */
- MemSet(valuesAtt, 0, sizeof(valuesAtt));
- MemSet(nullsAtt, false, sizeof(nullsAtt));
- MemSet(replacesAtt, false, sizeof(replacesAtt));
-
valuesAtt[Anum_pg_attribute_atthasmissing - 1] =
BoolGetDatum(false);
replacesAtt[Anum_pg_attribute_atthasmissing - 1] = true;
@@ -2006,9 +2002,9 @@ RelationClearMissing(Relation rel)
void
SetAttrMissing(Oid relid, char *attname, char *value)
{
- Datum valuesAtt[Natts_pg_attribute];
- bool nullsAtt[Natts_pg_attribute];
- bool replacesAtt[Natts_pg_attribute];
+ Datum valuesAtt[Natts_pg_attribute] = {0};
+ bool nullsAtt[Natts_pg_attribute] = {0};
+ bool replacesAtt[Natts_pg_attribute] = {0};
Datum missingval;
Form_pg_attribute attStruct;
Relation attrrel,
@@ -2041,10 +2037,6 @@ SetAttrMissing(Oid relid, char *attname, char *value)
Int32GetDatum(attStruct->atttypmod));
/* update the tuple - set atthasmissing and attmissingval */
- MemSet(valuesAtt, 0, sizeof(valuesAtt));
- MemSet(nullsAtt, false, sizeof(nullsAtt));
- MemSet(replacesAtt, false, sizeof(replacesAtt));
-
valuesAtt[Anum_pg_attribute_atthasmissing - 1] = BoolGetDatum(true);
replacesAtt[Anum_pg_attribute_atthasmissing - 1] = true;
valuesAtt[Anum_pg_attribute_attmissingval - 1] = missingval;
@@ -3321,7 +3313,7 @@ StorePartitionKey(Relation rel,
Relation pg_partitioned_table;
HeapTuple tuple;
Datum values[Natts_pg_partitioned_table];
- bool nulls[Natts_pg_partitioned_table];
+ bool nulls[Natts_pg_partitioned_table] = {0};
ObjectAddress myself;
ObjectAddress referenced;
ObjectAddresses *addrs;
@@ -3347,8 +3339,6 @@ StorePartitionKey(Relation rel,
pg_partitioned_table = table_open(PartitionedRelationId, RowExclusiveLock);
- MemSet(nulls, false, sizeof(nulls));
-
/* Only this can ever be NULL */
if (!partexprDatum)
nulls[Anum_pg_partitioned_table_partexprs - 1] = true;
diff --git a/src/backend/catalog/index.c b/src/backend/catalog/index.c
index c5d463ac55..d7192f35e3 100644
--- a/src/backend/catalog/index.c
+++ b/src/backend/catalog/index.c
@@ -554,7 +554,7 @@ UpdateIndexRelation(Oid indexoid,
Datum exprsDatum;
Datum predDatum;
Datum values[Natts_pg_index];
- bool nulls[Natts_pg_index];
+ bool nulls[Natts_pg_index] = {0};
Relation pg_index;
HeapTuple tuple;
int i;
@@ -608,8 +608,6 @@ UpdateIndexRelation(Oid indexoid,
/*
* Build a pg_index tuple
*/
- MemSet(nulls, false, sizeof(nulls));
-
values[Anum_pg_index_indexrelid - 1] = ObjectIdGetDatum(indexoid);
values[Anum_pg_index_indrelid - 1] = ObjectIdGetDatum(heapoid);
values[Anum_pg_index_indnatts - 1] = Int16GetDatum(indexInfo->ii_NumIndexAttrs);
diff --git a/src/backend/catalog/pg_attrdef.c b/src/backend/catalog/pg_attrdef.c
index c5d4a9912e..1a14093a9a 100644
--- a/src/backend/catalog/pg_attrdef.c
+++ b/src/backend/catalog/pg_attrdef.c
@@ -111,15 +111,12 @@ StoreAttrDefault(Relation rel, AttrNumber attnum,
Expr *expr2 = (Expr *) expr;
EState *estate = NULL;
ExprContext *econtext;
- Datum valuesAtt[Natts_pg_attribute];
- bool nullsAtt[Natts_pg_attribute];
- bool replacesAtt[Natts_pg_attribute];
+ Datum valuesAtt[Natts_pg_attribute] = {0};
+ bool nullsAtt[Natts_pg_attribute] = {0};
+ bool replacesAtt[Natts_pg_attribute] = {0};
Datum missingval = (Datum) 0;
bool missingIsNull = true;
- MemSet(valuesAtt, 0, sizeof(valuesAtt));
- MemSet(nullsAtt, false, sizeof(nullsAtt));
- MemSet(replacesAtt, false, sizeof(replacesAtt));
valuesAtt[Anum_pg_attribute_atthasdef - 1] = true;
replacesAtt[Anum_pg_attribute_atthasdef - 1] = true;
diff --git a/src/backend/catalog/pg_cast.c b/src/backend/catalog/pg_cast.c
index 4857f6468d..1812bb7fcc 100644
--- a/src/backend/catalog/pg_cast.c
+++ b/src/backend/catalog/pg_cast.c
@@ -47,7 +47,7 @@ CastCreate(Oid sourcetypeid, Oid targettypeid, Oid funcid, char castcontext,
HeapTuple tuple;
Oid castid;
Datum values[Natts_pg_cast];
- bool nulls[Natts_pg_cast];
+ bool nulls[Natts_pg_cast] = {0};
ObjectAddress myself,
referenced;
ObjectAddresses *addrs;
@@ -78,8 +78,6 @@ CastCreate(Oid sourcetypeid, Oid targettypeid, Oid funcid, char castcontext,
values[Anum_pg_cast_castcontext - 1] = CharGetDatum(castcontext);
values[Anum_pg_cast_castmethod - 1] = CharGetDatum(castmethod);
- MemSet(nulls, false, sizeof(nulls));
-
tuple = heap_form_tuple(RelationGetDescr(relation), values, nulls);
CatalogTupleInsert(relation, tuple);
diff --git a/src/backend/catalog/pg_parameter_acl.c b/src/backend/catalog/pg_parameter_acl.c
index 2decee909b..0570e811d1 100644
--- a/src/backend/catalog/pg_parameter_acl.c
+++ b/src/backend/catalog/pg_parameter_acl.c
@@ -74,8 +74,8 @@ ParameterAclCreate(const char *parameter)
Relation rel;
TupleDesc tupDesc;
HeapTuple tuple;
- Datum values[Natts_pg_parameter_acl];
- bool nulls[Natts_pg_parameter_acl];
+ Datum values[Natts_pg_parameter_acl] = {0};
+ bool nulls[Natts_pg_parameter_acl] = {0};
/*
* To prevent cluttering pg_parameter_acl with useless entries, insist
@@ -98,8 +98,6 @@ ParameterAclCreate(const char *parameter)
*/
rel = table_open(ParameterAclRelationId, RowExclusiveLock);
tupDesc = RelationGetDescr(rel);
- MemSet(values, 0, sizeof(values));
- MemSet(nulls, false, sizeof(nulls));
parameterId = GetNewOidWithIndex(rel,
ParameterAclOidIndexId,
Anum_pg_parameter_acl_oid);
diff --git a/src/backend/catalog/pg_publication.c b/src/backend/catalog/pg_publication.c
index c365de3a72..ade3bf3aca 100644
--- a/src/backend/catalog/pg_publication.c
+++ b/src/backend/catalog/pg_publication.c
@@ -1162,14 +1162,12 @@ pg_get_publication_tables(PG_FUNCTION_ARGS)
HeapTuple pubtuple = NULL;
HeapTuple rettuple;
Oid relid = list_nth_oid(tables, funcctx->call_cntr);
- Datum values[NUM_PUBLICATION_TABLES_ELEM];
- bool nulls[NUM_PUBLICATION_TABLES_ELEM];
+ Datum values[NUM_PUBLICATION_TABLES_ELEM] = {0};
+ bool nulls[NUM_PUBLICATION_TABLES_ELEM] = {0};
/*
* Form tuple with appropriate data.
*/
- MemSet(nulls, 0, sizeof(nulls));
- MemSet(values, 0, sizeof(values));
publication = GetPublicationByName(pubname, false);
diff --git a/src/backend/commands/dbcommands.c b/src/backend/commands/dbcommands.c
index 1901b434c5..099d369b2f 100644
--- a/src/backend/commands/dbcommands.c
+++ b/src/backend/commands/dbcommands.c
@@ -689,8 +689,8 @@ createdb(ParseState *pstate, const CreatedbStmt *stmt)
volatile Oid dst_deftablespace;
Relation pg_database_rel;
HeapTuple tuple;
- Datum new_record[Natts_pg_database];
- bool new_record_nulls[Natts_pg_database];
+ Datum new_record[Natts_pg_database] = {0};
+ bool new_record_nulls[Natts_pg_database] = {0};
Oid dboid = InvalidOid;
Oid datdba;
ListCell *option;
@@ -1296,9 +1296,6 @@ createdb(ParseState *pstate, const CreatedbStmt *stmt)
(dblocprovider != COLLPROVIDER_ICU && !dbiculocale));
/* Form tuple */
- MemSet(new_record, 0, sizeof(new_record));
- MemSet(new_record_nulls, false, sizeof(new_record_nulls));
-
new_record[Anum_pg_database_oid - 1] = ObjectIdGetDatum(dboid);
new_record[Anum_pg_database_datname - 1] =
DirectFunctionCall1(namein, CStringGetDatum(dbname));
@@ -1822,9 +1819,6 @@ movedb(const char *dbname, const char *tblspcname)
newtuple;
Oid src_tblspcoid,
dst_tblspcoid;
- Datum new_record[Natts_pg_database];
- bool new_record_nulls[Natts_pg_database];
- bool new_record_repl[Natts_pg_database];
ScanKeyData scankey;
SysScanDesc sysscan;
AclResult aclresult;
@@ -2003,6 +1997,10 @@ movedb(const char *dbname, const char *tblspcname)
PG_ENSURE_ERROR_CLEANUP(movedb_failure_callback,
PointerGetDatum(&fparms));
{
+ Datum new_record[Natts_pg_database] = {0};
+ bool new_record_nulls[Natts_pg_database] = {0};
+ bool new_record_repl[Natts_pg_database] = {0};
+
/*
* Copy files from the old tablespace to the new one
*/
@@ -2042,10 +2040,6 @@ movedb(const char *dbname, const char *tblspcname)
(errcode(ERRCODE_UNDEFINED_DATABASE),
errmsg("database \"%s\" does not exist", dbname)));
- MemSet(new_record, 0, sizeof(new_record));
- MemSet(new_record_nulls, false, sizeof(new_record_nulls));
- MemSet(new_record_repl, false, sizeof(new_record_repl));
-
new_record[Anum_pg_database_dattablespace - 1] = ObjectIdGetDatum(dst_tblspcoid);
new_record_repl[Anum_pg_database_dattablespace - 1] = true;
@@ -2194,9 +2188,9 @@ AlterDatabase(ParseState *pstate, AlterDatabaseStmt *stmt, bool isTopLevel)
DefElem *dallowconnections = NULL;
DefElem *dconnlimit = NULL;
DefElem *dtablespace = NULL;
- Datum new_record[Natts_pg_database];
- bool new_record_nulls[Natts_pg_database];
- bool new_record_repl[Natts_pg_database];
+ Datum new_record[Natts_pg_database] = {0};
+ bool new_record_nulls[Natts_pg_database] = {0};
+ bool new_record_repl[Natts_pg_database] = {0};
/* Extract options from the statement node tree */
foreach(option, stmt->options)
@@ -2305,10 +2299,6 @@ AlterDatabase(ParseState *pstate, AlterDatabaseStmt *stmt, bool isTopLevel)
/*
* Build an updated tuple, perusing the information just obtained
*/
- MemSet(new_record, 0, sizeof(new_record));
- MemSet(new_record_nulls, false, sizeof(new_record_nulls));
- MemSet(new_record_repl, false, sizeof(new_record_repl));
-
if (distemplate)
{
new_record[Anum_pg_database_datistemplate - 1] = BoolGetDatum(dbistemplate);
@@ -2492,8 +2482,8 @@ AlterDatabaseOwner(const char *dbname, Oid newOwnerId)
if (datForm->datdba != newOwnerId)
{
Datum repl_val[Natts_pg_database];
- bool repl_null[Natts_pg_database];
- bool repl_repl[Natts_pg_database];
+ bool repl_null[Natts_pg_database] = {0};
+ bool repl_repl[Natts_pg_database] = {0};
Acl *newAcl;
Datum aclDatum;
bool isNull;
@@ -2521,9 +2511,6 @@ AlterDatabaseOwner(const char *dbname, Oid newOwnerId)
(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
errmsg("permission denied to change owner of database")));
- memset(repl_null, false, sizeof(repl_null));
- memset(repl_repl, false, sizeof(repl_repl));
-
repl_repl[Anum_pg_database_datdba - 1] = true;
repl_val[Anum_pg_database_datdba - 1] = ObjectIdGetDatum(newOwnerId);
diff --git a/src/backend/commands/event_trigger.c b/src/backend/commands/event_trigger.c
index f46f86474a..eef3e5d56e 100644
--- a/src/backend/commands/event_trigger.c
+++ b/src/backend/commands/event_trigger.c
@@ -1310,14 +1310,11 @@ pg_event_trigger_dropped_objects(PG_FUNCTION_ARGS)
{
SQLDropObject *obj;
int i = 0;
- Datum values[12];
- bool nulls[12];
+ Datum values[12] = {0};
+ bool nulls[12] = {0};
obj = slist_container(SQLDropObject, next, iter.cur);
- MemSet(values, 0, sizeof(values));
- MemSet(nulls, 0, sizeof(nulls));
-
/* classid */
values[i++] = ObjectIdGetDatum(obj->address.classId);
@@ -1840,7 +1837,7 @@ pg_event_trigger_ddl_commands(PG_FUNCTION_ARGS)
{
CollectedCommand *cmd = lfirst(lc);
Datum values[9];
- bool nulls[9];
+ bool nulls[9] = {0};
ObjectAddress addr;
int i = 0;
@@ -1858,8 +1855,6 @@ pg_event_trigger_ddl_commands(PG_FUNCTION_ARGS)
!OidIsValid(cmd->d.simple.address.objectId))
continue;
- MemSet(nulls, 0, sizeof(nulls));
-
switch (cmd->type)
{
case SCT_Simple:
diff --git a/src/backend/commands/functioncmds.c b/src/backend/commands/functioncmds.c
index b016eecb2c..59e3af626f 100644
--- a/src/backend/commands/functioncmds.c
+++ b/src/backend/commands/functioncmds.c
@@ -1806,8 +1806,8 @@ CreateTransform(CreateTransformStmt *stmt)
AclResult aclresult;
Form_pg_proc procstruct;
Datum values[Natts_pg_transform];
- bool nulls[Natts_pg_transform];
- bool replaces[Natts_pg_transform];
+ bool nulls[Natts_pg_transform] = {0};
+ bool replaces[Natts_pg_transform] = {0};
Oid transformid;
HeapTuple tuple;
HeapTuple newtuple;
@@ -1913,8 +1913,6 @@ CreateTransform(CreateTransformStmt *stmt)
values[Anum_pg_transform_trffromsql - 1] = ObjectIdGetDatum(fromsqlfuncid);
values[Anum_pg_transform_trftosql - 1] = ObjectIdGetDatum(tosqlfuncid);
- MemSet(nulls, false, sizeof(nulls));
-
relation = table_open(TransformRelationId, RowExclusiveLock);
tuple = SearchSysCache2(TRFTYPELANG,
@@ -1931,7 +1929,6 @@ CreateTransform(CreateTransformStmt *stmt)
format_type_be(typeid),
stmt->lang)));
- MemSet(replaces, false, sizeof(replaces));
replaces[Anum_pg_transform_trffromsql - 1] = true;
replaces[Anum_pg_transform_trftosql - 1] = true;
diff --git a/src/backend/commands/prepare.c b/src/backend/commands/prepare.c
index 2333aae467..579825c159 100644
--- a/src/backend/commands/prepare.c
+++ b/src/backend/commands/prepare.c
@@ -685,12 +685,10 @@ pg_prepared_statement(PG_FUNCTION_ARGS)
{
TupleDesc result_desc;
Datum values[8];
- bool nulls[8];
+ bool nulls[8] = {0};
result_desc = prep_stmt->plansource->resultDesc;
- MemSet(nulls, 0, sizeof(nulls));
-
values[0] = CStringGetTextDatum(prep_stmt->stmt_name);
values[1] = CStringGetTextDatum(prep_stmt->plansource->query_string);
values[2] = TimestampTzGetDatum(prep_stmt->prepare_time);
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index ef5b34a312..18f7a4ae86 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -9013,15 +9013,15 @@ ATAddForeignKeyConstraint(List **wqueue, AlteredTableInfo *tab, Relation rel,
bool recurse, bool recursing, LOCKMODE lockmode)
{
Relation pkrel;
- int16 pkattnum[INDEX_MAX_KEYS];
- int16 fkattnum[INDEX_MAX_KEYS];
- Oid pktypoid[INDEX_MAX_KEYS];
- Oid fktypoid[INDEX_MAX_KEYS];
- Oid opclasses[INDEX_MAX_KEYS];
- Oid pfeqoperators[INDEX_MAX_KEYS];
- Oid ppeqoperators[INDEX_MAX_KEYS];
- Oid ffeqoperators[INDEX_MAX_KEYS];
- int16 fkdelsetcols[INDEX_MAX_KEYS];
+ int16 pkattnum[INDEX_MAX_KEYS] = {0};
+ int16 fkattnum[INDEX_MAX_KEYS] = {0};
+ Oid pktypoid[INDEX_MAX_KEYS] = {0};
+ Oid fktypoid[INDEX_MAX_KEYS] = {0};
+ Oid opclasses[INDEX_MAX_KEYS] = {0};
+ Oid pfeqoperators[INDEX_MAX_KEYS] = {0};
+ Oid ppeqoperators[INDEX_MAX_KEYS] = {0};
+ Oid ffeqoperators[INDEX_MAX_KEYS] = {0};
+ int16 fkdelsetcols[INDEX_MAX_KEYS] = {0};
int i;
int numfks,
numpks,
@@ -9113,16 +9113,6 @@ ATAddForeignKeyConstraint(List **wqueue, AlteredTableInfo *tab, Relation rel,
* Look up the referencing attributes to make sure they exist, and record
* their attnums and type OIDs.
*/
- MemSet(pkattnum, 0, sizeof(pkattnum));
- MemSet(fkattnum, 0, sizeof(fkattnum));
- MemSet(pktypoid, 0, sizeof(pktypoid));
- MemSet(fktypoid, 0, sizeof(fktypoid));
- MemSet(opclasses, 0, sizeof(opclasses));
- MemSet(pfeqoperators, 0, sizeof(pfeqoperators));
- MemSet(ppeqoperators, 0, sizeof(ppeqoperators));
- MemSet(ffeqoperators, 0, sizeof(ffeqoperators));
- MemSet(fkdelsetcols, 0, sizeof(fkdelsetcols));
-
numfks = transformColumnNameList(RelationGetRelid(rel),
fkconstraint->fk_attrs,
fkattnum, fktypoid);
@@ -11498,7 +11488,7 @@ validateForeignKeyConstraint(char *conname,
{
TupleTableSlot *slot;
TableScanDesc scan;
- Trigger trig;
+ Trigger trig = {0};
Snapshot snapshot;
MemoryContext oldcxt;
MemoryContext perTupCxt;
@@ -11509,7 +11499,6 @@ validateForeignKeyConstraint(char *conname,
/*
* Build a trigger call structure; we'll need it either way.
*/
- MemSet(&trig, 0, sizeof(trig));
trig.tgoid = InvalidOid;
trig.tgname = conname;
trig.tgenabled = TRIGGER_FIRES_ON_ORIGIN;
@@ -12783,15 +12772,11 @@ ATExecAlterColumnType(AlteredTableInfo *tab, Relation rel,
int one = 1;
bool isNull;
- Datum valuesAtt[Natts_pg_attribute];
- bool nullsAtt[Natts_pg_attribute];
- bool replacesAtt[Natts_pg_attribute];
+ Datum valuesAtt[Natts_pg_attribute] = {0};
+ bool nullsAtt[Natts_pg_attribute] = {0};
+ bool replacesAtt[Natts_pg_attribute] = {0};
HeapTuple newTup;
- MemSet(valuesAtt, 0, sizeof(valuesAtt));
- MemSet(nullsAtt, false, sizeof(nullsAtt));
- MemSet(replacesAtt, false, sizeof(replacesAtt));
-
missingval = array_get_element(missingval,
1,
&one,
@@ -19219,7 +19204,7 @@ ATDetachCheckNoForeignKeyRefs(Relation partition)
HeapTuple tuple;
Form_pg_constraint constrForm;
Relation rel;
- Trigger trig;
+ Trigger trig = {0};
tuple = SearchSysCache1(CONSTROID, ObjectIdGetDatum(constrOid));
if (!HeapTupleIsValid(tuple))
@@ -19232,7 +19217,6 @@ ATDetachCheckNoForeignKeyRefs(Relation partition)
/* prevent data changes into the referencing table until commit */
rel = table_open(constrForm->conrelid, ShareLock);
- MemSet(&trig, 0, sizeof(trig));
trig.tgoid = InvalidOid;
trig.tgname = NameStr(constrForm->conname);
trig.tgenabled = TRIGGER_FIRES_ON_ORIGIN;
diff --git a/src/backend/commands/tablespace.c b/src/backend/commands/tablespace.c
index c8bdd9992a..cb7d46089a 100644
--- a/src/backend/commands/tablespace.c
+++ b/src/backend/commands/tablespace.c
@@ -238,7 +238,7 @@ CreateTableSpace(CreateTableSpaceStmt *stmt)
#ifdef HAVE_SYMLINK
Relation rel;
Datum values[Natts_pg_tablespace];
- bool nulls[Natts_pg_tablespace];
+ bool nulls[Natts_pg_tablespace] = {0};
HeapTuple tuple;
Oid tablespaceoid;
char *location;
@@ -340,8 +340,6 @@ CreateTableSpace(CreateTableSpaceStmt *stmt)
*/
rel = table_open(TableSpaceRelationId, RowExclusiveLock);
- MemSet(nulls, false, sizeof(nulls));
-
if (IsBinaryUpgrade)
{
/* Use binary-upgrade override for tablespace oid */
diff --git a/src/backend/commands/typecmds.c b/src/backend/commands/typecmds.c
index 4f5e7c7ccb..4f58d29aa5 100644
--- a/src/backend/commands/typecmds.c
+++ b/src/backend/commands/typecmds.c
@@ -2570,9 +2570,9 @@ AlterDomainDefault(List *names, Node *defaultRaw)
Relation rel;
char *defaultValue;
Node *defaultExpr = NULL; /* NULL if no default specified */
- Datum new_record[Natts_pg_type];
- bool new_record_nulls[Natts_pg_type];
- bool new_record_repl[Natts_pg_type];
+ Datum new_record[Natts_pg_type] = {0};
+ bool new_record_nulls[Natts_pg_type] = {0};
+ bool new_record_repl[Natts_pg_type] = {0};
HeapTuple newtuple;
Form_pg_type typTup;
ObjectAddress address;
@@ -2593,9 +2593,6 @@ AlterDomainDefault(List *names, Node *defaultRaw)
checkDomainOwner(tup);
/* Setup new tuple */
- MemSet(new_record, (Datum) 0, sizeof(new_record));
- MemSet(new_record_nulls, false, sizeof(new_record_nulls));
- MemSet(new_record_repl, false, sizeof(new_record_repl));
/* Store the new default into the tuple */
if (defaultRaw)
diff --git a/src/backend/commands/user.c b/src/backend/commands/user.c
index 984305ba31..5b24b6dcad 100644
--- a/src/backend/commands/user.c
+++ b/src/backend/commands/user.c
@@ -74,8 +74,8 @@ CreateRole(ParseState *pstate, CreateRoleStmt *stmt)
Relation pg_authid_rel;
TupleDesc pg_authid_dsc;
HeapTuple tuple;
- Datum new_record[Natts_pg_authid];
- bool new_record_nulls[Natts_pg_authid];
+ Datum new_record[Natts_pg_authid] = {0};
+ bool new_record_nulls[Natts_pg_authid] = {0};
Oid roleid;
ListCell *item;
ListCell *option;
@@ -338,12 +338,8 @@ CreateRole(ParseState *pstate, CreateRoleStmt *stmt)
/*
* Build a tuple to insert
*/
- MemSet(new_record, 0, sizeof(new_record));
- MemSet(new_record_nulls, false, sizeof(new_record_nulls));
-
new_record[Anum_pg_authid_rolname - 1] =
DirectFunctionCall1(namein, CStringGetDatum(stmt->role));
-
new_record[Anum_pg_authid_rolsuper - 1] = BoolGetDatum(issuper);
new_record[Anum_pg_authid_rolinherit - 1] = BoolGetDatum(inherit);
new_record[Anum_pg_authid_rolcreaterole - 1] = BoolGetDatum(createrole);
@@ -492,9 +488,9 @@ CreateRole(ParseState *pstate, CreateRoleStmt *stmt)
Oid
AlterRole(ParseState *pstate, AlterRoleStmt *stmt)
{
- Datum new_record[Natts_pg_authid];
- bool new_record_nulls[Natts_pg_authid];
- bool new_record_repl[Natts_pg_authid];
+ Datum new_record[Natts_pg_authid] = {0};
+ bool new_record_nulls[Natts_pg_authid] = {0};
+ bool new_record_repl[Natts_pg_authid] = {0};
Relation pg_authid_rel;
TupleDesc pg_authid_dsc;
HeapTuple tuple,
@@ -691,9 +687,6 @@ AlterRole(ParseState *pstate, AlterRoleStmt *stmt)
/*
* Build an updated tuple, perusing the information just obtained
*/
- MemSet(new_record, 0, sizeof(new_record));
- MemSet(new_record_nulls, false, sizeof(new_record_nulls));
- MemSet(new_record_repl, false, sizeof(new_record_repl));
/*
* issuper/createrole/etc
@@ -1440,9 +1433,9 @@ AddRoleMems(const char *rolename, Oid roleid,
Oid memberid = lfirst_oid(iditem);
HeapTuple authmem_tuple;
HeapTuple tuple;
- Datum new_record[Natts_pg_auth_members];
- bool new_record_nulls[Natts_pg_auth_members];
- bool new_record_repl[Natts_pg_auth_members];
+ Datum new_record[Natts_pg_auth_members] = {0};
+ bool new_record_nulls[Natts_pg_auth_members] = {0};
+ bool new_record_repl[Natts_pg_auth_members] = {0};
/*
* pg_database_owner is never a role member. Lifting this restriction
@@ -1500,10 +1493,6 @@ AddRoleMems(const char *rolename, Oid roleid,
}
/* Build a tuple to insert or update */
- MemSet(new_record, 0, sizeof(new_record));
- MemSet(new_record_nulls, false, sizeof(new_record_nulls));
- MemSet(new_record_repl, false, sizeof(new_record_repl));
-
new_record[Anum_pg_auth_members_roleid - 1] = ObjectIdGetDatum(roleid);
new_record[Anum_pg_auth_members_member - 1] = ObjectIdGetDatum(memberid);
new_record[Anum_pg_auth_members_grantor - 1] = ObjectIdGetDatum(grantorId);
@@ -1614,15 +1603,11 @@ DelRoleMems(const char *rolename, Oid roleid,
{
/* Just turn off the admin option */
HeapTuple tuple;
- Datum new_record[Natts_pg_auth_members];
- bool new_record_nulls[Natts_pg_auth_members];
- bool new_record_repl[Natts_pg_auth_members];
+ Datum new_record[Natts_pg_auth_members] = {0};
+ bool new_record_nulls[Natts_pg_auth_members] = {0};
+ bool new_record_repl[Natts_pg_auth_members] = {0};
/* Build a tuple to update with */
- MemSet(new_record, 0, sizeof(new_record));
- MemSet(new_record_nulls, false, sizeof(new_record_nulls));
- MemSet(new_record_repl, false, sizeof(new_record_repl));
-
new_record[Anum_pg_auth_members_admin_option - 1] = BoolGetDatum(false);
new_record_repl[Anum_pg_auth_members_admin_option - 1] = true;
diff --git a/src/backend/optimizer/path/costsize.c b/src/backend/optimizer/path/costsize.c
index fcc26b01a4..1e0f1880c5 100644
--- a/src/backend/optimizer/path/costsize.c
+++ b/src/backend/optimizer/path/costsize.c
@@ -2926,13 +2926,12 @@ cost_agg(Path *path, PlannerInfo *root,
double output_tuples;
Cost startup_cost;
Cost total_cost;
- AggClauseCosts dummy_aggcosts;
+ const AggClauseCosts dummy_aggcosts = {0};
/* Use all-zero per-aggregate costs if NULL is passed */
if (aggcosts == NULL)
{
Assert(aggstrategy == AGG_HASHED);
- MemSet(&dummy_aggcosts, 0, sizeof(AggClauseCosts));
aggcosts = &dummy_aggcosts;
}
diff --git a/src/backend/parser/parse_target.c b/src/backend/parser/parse_target.c
index 2a1d44b813..16a0fe59e2 100644
--- a/src/backend/parser/parse_target.c
+++ b/src/backend/parser/parse_target.c
@@ -1594,9 +1594,8 @@ expandRecordVariable(ParseState *pstate, Var *var, int levelsup)
* to. We have to build an additional level of ParseState
* to keep in step with varlevelsup in the subselect.
*/
- ParseState mypstate;
+ ParseState mypstate = {0};
- MemSet(&mypstate, 0, sizeof(mypstate));
mypstate.parentParseState = pstate;
mypstate.p_rtable = rte->subquery->rtable;
/* don't bother filling the rest of the fake pstate */
diff --git a/src/backend/replication/logical/launcher.c b/src/backend/replication/logical/launcher.c
index 2bdab53e19..3bbd522724 100644
--- a/src/backend/replication/logical/launcher.c
+++ b/src/backend/replication/logical/launcher.c
@@ -938,8 +938,8 @@ pg_stat_get_subscription(PG_FUNCTION_ARGS)
for (i = 0; i < max_logical_replication_workers; i++)
{
/* for each row */
- Datum values[PG_STAT_GET_SUBSCRIPTION_COLS];
- bool nulls[PG_STAT_GET_SUBSCRIPTION_COLS];
+ Datum values[PG_STAT_GET_SUBSCRIPTION_COLS] = {0};
+ bool nulls[PG_STAT_GET_SUBSCRIPTION_COLS] = {0};
int worker_pid;
LogicalRepWorker worker;
@@ -953,9 +953,6 @@ pg_stat_get_subscription(PG_FUNCTION_ARGS)
worker_pid = worker.proc->pid;
- MemSet(values, 0, sizeof(values));
- MemSet(nulls, 0, sizeof(nulls));
-
values[0] = ObjectIdGetDatum(worker.subid);
if (OidIsValid(worker.relid))
values[1] = ObjectIdGetDatum(worker.relid);
diff --git a/src/backend/replication/walsender.c b/src/backend/replication/walsender.c
index 3c407ab964..3a86786cc3 100644
--- a/src/backend/replication/walsender.c
+++ b/src/backend/replication/walsender.c
@@ -402,7 +402,7 @@ IdentifySystem(void)
TupOutputState *tstate;
TupleDesc tupdesc;
Datum values[4];
- bool nulls[4];
+ bool nulls[4] = {0};
TimeLineID currTLI;
/*
@@ -437,7 +437,6 @@ IdentifySystem(void)
}
dest = CreateDestReceiver(DestRemoteSimple);
- MemSet(nulls, false, sizeof(nulls));
/* need a tuple descriptor representing four columns */
tupdesc = CreateTemplateTupleDesc(4);
@@ -483,7 +482,7 @@ ReadReplicationSlot(ReadReplicationSlotCmd *cmd)
DestReceiver *dest;
TupOutputState *tstate;
TupleDesc tupdesc;
- Datum values[READ_REPLICATION_SLOT_COLS];
+ Datum values[READ_REPLICATION_SLOT_COLS] = {0};
bool nulls[READ_REPLICATION_SLOT_COLS];
tupdesc = CreateTemplateTupleDesc(READ_REPLICATION_SLOT_COLS);
@@ -495,8 +494,7 @@ ReadReplicationSlot(ReadReplicationSlotCmd *cmd)
TupleDescInitBuiltinEntry(tupdesc, (AttrNumber) 3, "restart_tli",
INT8OID, -1, 0);
- MemSet(values, 0, READ_REPLICATION_SLOT_COLS * sizeof(Datum));
- MemSet(nulls, true, READ_REPLICATION_SLOT_COLS * sizeof(bool));
+ memset(nulls, true, READ_REPLICATION_SLOT_COLS * sizeof(bool));
LWLockAcquire(ReplicationSlotControlLock, LW_SHARED);
slot = SearchNamedReplicationSlot(cmd->slotname, false);
@@ -859,13 +857,12 @@ StartReplication(StartReplicationCmd *cmd)
TupOutputState *tstate;
TupleDesc tupdesc;
Datum values[2];
- bool nulls[2];
+ bool nulls[2] = {0};
snprintf(startpos_str, sizeof(startpos_str), "%X/%X",
LSN_FORMAT_ARGS(sendTimeLineValidUpto));
dest = CreateDestReceiver(DestRemoteSimple);
- MemSet(nulls, false, sizeof(nulls));
/*
* Need a tuple descriptor representing two columns. int8 may seem
@@ -1043,7 +1040,7 @@ CreateReplicationSlot(CreateReplicationSlotCmd *cmd)
TupOutputState *tstate;
TupleDesc tupdesc;
Datum values[4];
- bool nulls[4];
+ bool nulls[4] = {0};
Assert(!MyReplicationSlot);
@@ -1178,7 +1175,6 @@ CreateReplicationSlot(CreateReplicationSlotCmd *cmd)
LSN_FORMAT_ARGS(MyReplicationSlot->data.confirmed_flush));
dest = CreateDestReceiver(DestRemoteSimple);
- MemSet(nulls, false, sizeof(nulls));
/*----------
* Need a tuple descriptor representing four columns:
@@ -3488,7 +3484,7 @@ pg_stat_get_wal_senders(PG_FUNCTION_ARGS)
TimestampTz replyTime;
bool is_sync_standby;
Datum values[PG_STAT_GET_WAL_SENDERS_COLS];
- bool nulls[PG_STAT_GET_WAL_SENDERS_COLS];
+ bool nulls[PG_STAT_GET_WAL_SENDERS_COLS] = {0};
int j;
/* Collect data from shared memory */
@@ -3527,7 +3523,6 @@ pg_stat_get_wal_senders(PG_FUNCTION_ARGS)
}
}
- memset(nulls, 0, sizeof(nulls));
values[0] = Int32GetDatum(pid);
if (!has_privs_of_role(GetUserId(), ROLE_PG_READ_ALL_STATS))
diff --git a/src/backend/rewrite/rewriteDefine.c b/src/backend/rewrite/rewriteDefine.c
index 185bf5fbff..a5a1fb887f 100644
--- a/src/backend/rewrite/rewriteDefine.c
+++ b/src/backend/rewrite/rewriteDefine.c
@@ -67,8 +67,7 @@ InsertRule(const char *rulname,
char *evqual = nodeToString(event_qual);
char *actiontree = nodeToString((Node *) action);
Datum values[Natts_pg_rewrite];
- bool nulls[Natts_pg_rewrite];
- bool replaces[Natts_pg_rewrite];
+ bool nulls[Natts_pg_rewrite] = {0};
NameData rname;
Relation pg_rewrite_desc;
HeapTuple tup,
@@ -81,8 +80,6 @@ InsertRule(const char *rulname,
/*
* Set up *nulls and *values arrays
*/
- MemSet(nulls, false, sizeof(nulls));
-
namestrcpy(&rname, rulname);
values[Anum_pg_rewrite_rulename - 1] = NameGetDatum(&rname);
values[Anum_pg_rewrite_ev_class - 1] = ObjectIdGetDatum(eventrel_oid);
@@ -106,6 +103,8 @@ InsertRule(const char *rulname,
if (HeapTupleIsValid(oldtup))
{
+ bool replaces[Natts_pg_rewrite] = {0};
+
if (!replace)
ereport(ERROR,
(errcode(ERRCODE_DUPLICATE_OBJECT),
@@ -115,7 +114,6 @@ InsertRule(const char *rulname,
/*
* When replacing, we don't need to replace every attribute
*/
- MemSet(replaces, false, sizeof(replaces));
replaces[Anum_pg_rewrite_ev_type - 1] = true;
replaces[Anum_pg_rewrite_is_instead - 1] = true;
replaces[Anum_pg_rewrite_ev_qual - 1] = true;
diff --git a/src/backend/utils/adt/acl.c b/src/backend/utils/adt/acl.c
index b7fd3bcf05..6fa58dd8eb 100644
--- a/src/backend/utils/adt/acl.c
+++ b/src/backend/utils/adt/acl.c
@@ -1785,7 +1785,7 @@ aclexplode(PG_FUNCTION_ARGS)
{
Datum result;
Datum values[4];
- bool nulls[4];
+ bool nulls[4] = {0};
HeapTuple tuple;
values[0] = ObjectIdGetDatum(aidata->ai_grantor);
@@ -1793,8 +1793,6 @@ aclexplode(PG_FUNCTION_ARGS)
values[2] = CStringGetTextDatum(convert_aclright_to_string(priv_bit));
values[3] = BoolGetDatum((ACLITEM_GET_GOPTIONS(*aidata) & priv_bit) != 0);
- MemSet(nulls, 0, sizeof(nulls));
-
tuple = heap_form_tuple(funcctx->tuple_desc, values, nulls);
result = HeapTupleGetDatum(tuple);
diff --git a/src/backend/utils/adt/arrayfuncs.c b/src/backend/utils/adt/arrayfuncs.c
index b0c37ede87..fb167f226a 100644
--- a/src/backend/utils/adt/arrayfuncs.c
+++ b/src/backend/utils/adt/arrayfuncs.c
@@ -742,11 +742,10 @@ ReadArrayStr(char *arrayStr,
bool eoArray = false;
bool hasnull;
int32 totbytes;
- int indx[MAXDIM],
+ int indx[MAXDIM] = {0},
prod[MAXDIM];
mda_get_prod(ndim, dim, prod);
- MemSet(indx, 0, sizeof(indx));
/* Initialize is-null markers to true */
memset(nulls, true, nitems * sizeof(bool));
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 4c12c4d663..43fff50d49 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4924,7 +4924,7 @@ pg_timezone_abbrevs(PG_FUNCTION_ARGS)
Datum result;
HeapTuple tuple;
Datum values[3];
- bool nulls[3];
+ bool nulls[3] = {0};
const datetkn *tp;
char buffer[TOKMAXLEN + 1];
int gmtoffset;
@@ -5011,8 +5011,6 @@ pg_timezone_abbrevs(PG_FUNCTION_ARGS)
break;
}
- MemSet(nulls, 0, sizeof(nulls));
-
/*
* Convert name to text, using upcasing conversion that is the inverse of
* what ParseDateTime() uses.
@@ -5051,7 +5049,7 @@ pg_timezone_names(PG_FUNCTION_ARGS)
pg_tzenum *tzenum;
pg_tz *tz;
Datum values[4];
- bool nulls[4];
+ bool nulls[4] = {0};
int tzoff;
struct pg_tm tm;
fsec_t fsec;
@@ -5088,8 +5086,6 @@ pg_timezone_names(PG_FUNCTION_ARGS)
if (tzn && strlen(tzn) > 31)
continue;
- MemSet(nulls, 0, sizeof(nulls));
-
values[0] = CStringGetTextDatum(pg_get_timezone_name(tz));
values[1] = CStringGetTextDatum(tzn ? tzn : "");
diff --git a/src/backend/utils/adt/lockfuncs.c b/src/backend/utils/adt/lockfuncs.c
index dedee7af5c..f9b324efec 100644
--- a/src/backend/utils/adt/lockfuncs.c
+++ b/src/backend/utils/adt/lockfuncs.c
@@ -172,8 +172,8 @@ pg_lock_status(PG_FUNCTION_ARGS)
LOCKMODE mode = 0;
const char *locktypename;
char tnbuf[32];
- Datum values[NUM_LOCK_STATUS_COLUMNS];
- bool nulls[NUM_LOCK_STATUS_COLUMNS];
+ Datum values[NUM_LOCK_STATUS_COLUMNS] = {0};
+ bool nulls[NUM_LOCK_STATUS_COLUMNS] = {0};
HeapTuple tuple;
Datum result;
LockInstanceData *instance;
@@ -230,8 +230,6 @@ pg_lock_status(PG_FUNCTION_ARGS)
/*
* Form tuple with appropriate data.
*/
- MemSet(values, 0, sizeof(values));
- MemSet(nulls, false, sizeof(nulls));
if (instance->locktag.locktag_type <= LOCKTAG_LAST_TYPE)
locktypename = LockTagTypeNames[instance->locktag.locktag_type];
@@ -359,8 +357,8 @@ pg_lock_status(PG_FUNCTION_ARGS)
PREDICATELOCKTARGETTAG *predTag = &(predLockData->locktags[mystatus->predLockIdx]);
SERIALIZABLEXACT *xact = &(predLockData->xacts[mystatus->predLockIdx]);
- Datum values[NUM_LOCK_STATUS_COLUMNS];
- bool nulls[NUM_LOCK_STATUS_COLUMNS];
+ Datum values[NUM_LOCK_STATUS_COLUMNS] = {0};
+ bool nulls[NUM_LOCK_STATUS_COLUMNS] = {0};
HeapTuple tuple;
Datum result;
@@ -369,8 +367,6 @@ pg_lock_status(PG_FUNCTION_ARGS)
/*
* Form tuple with appropriate data.
*/
- MemSet(values, 0, sizeof(values));
- MemSet(nulls, false, sizeof(nulls));
/* lock type */
lockType = GET_PREDICATELOCKTARGETTAG_TYPE(*predTag);
diff --git a/src/backend/utils/adt/partitionfuncs.c b/src/backend/utils/adt/partitionfuncs.c
index 0243bc061f..109dc8023e 100644
--- a/src/backend/utils/adt/partitionfuncs.c
+++ b/src/backend/utils/adt/partitionfuncs.c
@@ -113,8 +113,8 @@ pg_partition_tree(PG_FUNCTION_ARGS)
if (funcctx->call_cntr < list_length(partitions))
{
Datum result;
- Datum values[PG_PARTITION_TREE_COLS];
- bool nulls[PG_PARTITION_TREE_COLS];
+ Datum values[PG_PARTITION_TREE_COLS] = {0};
+ bool nulls[PG_PARTITION_TREE_COLS] = {0};
HeapTuple tuple;
Oid parentid = InvalidOid;
Oid relid = list_nth_oid(partitions, funcctx->call_cntr);
@@ -126,8 +126,6 @@ pg_partition_tree(PG_FUNCTION_ARGS)
/*
* Form tuple with appropriate data.
*/
- MemSet(nulls, 0, sizeof(nulls));
- MemSet(values, 0, sizeof(values));
/* relid */
values[0] = ObjectIdGetDatum(relid);
diff --git a/src/backend/utils/adt/pgstatfuncs.c b/src/backend/utils/adt/pgstatfuncs.c
index 893690dad5..d9e2a79382 100644
--- a/src/backend/utils/adt/pgstatfuncs.c
+++ b/src/backend/utils/adt/pgstatfuncs.c
@@ -488,13 +488,10 @@ pg_stat_get_progress_info(PG_FUNCTION_ARGS)
{
LocalPgBackendStatus *local_beentry;
PgBackendStatus *beentry;
- Datum values[PG_STAT_GET_PROGRESS_COLS];
- bool nulls[PG_STAT_GET_PROGRESS_COLS];
+ Datum values[PG_STAT_GET_PROGRESS_COLS] = {0};
+ bool nulls[PG_STAT_GET_PROGRESS_COLS] = {0};
int i;
- MemSet(values, 0, sizeof(values));
- MemSet(nulls, 0, sizeof(nulls));
-
local_beentry = pgstat_fetch_stat_local_beentry(curr_backend);
if (!local_beentry)
@@ -551,17 +548,14 @@ pg_stat_get_activity(PG_FUNCTION_ARGS)
for (curr_backend = 1; curr_backend <= num_backends; curr_backend++)
{
/* for each row */
- Datum values[PG_STAT_GET_ACTIVITY_COLS];
- bool nulls[PG_STAT_GET_ACTIVITY_COLS];
+ Datum values[PG_STAT_GET_ACTIVITY_COLS] = {0};
+ bool nulls[PG_STAT_GET_ACTIVITY_COLS] = {0};
LocalPgBackendStatus *local_beentry;
PgBackendStatus *beentry;
PGPROC *proc;
const char *wait_event_type = NULL;
const char *wait_event = NULL;
- MemSet(values, 0, sizeof(values));
- MemSet(nulls, 0, sizeof(nulls));
-
/* Get the next one in the list */
local_beentry = pgstat_fetch_stat_local_beentry(curr_backend);
if (!local_beentry)
@@ -1747,15 +1741,11 @@ pg_stat_get_wal(PG_FUNCTION_ARGS)
{
#define PG_STAT_GET_WAL_COLS 9
TupleDesc tupdesc;
- Datum values[PG_STAT_GET_WAL_COLS];
- bool nulls[PG_STAT_GET_WAL_COLS];
+ Datum values[PG_STAT_GET_WAL_COLS] = {0};
+ bool nulls[PG_STAT_GET_WAL_COLS] = {0};
char buf[256];
PgStat_WalStats *wal_stats;
- /* Initialise values and NULL flags arrays */
- MemSet(values, 0, sizeof(values));
- MemSet(nulls, 0, sizeof(nulls));
-
/* Initialise attributes information in the tuple descriptor */
tupdesc = CreateTemplateTupleDesc(PG_STAT_GET_WAL_COLS);
TupleDescInitEntry(tupdesc, (AttrNumber) 1, "wal_records",
@@ -1826,8 +1816,8 @@ pg_stat_get_slru(PG_FUNCTION_ARGS)
for (i = 0;; i++)
{
/* for each row */
- Datum values[PG_STAT_GET_SLRU_COLS];
- bool nulls[PG_STAT_GET_SLRU_COLS];
+ Datum values[PG_STAT_GET_SLRU_COLS] = {0};
+ bool nulls[PG_STAT_GET_SLRU_COLS] = {0};
PgStat_SLRUStats stat;
const char *name;
@@ -1837,8 +1827,6 @@ pg_stat_get_slru(PG_FUNCTION_ARGS)
break;
stat = stats[i];
- MemSet(values, 0, sizeof(values));
- MemSet(nulls, 0, sizeof(nulls));
values[0] = PointerGetDatum(cstring_to_text(name));
values[1] = Int64GetDatum(stat.blocks_zeroed);
@@ -2201,14 +2189,10 @@ Datum
pg_stat_get_archiver(PG_FUNCTION_ARGS)
{
TupleDesc tupdesc;
- Datum values[7];
- bool nulls[7];
+ Datum values[7] = {0};
+ bool nulls[7] = {0};
PgStat_ArchiverStats *archiver_stats;
- /* Initialise values and NULL flags arrays */
- MemSet(values, 0, sizeof(values));
- MemSet(nulls, 0, sizeof(nulls));
-
/* Initialise attributes information in the tuple descriptor */
tupdesc = CreateTemplateTupleDesc(7);
TupleDescInitEntry(tupdesc, (AttrNumber) 1, "archived_count",
@@ -2274,15 +2258,11 @@ pg_stat_get_replication_slot(PG_FUNCTION_ARGS)
text *slotname_text = PG_GETARG_TEXT_P(0);
NameData slotname;
TupleDesc tupdesc;
- Datum values[PG_STAT_GET_REPLICATION_SLOT_COLS];
- bool nulls[PG_STAT_GET_REPLICATION_SLOT_COLS];
+ Datum values[PG_STAT_GET_REPLICATION_SLOT_COLS] = {0};
+ bool nulls[PG_STAT_GET_REPLICATION_SLOT_COLS] = {0};
PgStat_StatReplSlotEntry *slotent;
PgStat_StatReplSlotEntry allzero;
- /* Initialise values and NULL flags arrays */
- MemSet(values, 0, sizeof(values));
- MemSet(nulls, 0, sizeof(nulls));
-
/* Initialise attributes information in the tuple descriptor */
tupdesc = CreateTemplateTupleDesc(PG_STAT_GET_REPLICATION_SLOT_COLS);
TupleDescInitEntry(tupdesc, (AttrNumber) 1, "slot_name",
@@ -2348,8 +2328,8 @@ pg_stat_get_subscription_stats(PG_FUNCTION_ARGS)
#define PG_STAT_GET_SUBSCRIPTION_STATS_COLS 4
Oid subid = PG_GETARG_OID(0);
TupleDesc tupdesc;
- Datum values[PG_STAT_GET_SUBSCRIPTION_STATS_COLS];
- bool nulls[PG_STAT_GET_SUBSCRIPTION_STATS_COLS];
+ Datum values[PG_STAT_GET_SUBSCRIPTION_STATS_COLS] = {0};
+ bool nulls[PG_STAT_GET_SUBSCRIPTION_STATS_COLS] = {0};
PgStat_StatSubEntry *subentry;
PgStat_StatSubEntry allzero;
@@ -2368,10 +2348,6 @@ pg_stat_get_subscription_stats(PG_FUNCTION_ARGS)
TIMESTAMPTZOID, -1, 0);
BlessTupleDesc(tupdesc);
- /* Initialise values and NULL flags arrays */
- MemSet(values, 0, sizeof(values));
- MemSet(nulls, 0, sizeof(nulls));
-
if (!subentry)
{
/* If the subscription is not found, initialise its stats */
diff --git a/src/backend/utils/adt/selfuncs.c b/src/backend/utils/adt/selfuncs.c
index fa1f589fad..6f99b5b243 100644
--- a/src/backend/utils/adt/selfuncs.c
+++ b/src/backend/utils/adt/selfuncs.c
@@ -6642,10 +6642,10 @@ btcostestimate(PlannerInfo *root, IndexPath *path, double loop_count,
double *indexPages)
{
IndexOptInfo *index = path->indexinfo;
- GenericCosts costs;
+ GenericCosts costs = {0};
Oid relid;
AttrNumber colnum;
- VariableStatData vardata;
+ VariableStatData vardata = {0};
double numIndexTuples;
Cost descentCost;
List *indexBoundQuals;
@@ -6797,7 +6797,6 @@ btcostestimate(PlannerInfo *root, IndexPath *path, double loop_count,
/*
* Now do generic index cost estimation.
*/
- MemSet(&costs, 0, sizeof(costs));
costs.numIndexTuples = numIndexTuples;
genericcostestimate(root, path, loop_count, &costs);
@@ -6842,8 +6841,6 @@ btcostestimate(PlannerInfo *root, IndexPath *path, double loop_count,
* ordering, but don't negate it entirely. Before 8.0 we divided the
* correlation by the number of columns, but that seems too strong.)
*/
- MemSet(&vardata, 0, sizeof(vardata));
-
if (index->indexkeys[0] != 0)
{
/* Simple variable --- look to stats for the underlying table */
@@ -6947,9 +6944,7 @@ hashcostestimate(PlannerInfo *root, IndexPath *path, double loop_count,
Selectivity *indexSelectivity, double *indexCorrelation,
double *indexPages)
{
- GenericCosts costs;
-
- MemSet(&costs, 0, sizeof(costs));
+ GenericCosts costs = {0};
genericcostestimate(root, path, loop_count, &costs);
@@ -6992,11 +6987,9 @@ gistcostestimate(PlannerInfo *root, IndexPath *path, double loop_count,
double *indexPages)
{
IndexOptInfo *index = path->indexinfo;
- GenericCosts costs;
+ GenericCosts costs = {0};
Cost descentCost;
- MemSet(&costs, 0, sizeof(costs));
-
genericcostestimate(root, path, loop_count, &costs);
/*
@@ -7049,11 +7042,9 @@ spgcostestimate(PlannerInfo *root, IndexPath *path, double loop_count,
double *indexPages)
{
IndexOptInfo *index = path->indexinfo;
- GenericCosts costs;
+ GenericCosts costs = {0};
Cost descentCost;
- MemSet(&costs, 0, sizeof(costs));
-
genericcostestimate(root, path, loop_count, &costs);
/*
diff --git a/src/backend/utils/adt/timestamp.c b/src/backend/utils/adt/timestamp.c
index f70f829d83..49cdb290ac 100644
--- a/src/backend/utils/adt/timestamp.c
+++ b/src/backend/utils/adt/timestamp.c
@@ -2403,7 +2403,7 @@ interval_cmp_value(const Interval *interval)
}
static int
-interval_cmp_internal(Interval *interval1, Interval *interval2)
+interval_cmp_internal(const Interval *interval1, const Interval *interval2)
{
INT128 span1 = interval_cmp_value(interval1);
INT128 span2 = interval_cmp_value(interval2);
@@ -5777,7 +5777,7 @@ generate_series_timestamp(PG_FUNCTION_ARGS)
Timestamp finish = PG_GETARG_TIMESTAMP(1);
Interval *step = PG_GETARG_INTERVAL_P(2);
MemoryContext oldcontext;
- Interval interval_zero;
+ const Interval interval_zero = {0};
/* create a function context for cross-call persistence */
funcctx = SRF_FIRSTCALL_INIT();
@@ -5800,7 +5800,6 @@ generate_series_timestamp(PG_FUNCTION_ARGS)
fctx->step = *step;
/* Determine sign of the interval */
- MemSet(&interval_zero, 0, sizeof(Interval));
fctx->step_sign = interval_cmp_internal(&fctx->step, &interval_zero);
if (fctx->step_sign == 0)
@@ -5857,7 +5856,7 @@ generate_series_timestamptz(PG_FUNCTION_ARGS)
TimestampTz finish = PG_GETARG_TIMESTAMPTZ(1);
Interval *step = PG_GETARG_INTERVAL_P(2);
MemoryContext oldcontext;
- Interval interval_zero;
+ const Interval interval_zero = {0};
/* create a function context for cross-call persistence */
funcctx = SRF_FIRSTCALL_INIT();
@@ -5880,7 +5879,6 @@ generate_series_timestamptz(PG_FUNCTION_ARGS)
fctx->step = *step;
/* Determine sign of the interval */
- MemSet(&interval_zero, 0, sizeof(Interval));
fctx->step_sign = interval_cmp_internal(&fctx->step, &interval_zero);
if (fctx->step_sign == 0)
diff --git a/src/backend/utils/mmgr/portalmem.c b/src/backend/utils/mmgr/portalmem.c
index d549f66d4a..3a161bdb88 100644
--- a/src/backend/utils/mmgr/portalmem.c
+++ b/src/backend/utils/mmgr/portalmem.c
@@ -1146,14 +1146,12 @@ pg_cursor(PG_FUNCTION_ARGS)
{
Portal portal = hentry->portal;
Datum values[6];
- bool nulls[6];
+ bool nulls[6] = {0};
/* report only "visible" entries */
if (!portal->visible)
continue;
- MemSet(nulls, 0, sizeof(nulls));
-
values[0] = CStringGetTextDatum(portal->name);
values[1] = CStringGetTextDatum(portal->sourceText);
values[2] = BoolGetDatum(portal->cursorOptions & CURSOR_OPT_HOLD);
diff --git a/src/bin/pg_basebackup/pg_basebackup.c b/src/bin/pg_basebackup/pg_basebackup.c
index 4445a86aee..79b23fa7d7 100644
--- a/src/bin/pg_basebackup/pg_basebackup.c
+++ b/src/bin/pg_basebackup/pg_basebackup.c
@@ -447,7 +447,7 @@ reached_end_position(XLogRecPtr segendpos, uint32 timeline,
{
#ifndef WIN32
fd_set fds;
- struct timeval tv;
+ struct timeval tv = {0};
int r;
/*
@@ -457,16 +457,13 @@ reached_end_position(XLogRecPtr segendpos, uint32 timeline,
FD_ZERO(&fds);
FD_SET(bgpipe[0], &fds);
- MemSet(&tv, 0, sizeof(tv));
-
r = select(bgpipe[0] + 1, &fds, NULL, NULL, &tv);
if (r == 1)
{
- char xlogend[64];
+ char xlogend[64] = {0};
uint32 hi,
lo;
- MemSet(xlogend, 0, sizeof(xlogend));
r = read(bgpipe[0], xlogend, sizeof(xlogend) - 1);
if (r < 0)
pg_fatal("could not read from ready pipe: %m");
@@ -528,11 +525,10 @@ typedef struct
static int
LogStreamerMain(logstreamer_param *param)
{
- StreamCtl stream;
+ StreamCtl stream = {0};
in_log_streamer = true;
- MemSet(&stream, 0, sizeof(stream));
stream.startpos = param->startptr;
stream.timeline = param->timeline;
stream.sysidentifier = param->sysidentifier;
@@ -1952,7 +1948,6 @@ BaseBackup(char *compression_algorithm, char *compression_detail,
else
starttli = latesttli;
PQclear(res);
- MemSet(xlogend, 0, sizeof(xlogend));
if (verbose && includewal != NO_WAL)
pg_log_info("write-ahead log start point: %s on timeline %u",
diff --git a/src/bin/pg_basebackup/pg_receivewal.c b/src/bin/pg_basebackup/pg_receivewal.c
index ea3902c971..f064cff4ab 100644
--- a/src/bin/pg_basebackup/pg_receivewal.c
+++ b/src/bin/pg_basebackup/pg_receivewal.c
@@ -564,11 +564,9 @@ StreamLog(void)
{
XLogRecPtr serverpos;
TimeLineID servertli;
- StreamCtl stream;
+ StreamCtl stream = {0};
char *sysidentifier;
- MemSet(&stream, 0, sizeof(stream));
-
/*
* Connect in replication mode to the server
*/
diff --git a/src/bin/pg_basebackup/walmethods.c b/src/bin/pg_basebackup/walmethods.c
index ef4c11277a..e90aa0ba37 100644
--- a/src/bin/pg_basebackup/walmethods.c
+++ b/src/bin/pg_basebackup/walmethods.c
@@ -1111,9 +1111,8 @@ tar_close(Walfile f, WalCloseMethod method)
padding = tarPaddingBytesRequired(filesize);
if (padding)
{
- char zerobuf[TAR_BLOCK_SIZE];
+ char zerobuf[TAR_BLOCK_SIZE] = {0};
- MemSet(zerobuf, 0, padding);
if (tar_write(f, zerobuf, padding) != padding)
return -1;
}
@@ -1222,7 +1221,7 @@ tar_existsfile(const char *pathname)
static bool
tar_finish(void)
{
- char zerobuf[1024];
+ char zerobuf[1024] = {0};
tar_clear_error();
@@ -1233,7 +1232,6 @@ tar_finish(void)
}
/* A tarfile always ends with two empty blocks */
- MemSet(zerobuf, 0, sizeof(zerobuf));
if (tar_data->compression_algorithm == PG_COMPRESSION_NONE)
{
errno = 0;
diff --git a/src/common/ip.c b/src/common/ip.c
index cd73d49679..267103efb9 100644
--- a/src/common/ip.c
+++ b/src/common/ip.c
@@ -165,14 +165,12 @@ static int
getaddrinfo_unix(const char *path, const struct addrinfo *hintsp,
struct addrinfo **result)
{
- struct addrinfo hints;
+ struct addrinfo hints = {0};
struct addrinfo *aip;
struct sockaddr_un *unp;
*result = NULL;
- MemSet(&hints, 0, sizeof(hints));
-
if (strlen(path) >= sizeof(unp->sun_path))
return EAI_FAIL;
diff --git a/src/port/snprintf.c b/src/port/snprintf.c
index abb1c59770..e646b0e642 100644
--- a/src/port/snprintf.c
+++ b/src/port/snprintf.c
@@ -756,12 +756,9 @@ find_arguments(const char *format, va_list args,
int longflag;
int fmtpos;
int i;
- int last_dollar;
- PrintfArgType argtypes[PG_NL_ARGMAX + 1];
-
/* Initialize to "no dollar arguments known" */
- last_dollar = 0;
- MemSet(argtypes, 0, sizeof(argtypes));
+ int last_dollar = 0;
+ PrintfArgType argtypes[PG_NL_ARGMAX + 1] = {0};
/*
* This loop must accept the same format strings as the one in dopr().
diff --git a/src/test/modules/test_predtest/test_predtest.c b/src/test/modules/test_predtest/test_predtest.c
index 3b19e0eadc..2ce88cb624 100644
--- a/src/test/modules/test_predtest/test_predtest.c
+++ b/src/test/modules/test_predtest/test_predtest.c
@@ -50,7 +50,7 @@ test_predtest(PG_FUNCTION_ARGS)
strong_refuted_by,
weak_refuted_by;
Datum values[8];
- bool nulls[8];
+ bool nulls[8] = {0};
int i;
/* We use SPI to parse, plan, and execute the test query */
@@ -204,7 +204,6 @@ test_predtest(PG_FUNCTION_ARGS)
"w_r_holds", BOOLOID, -1, 0);
tupdesc = BlessTupleDesc(tupdesc);
- MemSet(nulls, 0, sizeof(nulls));
values[0] = BoolGetDatum(strong_implied_by);
values[1] = BoolGetDatum(weak_implied_by);
values[2] = BoolGetDatum(strong_refuted_by);
diff --git a/src/test/regress/regress.c b/src/test/regress/regress.c
index ba3532a51e..b88d70b6fc 100644
--- a/src/test/regress/regress.c
+++ b/src/test/regress/regress.c
@@ -1110,7 +1110,7 @@ test_enc_conversion(PG_FUNCTION_ARGS)
int convertedbytes;
int dstlen;
Datum values[2];
- bool nulls[2];
+ bool nulls[2] = {0};
HeapTuple tuple;
if (src_encoding < 0)
@@ -1199,7 +1199,6 @@ test_enc_conversion(PG_FUNCTION_ARGS)
pfree(dst);
}
- MemSet(nulls, 0, sizeof(nulls));
values[0] = Int32GetDatum(convertedbytes);
values[1] = PointerGetDatum(retval);
tuple = heap_form_tuple(tupdesc, values, nulls);
--
2.36.1
On 2022-Jul-07, Peter Eisentraut wrote:
diff --git a/src/bin/pg_basebackup/pg_basebackup.c b/src/bin/pg_basebackup/pg_basebackup.c index 4445a86aee..79b23fa7d7 100644 --- a/src/bin/pg_basebackup/pg_basebackup.c +++ b/src/bin/pg_basebackup/pg_basebackup.c
@@ -1952,7 +1948,6 @@ BaseBackup(char *compression_algorithm, char *compression_detail,
else
starttli = latesttli;
PQclear(res);
- MemSet(xlogend, 0, sizeof(xlogend));if (verbose && includewal != NO_WAL)
pg_log_info("write-ahead log start point: %s on timeline %u",
You removed the MemSet here, but there's no corresponding
initialization.
diff --git a/src/port/snprintf.c b/src/port/snprintf.c index abb1c59770..e646b0e642 100644 --- a/src/port/snprintf.c +++ b/src/port/snprintf.c @@ -756,12 +756,9 @@ find_arguments(const char *format, va_list args, int longflag; int fmtpos; int i; - int last_dollar; - PrintfArgType argtypes[PG_NL_ARGMAX + 1]; - /* Initialize to "no dollar arguments known" */ - last_dollar = 0; - MemSet(argtypes, 0, sizeof(argtypes)); + int last_dollar = 0; + PrintfArgType argtypes[PG_NL_ARGMAX + 1] = {0};
pgindent will insert a blank line before the comment, which I personally
find quite ugly (because it splits the block of declarations).
--
Álvaro Herrera 48°01'N 7°57'E — https://www.EnterpriseDB.com/
"El Maquinismo fue proscrito so pena de cosquilleo hasta la muerte"
(Ijon Tichy en Viajes, Stanislaw Lem)
On 01.07.22 17:58, Ranier Vilela wrote:
Em qui., 30 de jun. de 2022 às 19:37, Peter Eisentraut
<peter.eisentraut@enterprisedb.com
<mailto:peter.eisentraut@enterprisedb.com>> escreveu:I have also committed a patch that gets rid of MemSet() calls where the
value is a constant not-0, because that just falls back to memset()
anyway.Peter there are some missing paths in this commit.
As I wrote in the commit message:
(There are a few MemSet() calls that I didn't change to maintain the
consistency with their surrounding code.)
Em qui., 7 de jul. de 2022 às 08:00, Peter Eisentraut <
peter.eisentraut@enterprisedb.com> escreveu:
On 18.05.22 15:52, Peter Eisentraut wrote:
On 18.05.22 01:18, Justin Pryzby wrote:
Take the first one as an example. It says:
GenericCosts costs;
MemSet(&costs, 0, sizeof(costs));You sent a patch to change it to sizeof(GenericCosts).
But it's not a pointer, so they are the same.
This instance can more easily be written as
costs = {0};
The attached patch replaces all MemSet() calls with struct
initialization where that is easily possible. (For example, some cases
have to worry about padding bits, so I left those.)
Sounds great.
#include <stdio.h>
#include <string.h>
int main(void) {
bool nulls[4] = {0};
int i;
memset(nulls, 0, sizeof(nulls));
for(i = 0; i < 4; i++)
{
nulls[i] = 0;
}
return 1;
}
main:
push rbp
mov rbp, rsp
sub rsp, 16
mov DWORD PTR [rbp-8], 0 // bool nulls[4] = {0}; lea
rax, [rbp-8]
mov edx, 4
mov esi, 0
mov rdi, rax
call memset
mov DWORD PTR [rbp-4], 0
jmp .L2
.L3:
mov eax, DWORD PTR [rbp-4]
cdqe
mov BYTE PTR [rbp-8+rax], 0
add DWORD PTR [rbp-4], 1
.L2:
cmp DWORD PTR [rbp-4], 3
jle .L3
mov eax, 1
leave
ret
Only one line using {0}.
+1
regards,
Ranier Vilela
Em qui., 7 de jul. de 2022 às 08:00, Peter Eisentraut <
peter.eisentraut@enterprisedb.com> escreveu:
diff --git a/src/backend/access/transam/twophase.c
b/src/backend/access/transam/twophase.c
index 41b31c5c6f..803d169f57 100644 --- a/src/backend/access/transam/twophase.c +++ b/src/backend/access/transam/twophase.c @@ -780,8 +780,8 @@ pg_prepared_xact(PG_FUNCTION_ARGS) { GlobalTransaction gxact = &status->array[status->currIdx++]; PGPROC *proc = &ProcGlobal->allProcs[gxact->pgprocno]; - Datum values[5]; - bool nulls[5]; + Datum values[5] = {0}; + bool nulls[5] = {0};
values variable no initialization or MemSet needed.
diff --git a/src/backend/access/transam/xlogfuncs.c
b/src/backend/access/transam/xlogfuncs.c
index 02bd919ff6..61e0f4a29c 100644
--- a/src/backend/access/transam/xlogfuncs.c
+++ b/src/backend/access/transam/xlogfuncs.c
@@ -106,8 +106,8 @@ pg_backup_stop(PG_FUNCTION_ARGS)
{
#define PG_STOP_BACKUP_V2_COLS 3
TupleDesc tupdesc;
- Datum values[PG_STOP_BACKUP_V2_COLS];
- bool nulls[PG_STOP_BACKUP_V2_COLS];
+ Datum values[PG_STOP_BACKUP_V2_COLS] = {0};
+ bool nulls[PG_STOP_BACKUP_V2_COLS] = {0};
Same, values variable no initialization or MemSet needed.
diff --git a/src/backend/catalog/aclchk.c b/src/backend/catalog/aclchk.c
index 5f1726c095..17ff617fba 100644
--- a/src/backend/catalog/aclchk.c
+++ b/src/backend/catalog/aclchk.c
@@ -1188,9 +1188,6 @@ SetDefaultACL(InternalDefaultACL *iacls)
Acl *old_acl;
Acl *new_acl;
HeapTuple newtuple;
- Datum values[Natts_pg_default_acl];
- bool nulls[Natts_pg_default_acl];
- bool replaces[Natts_pg_default_acl];
int noldmembers;
int nnewmembers;
Oid *oldmembers;
@@ -1341,13 +1338,11 @@ SetDefaultACL(InternalDefaultACL *iacls)
}
else
{
+ Datum values[Natts_pg_default_acl] = {0};
+ bool nulls[Natts_pg_default_acl] = {0};
replaces, can be reduced more one level.
line 1365:
else
{
+bool replaces[Natts_pg_default_acl] = {0};
defAclOid = ((Form_pg_default_acl) GETSTRUCT(tuple))->oid;
please, wait a minute, I will produce a new version of your patch, with
some changes for your review.
regards,
Ranier Vilela
Em qui., 7 de jul. de 2022 às 09:45, Ranier Vilela <ranier.vf@gmail.com>
escreveu:
Em qui., 7 de jul. de 2022 às 08:00, Peter Eisentraut <
peter.eisentraut@enterprisedb.com> escreveu:diff --git a/src/backend/access/transam/twophase.cb/src/backend/access/transam/twophase.c
index 41b31c5c6f..803d169f57 100644 --- a/src/backend/access/transam/twophase.c +++ b/src/backend/access/transam/twophase.c @@ -780,8 +780,8 @@ pg_prepared_xact(PG_FUNCTION_ARGS) { GlobalTransaction gxact = &status->array[status->currIdx++]; PGPROC *proc = &ProcGlobal->allProcs[gxact->pgprocno]; - Datum values[5]; - bool nulls[5]; + Datum values[5] = {0}; + bool nulls[5] = {0};values variable no initialization or MemSet needed.
diff --git a/src/backend/access/transam/xlogfuncs.c b/src/backend/access/transam/xlogfuncs.c index 02bd919ff6..61e0f4a29c 100644 --- a/src/backend/access/transam/xlogfuncs.c +++ b/src/backend/access/transam/xlogfuncs.c @@ -106,8 +106,8 @@ pg_backup_stop(PG_FUNCTION_ARGS) { #define PG_STOP_BACKUP_V2_COLS 3 TupleDesc tupdesc; - Datum values[PG_STOP_BACKUP_V2_COLS]; - bool nulls[PG_STOP_BACKUP_V2_COLS]; + Datum values[PG_STOP_BACKUP_V2_COLS] = {0}; + bool nulls[PG_STOP_BACKUP_V2_COLS] = {0};Same, values variable no initialization or MemSet needed.
diff --git a/src/backend/catalog/aclchk.c b/src/backend/catalog/aclchk.c index 5f1726c095..17ff617fba 100644 --- a/src/backend/catalog/aclchk.c +++ b/src/backend/catalog/aclchk.c @@ -1188,9 +1188,6 @@ SetDefaultACL(InternalDefaultACL *iacls) Acl *old_acl; Acl *new_acl; HeapTuple newtuple; - Datum values[Natts_pg_default_acl]; - bool nulls[Natts_pg_default_acl]; - bool replaces[Natts_pg_default_acl]; int noldmembers; int nnewmembers; Oid *oldmembers; @@ -1341,13 +1338,11 @@ SetDefaultACL(InternalDefaultACL *iacls) } else { + Datum values[Natts_pg_default_acl] = {0}; + bool nulls[Natts_pg_default_acl] = {0};replaces, can be reduced more one level.
line 1365:
else
{
+bool replaces[Natts_pg_default_acl] = {0};
defAclOid = ((Form_pg_default_acl) GETSTRUCT(tuple))->oid;please, wait a minute, I will produce a new version of your patch, with
some changes for your review.
Attached the v1 of your patch.
I think that all is safe to switch MemSet by {0}.
regards,
Ranier Vilela
Attachments:
v1-0001-WIP-Replace-MemSet-calls-with-struct-initialization.patchapplication/octet-stream; name=v1-0001-WIP-Replace-MemSet-calls-with-struct-initialization.patchDownload
diff --git a/contrib/amcheck/verify_heapam.c b/contrib/amcheck/verify_heapam.c
index e488f5e234..4cd4354278 100644
--- a/contrib/amcheck/verify_heapam.c
+++ b/contrib/amcheck/verify_heapam.c
@@ -554,17 +554,15 @@ report_corruption_internal(Tuplestorestate *tupstore, TupleDesc tupdesc,
BlockNumber blkno, OffsetNumber offnum,
AttrNumber attnum, char *msg)
{
- Datum values[HEAPCHECK_RELATION_COLS];
- bool nulls[HEAPCHECK_RELATION_COLS];
+ Datum values[HEAPCHECK_RELATION_COLS] = {0};
+ bool nulls[HEAPCHECK_RELATION_COLS] = {0};
HeapTuple tuple;
- MemSet(values, 0, sizeof(values));
- MemSet(nulls, 0, sizeof(nulls));
values[0] = Int64GetDatum(blkno);
values[1] = Int32GetDatum(offnum);
values[2] = Int32GetDatum(attnum);
- nulls[2] = (attnum < 0);
values[3] = CStringGetTextDatum(msg);
+ nulls[2] = (attnum < 0);
/*
* In principle, there is nothing to prevent a scan over a large, highly
diff --git a/contrib/bloom/blcost.c b/contrib/bloom/blcost.c
index d42e4e9628..d4b1c76303 100644
--- a/contrib/bloom/blcost.c
+++ b/contrib/bloom/blcost.c
@@ -26,9 +26,7 @@ blcostestimate(PlannerInfo *root, IndexPath *path, double loop_count,
double *indexPages)
{
IndexOptInfo *index = path->indexinfo;
- GenericCosts costs;
-
- MemSet(&costs, 0, sizeof(costs));
+ GenericCosts costs = {0};
/* We have to visit all index tuples anyway */
costs.numIndexTuples = index->tuples;
diff --git a/contrib/pageinspect/brinfuncs.c b/contrib/pageinspect/brinfuncs.c
index 879276e6de..f4c959ecab 100644
--- a/contrib/pageinspect/brinfuncs.c
+++ b/contrib/pageinspect/brinfuncs.c
@@ -202,7 +202,7 @@ brin_page_items(PG_FUNCTION_ARGS)
for (;;)
{
Datum values[7];
- bool nulls[7];
+ bool nulls[7] = {0};
/*
* This loop is called once for every attribute of every tuple in the
@@ -230,8 +230,6 @@ brin_page_items(PG_FUNCTION_ARGS)
else
attno++;
- MemSet(nulls, 0, sizeof(nulls));
-
if (unusedItem)
{
values[0] = UInt16GetDatum(offset);
@@ -334,7 +332,7 @@ brin_metapage_info(PG_FUNCTION_ARGS)
BrinMetaPageData *meta;
TupleDesc tupdesc;
Datum values[4];
- bool nulls[4];
+ bool nulls[4] = {0};
HeapTuple htup;
if (!superuser())
@@ -354,7 +352,6 @@ brin_metapage_info(PG_FUNCTION_ARGS)
/* Extract values from the metapage */
meta = (BrinMetaPageData *) PageGetContents(page);
- MemSet(nulls, 0, sizeof(nulls));
values[0] = CStringGetTextDatum(psprintf("0x%08X", meta->brinMagic));
values[1] = Int32GetDatum(meta->brinVersion);
values[2] = Int32GetDatum(meta->pagesPerRange);
diff --git a/contrib/pageinspect/hashfuncs.c b/contrib/pageinspect/hashfuncs.c
index 5287dbe1a3..81815392d7 100644
--- a/contrib/pageinspect/hashfuncs.c
+++ b/contrib/pageinspect/hashfuncs.c
@@ -238,7 +238,7 @@ hash_page_stats(PG_FUNCTION_ARGS)
Page page;
int j;
Datum values[9];
- bool nulls[9];
+ bool nulls[9] = {0};
HashPageStat stat;
HeapTuple tuple;
TupleDesc tupleDesc;
@@ -261,8 +261,6 @@ hash_page_stats(PG_FUNCTION_ARGS)
elog(ERROR, "return type must be a row type");
tupleDesc = BlessTupleDesc(tupleDesc);
- MemSet(nulls, 0, sizeof(nulls));
-
j = 0;
values[j++] = Int32GetDatum(stat.live_items);
values[j++] = Int32GetDatum(stat.dead_items);
@@ -303,7 +301,7 @@ hash_page_items(PG_FUNCTION_ARGS)
Page page;
Datum result;
Datum values[3];
- bool nulls[3];
+ bool nulls[3] = {0};
uint32 hashkey;
HeapTuple tuple;
FuncCallContext *fctx;
@@ -361,8 +359,6 @@ hash_page_items(PG_FUNCTION_ARGS)
itup = (IndexTuple) PageGetItem(uargs->page, id);
- MemSet(nulls, 0, sizeof(nulls));
-
j = 0;
values[j++] = Int32GetDatum((int32) uargs->offset);
values[j++] = PointerGetDatum(&itup->t_tid);
@@ -409,7 +405,7 @@ hash_bitmap_info(PG_FUNCTION_ARGS)
int i,
j;
Datum values[3];
- bool nulls[3];
+ bool nulls[3] = {0};
uint32 *freep;
if (!superuser())
@@ -495,8 +491,6 @@ hash_bitmap_info(PG_FUNCTION_ARGS)
elog(ERROR, "return type must be a row type");
tupleDesc = BlessTupleDesc(tupleDesc);
- MemSet(nulls, 0, sizeof(nulls));
-
j = 0;
values[j++] = Int64GetDatum((int64) bitmapblkno);
values[j++] = Int32GetDatum(bitmapbit);
@@ -526,7 +520,7 @@ hash_metapage_info(PG_FUNCTION_ARGS)
int i,
j;
Datum values[16];
- bool nulls[16];
+ bool nulls[16] = {0};
Datum spares[HASH_MAX_SPLITPOINTS];
Datum mapp[HASH_MAX_BITMAPS];
@@ -544,8 +538,6 @@ hash_metapage_info(PG_FUNCTION_ARGS)
metad = HashPageGetMeta(page);
- MemSet(nulls, 0, sizeof(nulls));
-
j = 0;
values[j++] = Int64GetDatum((int64) metad->hashm_magic);
values[j++] = Int64GetDatum((int64) metad->hashm_version);
diff --git a/contrib/pageinspect/heapfuncs.c b/contrib/pageinspect/heapfuncs.c
index a654234c6b..952f5ed57e 100644
--- a/contrib/pageinspect/heapfuncs.c
+++ b/contrib/pageinspect/heapfuncs.c
@@ -181,13 +181,11 @@ heap_page_items(PG_FUNCTION_ARGS)
Datum result;
ItemId id;
Datum values[14];
- bool nulls[14];
+ bool nulls[14] = {0};
uint16 lp_offset;
uint16 lp_flags;
uint16 lp_len;
- memset(nulls, 0, sizeof(nulls));
-
/* Extract information from the line pointer */
id = PageGetItemId(page, inter_call_data->offset);
@@ -507,8 +505,8 @@ Datum
heap_tuple_infomask_flags(PG_FUNCTION_ARGS)
{
#define HEAP_TUPLE_INFOMASK_COLS 2
- Datum values[HEAP_TUPLE_INFOMASK_COLS];
- bool nulls[HEAP_TUPLE_INFOMASK_COLS];
+ Datum values[HEAP_TUPLE_INFOMASK_COLS] = {0};
+ bool nulls[HEAP_TUPLE_INFOMASK_COLS] = {0};
uint16 t_infomask = PG_GETARG_INT16(0);
uint16 t_infomask2 = PG_GETARG_INT16(1);
int cnt = 0;
@@ -530,10 +528,6 @@ heap_tuple_infomask_flags(PG_FUNCTION_ARGS)
bitcnt = pg_popcount((const char *) &t_infomask, sizeof(uint16)) +
pg_popcount((const char *) &t_infomask2, sizeof(uint16));
- /* Initialize values and NULL flags arrays */
- MemSet(values, 0, sizeof(values));
- MemSet(nulls, 0, sizeof(nulls));
-
/* If no flags, return a set of empty arrays */
if (bitcnt <= 0)
{
diff --git a/contrib/pg_prewarm/autoprewarm.c b/contrib/pg_prewarm/autoprewarm.c
index 13eee4a137..ee20e9b085 100644
--- a/contrib/pg_prewarm/autoprewarm.c
+++ b/contrib/pg_prewarm/autoprewarm.c
@@ -814,12 +814,11 @@ apw_detach_shmem(int code, Datum arg)
static void
apw_start_leader_worker(void)
{
- BackgroundWorker worker;
+ BackgroundWorker worker = {0};
BackgroundWorkerHandle *handle;
BgwHandleStatus status;
pid_t pid;
- MemSet(&worker, 0, sizeof(BackgroundWorker));
worker.bgw_flags = BGWORKER_SHMEM_ACCESS;
worker.bgw_start_time = BgWorkerStart_ConsistentState;
strcpy(worker.bgw_library_name, "pg_prewarm");
@@ -856,10 +855,9 @@ apw_start_leader_worker(void)
static void
apw_start_database_worker(void)
{
- BackgroundWorker worker;
+ BackgroundWorker worker = {0};
BackgroundWorkerHandle *handle;
- MemSet(&worker, 0, sizeof(BackgroundWorker));
worker.bgw_flags =
BGWORKER_SHMEM_ACCESS | BGWORKER_BACKEND_DATABASE_CONNECTION;
worker.bgw_start_time = BgWorkerStart_ConsistentState;
diff --git a/contrib/pg_stat_statements/pg_stat_statements.c b/contrib/pg_stat_statements/pg_stat_statements.c
index 4acfddcdb8..b4d4231dc6 100644
--- a/contrib/pg_stat_statements/pg_stat_statements.c
+++ b/contrib/pg_stat_statements/pg_stat_statements.c
@@ -1854,8 +1854,8 @@ pg_stat_statements_info(PG_FUNCTION_ARGS)
{
pgssGlobalStats stats;
TupleDesc tupdesc;
- Datum values[PG_STAT_STATEMENTS_INFO_COLS];
- bool nulls[PG_STAT_STATEMENTS_INFO_COLS];
+ Datum values[PG_STAT_STATEMENTS_INFO_COLS] = {0};
+ bool nulls[PG_STAT_STATEMENTS_INFO_COLS] = {0};
if (!pgss || !pgss_hash)
ereport(ERROR,
@@ -1866,9 +1866,6 @@ pg_stat_statements_info(PG_FUNCTION_ARGS)
if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE)
elog(ERROR, "return type must be a row type");
- MemSet(values, 0, sizeof(values));
- MemSet(nulls, 0, sizeof(nulls));
-
/* Read global statistics for pg_stat_statements */
{
volatile pgssSharedState *s = (volatile pgssSharedState *) pgss;
diff --git a/contrib/pg_trgm/trgm_regexp.c b/contrib/pg_trgm/trgm_regexp.c
index 58d32ba946..a155d4c13d 100644
--- a/contrib/pg_trgm/trgm_regexp.c
+++ b/contrib/pg_trgm/trgm_regexp.c
@@ -905,7 +905,7 @@ static void
transformGraph(TrgmNFA *trgmNFA)
{
HASHCTL hashCtl;
- TrgmStateKey initkey;
+ TrgmStateKey initkey = {0};
TrgmState *initstate;
ListCell *lc;
@@ -926,7 +926,6 @@ transformGraph(TrgmNFA *trgmNFA)
trgmNFA->nstates = 0;
/* Create initial state: ambiguous prefix, NFA's initial state */
- MemSet(&initkey, 0, sizeof(initkey));
initkey.prefix.colors[0] = COLOR_UNKNOWN;
initkey.prefix.colors[1] = COLOR_UNKNOWN;
initkey.nstate = pg_reg_getinitialstate(trgmNFA->regex);
@@ -1014,22 +1013,19 @@ processState(TrgmNFA *trgmNFA, TrgmState *state)
*
* Note that we don't generate any actual arcs here. addArcs will do that
* later, after we have identified all the enter keys for this state.
+ *
+ * Ensure any pad bytes in destKey are zero, since it may get used as a
+ * hashtable key by getState.
*/
static void
addKey(TrgmNFA *trgmNFA, TrgmState *state, TrgmStateKey *key)
{
regex_arc_t *arcs;
- TrgmStateKey destKey;
+ TrgmStateKey destKey = {0};
ListCell *cell;
int i,
arcsCount;
- /*
- * Ensure any pad bytes in destKey are zero, since it may get used as a
- * hashtable key by getState.
- */
- MemSet(&destKey, 0, sizeof(destKey));
-
/*
* Compare key to each existing enter key of the state to check for
* redundancy. We can drop either old key(s) or the new key if we find
@@ -1195,22 +1191,19 @@ addKeyToQueue(TrgmNFA *trgmNFA, TrgmStateKey *key)
/*
* Add outgoing arcs from given state, whose enter keys are all now known.
+ *
+ * Ensure any pad bytes in destKey are zero, since it may get used as a
+ * hashtable key by getState.
*/
static void
addArcs(TrgmNFA *trgmNFA, TrgmState *state)
{
- TrgmStateKey destKey;
+ TrgmStateKey destKey = {0};
ListCell *cell;
regex_arc_t *arcs;
int arcsCount,
i;
- /*
- * Ensure any pad bytes in destKey are zero, since it may get used as a
- * hashtable key by getState.
- */
- MemSet(&destKey, 0, sizeof(destKey));
-
/*
* Iterate over enter keys associated with this expanded-graph state. This
* includes both the state's own stateKey, and any enter keys we added to
diff --git a/contrib/pg_visibility/pg_visibility.c b/contrib/pg_visibility/pg_visibility.c
index 4e2e9ea9bb..a95f73ec79 100644
--- a/contrib/pg_visibility/pg_visibility.c
+++ b/contrib/pg_visibility/pg_visibility.c
@@ -75,7 +75,7 @@ pg_visibility_map(PG_FUNCTION_ARGS)
Buffer vmbuffer = InvalidBuffer;
TupleDesc tupdesc;
Datum values[2];
- bool nulls[2];
+ bool nulls[2] = {0};
rel = relation_open(relid, AccessShareLock);
@@ -88,7 +88,6 @@ pg_visibility_map(PG_FUNCTION_ARGS)
errmsg("invalid block number")));
tupdesc = pg_visibility_tupdesc(false, false);
- MemSet(nulls, 0, sizeof(nulls));
mapbits = (int32) visibilitymap_get_status(rel, blkno, &vmbuffer);
if (vmbuffer != InvalidBuffer)
@@ -117,7 +116,7 @@ pg_visibility(PG_FUNCTION_ARGS)
Page page;
TupleDesc tupdesc;
Datum values[3];
- bool nulls[3];
+ bool nulls[3] = {0};
rel = relation_open(relid, AccessShareLock);
@@ -130,7 +129,6 @@ pg_visibility(PG_FUNCTION_ARGS)
errmsg("invalid block number")));
tupdesc = pg_visibility_tupdesc(false, true);
- MemSet(nulls, 0, sizeof(nulls));
mapbits = (int32) visibilitymap_get_status(rel, blkno, &vmbuffer);
if (vmbuffer != InvalidBuffer)
@@ -188,10 +186,9 @@ pg_visibility_map_rel(PG_FUNCTION_ARGS)
if (info->next < info->count)
{
Datum values[3];
- bool nulls[3];
+ bool nulls[3] = {0};
HeapTuple tuple;
- MemSet(nulls, 0, sizeof(nulls));
values[0] = Int64GetDatum(info->next);
values[1] = BoolGetDatum((info->bits[info->next] & (1 << 0)) != 0);
values[2] = BoolGetDatum((info->bits[info->next] & (1 << 1)) != 0);
@@ -233,10 +230,9 @@ pg_visibility_rel(PG_FUNCTION_ARGS)
if (info->next < info->count)
{
Datum values[4];
- bool nulls[4];
+ bool nulls[4] = {0};
HeapTuple tuple;
- MemSet(nulls, 0, sizeof(nulls));
values[0] = Int64GetDatum(info->next);
values[1] = BoolGetDatum((info->bits[info->next] & (1 << 0)) != 0);
values[2] = BoolGetDatum((info->bits[info->next] & (1 << 1)) != 0);
@@ -266,7 +262,7 @@ pg_visibility_map_summary(PG_FUNCTION_ARGS)
int64 all_frozen = 0;
TupleDesc tupdesc;
Datum values[2];
- bool nulls[2];
+ bool nulls[2] = {0};
rel = relation_open(relid, AccessShareLock);
@@ -300,7 +296,6 @@ pg_visibility_map_summary(PG_FUNCTION_ARGS)
TupleDescInitEntry(tupdesc, (AttrNumber) 2, "all_frozen", INT8OID, -1, 0);
tupdesc = BlessTupleDesc(tupdesc);
- MemSet(nulls, 0, sizeof(nulls));
values[0] = Int64GetDatum(all_visible);
values[1] = Int64GetDatum(all_frozen);
diff --git a/contrib/pg_walinspect/pg_walinspect.c b/contrib/pg_walinspect/pg_walinspect.c
index a082dfb331..9081787634 100644
--- a/contrib/pg_walinspect/pg_walinspect.c
+++ b/contrib/pg_walinspect/pg_walinspect.c
@@ -229,8 +229,8 @@ pg_get_wal_record_info(PG_FUNCTION_ARGS)
{
#define PG_GET_WAL_RECORD_INFO_COLS 11
Datum result;
- Datum values[PG_GET_WAL_RECORD_INFO_COLS];
- bool nulls[PG_GET_WAL_RECORD_INFO_COLS];
+ Datum values[PG_GET_WAL_RECORD_INFO_COLS] = {0};
+ bool nulls[PG_GET_WAL_RECORD_INFO_COLS] = {0};
XLogRecPtr lsn;
XLogRecPtr curr_lsn;
XLogRecPtr first_record;
@@ -266,9 +266,6 @@ pg_get_wal_record_info(PG_FUNCTION_ARGS)
errmsg("could not read WAL at %X/%X",
LSN_FORMAT_ARGS(first_record))));
- MemSet(values, 0, sizeof(values));
- MemSet(nulls, 0, sizeof(nulls));
-
GetWALRecordInfo(xlogreader, first_record, values, nulls,
PG_GET_WAL_RECORD_INFO_COLS);
@@ -334,8 +331,8 @@ GetWALRecordsInfo(FunctionCallInfo fcinfo, XLogRecPtr start_lsn,
XLogRecPtr first_record;
XLogReaderState *xlogreader;
ReturnSetInfo *rsinfo = (ReturnSetInfo *) fcinfo->resultinfo;
- Datum values[PG_GET_WAL_RECORDS_INFO_COLS];
- bool nulls[PG_GET_WAL_RECORDS_INFO_COLS];
+ Datum values[PG_GET_WAL_RECORDS_INFO_COLS] = {0};
+ bool nulls[PG_GET_WAL_RECORDS_INFO_COLS] = {0};
SetSingleFuncCall(fcinfo, 0);
@@ -343,9 +340,6 @@ GetWALRecordsInfo(FunctionCallInfo fcinfo, XLogRecPtr start_lsn,
Assert(xlogreader);
- MemSet(values, 0, sizeof(values));
- MemSet(nulls, 0, sizeof(nulls));
-
while (ReadNextXLogRecord(xlogreader, first_record) &&
xlogreader->EndRecPtr <= end_lsn)
{
@@ -556,17 +550,15 @@ GetWalStats(FunctionCallInfo fcinfo, XLogRecPtr start_lsn,
#define PG_GET_WAL_STATS_COLS 9
XLogRecPtr first_record;
XLogReaderState *xlogreader;
- XLogStats stats;
+ XLogStats stats = {0};
ReturnSetInfo *rsinfo = (ReturnSetInfo *) fcinfo->resultinfo;
- Datum values[PG_GET_WAL_STATS_COLS];
- bool nulls[PG_GET_WAL_STATS_COLS];
+ Datum values[PG_GET_WAL_STATS_COLS] = {0};
+ bool nulls[PG_GET_WAL_STATS_COLS] = {0};
SetSingleFuncCall(fcinfo, 0);
xlogreader = InitXLogReaderState(start_lsn, &first_record);
- MemSet(&stats, 0, sizeof(stats));
-
while (ReadNextXLogRecord(xlogreader, first_record) &&
xlogreader->EndRecPtr <= end_lsn)
{
@@ -578,9 +570,6 @@ GetWalStats(FunctionCallInfo fcinfo, XLogRecPtr start_lsn,
pfree(xlogreader->private_data);
XLogReaderFree(xlogreader);
- MemSet(values, 0, sizeof(values));
- MemSet(nulls, 0, sizeof(nulls));
-
GetXLogSummaryStats(&stats, rsinfo, values, nulls,
PG_GET_WAL_STATS_COLS,
stats_per_record);
diff --git a/contrib/pgstattuple/pgstatindex.c b/contrib/pgstattuple/pgstatindex.c
index e1048e47ff..d69ac1c93d 100644
--- a/contrib/pgstattuple/pgstatindex.c
+++ b/contrib/pgstattuple/pgstatindex.c
@@ -575,7 +575,7 @@ pgstathashindex(PG_FUNCTION_ARGS)
HeapTuple tuple;
TupleDesc tupleDesc;
Datum values[8];
- bool nulls[8];
+ bool nulls[8] = {0};
Buffer metabuf;
HashMetaPage metap;
float8 free_percent;
@@ -697,7 +697,6 @@ pgstathashindex(PG_FUNCTION_ARGS)
/*
* Build and return the tuple
*/
- MemSet(nulls, 0, sizeof(nulls));
values[0] = Int32GetDatum(stats.version);
values[1] = Int64GetDatum((int64) stats.bucket_pages);
values[2] = Int64GetDatum((int64) stats.overflow_pages);
diff --git a/contrib/postgres_fdw/connection.c b/contrib/postgres_fdw/connection.c
index cffb6f8310..939d114f02 100644
--- a/contrib/postgres_fdw/connection.c
+++ b/contrib/postgres_fdw/connection.c
@@ -1678,8 +1678,8 @@ postgres_fdw_get_connections(PG_FUNCTION_ARGS)
while ((entry = (ConnCacheEntry *) hash_seq_search(&scan)))
{
ForeignServer *server;
- Datum values[POSTGRES_FDW_GET_CONNECTIONS_COLS];
- bool nulls[POSTGRES_FDW_GET_CONNECTIONS_COLS];
+ Datum values[POSTGRES_FDW_GET_CONNECTIONS_COLS] = {0};
+ bool nulls[POSTGRES_FDW_GET_CONNECTIONS_COLS] = {0};
/* We only look for open remote connections */
if (!entry->conn)
@@ -1687,9 +1687,6 @@ postgres_fdw_get_connections(PG_FUNCTION_ARGS)
server = GetForeignServerExtended(entry->serverid, FSV_MISSING_OK);
- MemSet(values, 0, sizeof(values));
- MemSet(nulls, 0, sizeof(nulls));
-
/*
* The foreign server may have been dropped in current explicit
* transaction. It is not possible to drop the server from another
diff --git a/contrib/postgres_fdw/postgres_fdw.c b/contrib/postgres_fdw/postgres_fdw.c
index 955a428e3d..cfac539008 100644
--- a/contrib/postgres_fdw/postgres_fdw.c
+++ b/contrib/postgres_fdw/postgres_fdw.c
@@ -3307,7 +3307,7 @@ estimate_path_cost_size(PlannerInfo *root,
{
RelOptInfo *outerrel = fpinfo->outerrel;
PgFdwRelationInfo *ofpinfo;
- AggClauseCosts aggcosts;
+ AggClauseCosts aggcosts = {0};
double input_rows;
int numGroupCols;
double numGroups = 1;
@@ -3331,7 +3331,6 @@ estimate_path_cost_size(PlannerInfo *root,
input_rows = ofpinfo->rows;
/* Collect statistics about aggregates for estimating costs. */
- MemSet(&aggcosts, 0, sizeof(AggClauseCosts));
if (root->parse->hasAggs)
{
get_agg_clause_costs(root, AGGSPLIT_SIMPLE, &aggcosts);
diff --git a/contrib/tablefunc/tablefunc.c b/contrib/tablefunc/tablefunc.c
index e308228bde..6452111e19 100644
--- a/contrib/tablefunc/tablefunc.c
+++ b/contrib/tablefunc/tablefunc.c
@@ -127,9 +127,8 @@ typedef struct crosstab_cat_desc
#define crosstab_HashTableLookup(HASHTAB, CATNAME, CATDESC) \
do { \
- crosstab_HashEnt *hentry; char key[MAX_CATNAME_LEN]; \
+ crosstab_HashEnt *hentry; char key[MAX_CATNAME_LEN] = {0}; \
\
- MemSet(key, 0, MAX_CATNAME_LEN); \
snprintf(key, MAX_CATNAME_LEN - 1, "%s", CATNAME); \
hentry = (crosstab_HashEnt*) hash_search(HASHTAB, \
key, HASH_FIND, NULL); \
@@ -141,9 +140,8 @@ do { \
#define crosstab_HashTableInsert(HASHTAB, CATDESC) \
do { \
- crosstab_HashEnt *hentry; bool found; char key[MAX_CATNAME_LEN]; \
+ crosstab_HashEnt *hentry; bool found; char key[MAX_CATNAME_LEN] = {0}; \
\
- MemSet(key, 0, MAX_CATNAME_LEN); \
snprintf(key, MAX_CATNAME_LEN - 1, "%s", CATDESC->catname); \
hentry = (crosstab_HashEnt*) hash_search(HASHTAB, \
key, HASH_ENTER, &found); \
diff --git a/src/backend/access/nbtree/nbtxlog.c b/src/backend/access/nbtree/nbtxlog.c
index ad489e33b3..14fe2d76c4 100644
--- a/src/backend/access/nbtree/nbtxlog.c
+++ b/src/backend/access/nbtree/nbtxlog.c
@@ -717,7 +717,7 @@ btree_xlog_mark_page_halfdead(uint8 info, XLogReaderState *record)
Buffer buffer;
Page page;
BTPageOpaque pageop;
- IndexTupleData trunctuple;
+ IndexTupleData trunctuple = {0};
/*
* In normal operation, we would lock all the pages this WAL record
@@ -780,7 +780,6 @@ btree_xlog_mark_page_halfdead(uint8 info, XLogReaderState *record)
* Construct a dummy high key item that points to top parent page (value
* is InvalidBlockNumber when the top parent page is the leaf page itself)
*/
- MemSet(&trunctuple, 0, sizeof(IndexTupleData));
trunctuple.t_info = sizeof(IndexTupleData);
BTreeTupleSetTopParent(&trunctuple, xlrec->topparent);
@@ -898,7 +897,7 @@ btree_xlog_unlink_page(uint8 info, XLogReaderState *record)
* we'll delete in the subtree undergoing deletion.
*/
Buffer leafbuf;
- IndexTupleData trunctuple;
+ IndexTupleData trunctuple = {0};
Assert(!isleaf);
@@ -915,7 +914,6 @@ btree_xlog_unlink_page(uint8 info, XLogReaderState *record)
pageop->btpo_cycleid = 0;
/* Add a dummy hikey item */
- MemSet(&trunctuple, 0, sizeof(IndexTupleData));
trunctuple.t_info = sizeof(IndexTupleData);
BTreeTupleSetTopParent(&trunctuple, xlrec->leaftopparent);
diff --git a/src/backend/access/transam/twophase.c b/src/backend/access/transam/twophase.c
index 41b31c5c6f..dd330ce260 100644
--- a/src/backend/access/transam/twophase.c
+++ b/src/backend/access/transam/twophase.c
@@ -781,7 +781,7 @@ pg_prepared_xact(PG_FUNCTION_ARGS)
GlobalTransaction gxact = &status->array[status->currIdx++];
PGPROC *proc = &ProcGlobal->allProcs[gxact->pgprocno];
Datum values[5];
- bool nulls[5];
+ bool nulls[5] = {0};
HeapTuple tuple;
Datum result;
@@ -791,9 +791,6 @@ pg_prepared_xact(PG_FUNCTION_ARGS)
/*
* Form tuple with appropriate data.
*/
- MemSet(values, 0, sizeof(values));
- MemSet(nulls, 0, sizeof(nulls));
-
values[0] = TransactionIdGetDatum(proc->xid);
values[1] = CStringGetTextDatum(gxact->gid);
values[2] = TimestampTzGetDatum(gxact->prepared_at);
diff --git a/src/backend/access/transam/xlogfuncs.c b/src/backend/access/transam/xlogfuncs.c
index 02bd919ff6..ed79e3d9a3 100644
--- a/src/backend/access/transam/xlogfuncs.c
+++ b/src/backend/access/transam/xlogfuncs.c
@@ -107,7 +107,7 @@ pg_backup_stop(PG_FUNCTION_ARGS)
#define PG_STOP_BACKUP_V2_COLS 3
TupleDesc tupdesc;
Datum values[PG_STOP_BACKUP_V2_COLS];
- bool nulls[PG_STOP_BACKUP_V2_COLS];
+ bool nulls[PG_STOP_BACKUP_V2_COLS] = {0};
bool waitforarchive = PG_GETARG_BOOL(0);
XLogRecPtr stoppoint;
@@ -117,9 +117,6 @@ pg_backup_stop(PG_FUNCTION_ARGS)
if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE)
elog(ERROR, "return type must be a row type");
- MemSet(values, 0, sizeof(values));
- MemSet(nulls, 0, sizeof(nulls));
-
if (status != SESSION_BACKUP_RUNNING)
ereport(ERROR,
(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
diff --git a/src/backend/catalog/aclchk.c b/src/backend/catalog/aclchk.c
index 5f1726c095..0bd4557050 100644
--- a/src/backend/catalog/aclchk.c
+++ b/src/backend/catalog/aclchk.c
@@ -1188,9 +1188,6 @@ SetDefaultACL(InternalDefaultACL *iacls)
Acl *old_acl;
Acl *new_acl;
HeapTuple newtuple;
- Datum values[Natts_pg_default_acl];
- bool nulls[Natts_pg_default_acl];
- bool replaces[Natts_pg_default_acl];
int noldmembers;
int nnewmembers;
Oid *oldmembers;
@@ -1341,13 +1338,10 @@ SetDefaultACL(InternalDefaultACL *iacls)
}
else
{
+ Datum values[Natts_pg_default_acl] = {0};
+ bool nulls[Natts_pg_default_acl] = {0};
Oid defAclOid;
- /* Prepare to insert or update pg_default_acl entry */
- MemSet(values, 0, sizeof(values));
- MemSet(nulls, false, sizeof(nulls));
- MemSet(replaces, false, sizeof(replaces));
-
if (isNew)
{
/* insert new entry */
@@ -1364,6 +1358,8 @@ SetDefaultACL(InternalDefaultACL *iacls)
}
else
{
+ bool replaces[Natts_pg_default_acl] = {0};
+
defAclOid = ((Form_pg_default_acl) GETSTRUCT(tuple))->oid;
/* update existing entry */
@@ -1662,9 +1658,8 @@ ExecGrant_Attribute(InternalGrant *istmt, Oid relOid, const char *relname,
AclMode avail_goptions;
bool need_update;
HeapTuple newtuple;
- Datum values[Natts_pg_attribute];
- bool nulls[Natts_pg_attribute];
- bool replaces[Natts_pg_attribute];
+ Datum values[Natts_pg_attribute] = {0};
+ bool nulls[Natts_pg_attribute] = {0};
int noldmembers;
int nnewmembers;
Oid *oldmembers;
@@ -1745,9 +1740,6 @@ ExecGrant_Attribute(InternalGrant *istmt, Oid relOid, const char *relname,
nnewmembers = aclmembers(new_acl, &newmembers);
/* finished building new ACL value, now insert it */
- MemSet(values, 0, sizeof(values));
- MemSet(nulls, false, sizeof(nulls));
- MemSet(replaces, false, sizeof(replaces));
/*
* If the updated ACL is empty, we can set attacl to null, and maybe even
@@ -1766,10 +1758,12 @@ ExecGrant_Attribute(InternalGrant *istmt, Oid relOid, const char *relname,
nulls[Anum_pg_attribute_attacl - 1] = true;
need_update = !isNull;
}
- replaces[Anum_pg_attribute_attacl - 1] = true;
if (need_update)
{
+ bool replaces[Natts_pg_attribute] = {0};
+
+ replaces[Anum_pg_attribute_attacl - 1] = true;
newtuple = heap_modify_tuple(attr_tuple, RelationGetDescr(attRelation),
values, nulls, replaces);
@@ -1975,9 +1969,9 @@ ExecGrant_Relation(InternalGrant *istmt)
Acl *new_acl;
Oid grantorId;
HeapTuple newtuple;
- Datum values[Natts_pg_class];
- bool nulls[Natts_pg_class];
- bool replaces[Natts_pg_class];
+ Datum values[Natts_pg_class] = {0};
+ bool nulls[Natts_pg_class] = {0};
+ bool replaces[Natts_pg_class] = {0};
int nnewmembers;
Oid *newmembers;
ObjectType objtype;
@@ -2027,10 +2021,6 @@ ExecGrant_Relation(InternalGrant *istmt)
nnewmembers = aclmembers(new_acl, &newmembers);
/* finished building new ACL value, now insert it */
- MemSet(values, 0, sizeof(values));
- MemSet(nulls, false, sizeof(nulls));
- MemSet(replaces, false, sizeof(replaces));
-
replaces[Anum_pg_class_relacl - 1] = true;
values[Anum_pg_class_relacl - 1] = PointerGetDatum(new_acl);
@@ -2129,6 +2119,9 @@ ExecGrant_Relation(InternalGrant *istmt)
static void
ExecGrant_Database(InternalGrant *istmt)
{
+ Datum values[Natts_pg_database] = {0};
+ bool nulls[Natts_pg_database] = {0};
+ bool replaces[Natts_pg_database] = {0};
Relation relation;
ListCell *cell;
@@ -2150,9 +2143,6 @@ ExecGrant_Database(InternalGrant *istmt)
Oid grantorId;
Oid ownerId;
HeapTuple newtuple;
- Datum values[Natts_pg_database];
- bool nulls[Natts_pg_database];
- bool replaces[Natts_pg_database];
int noldmembers;
int nnewmembers;
Oid *oldmembers;
@@ -2217,10 +2207,6 @@ ExecGrant_Database(InternalGrant *istmt)
nnewmembers = aclmembers(new_acl, &newmembers);
/* finished building new ACL value, now insert it */
- MemSet(values, 0, sizeof(values));
- MemSet(nulls, false, sizeof(nulls));
- MemSet(replaces, false, sizeof(replaces));
-
replaces[Anum_pg_database_datacl - 1] = true;
values[Anum_pg_database_datacl - 1] = PointerGetDatum(new_acl);
@@ -2249,6 +2235,9 @@ ExecGrant_Database(InternalGrant *istmt)
static void
ExecGrant_Fdw(InternalGrant *istmt)
{
+ Datum values[Natts_pg_foreign_data_wrapper] = {0};
+ bool nulls[Natts_pg_foreign_data_wrapper] = {0};
+ bool replaces[Natts_pg_foreign_data_wrapper] = {0};
Relation relation;
ListCell *cell;
@@ -2271,9 +2260,6 @@ ExecGrant_Fdw(InternalGrant *istmt)
Oid ownerId;
HeapTuple tuple;
HeapTuple newtuple;
- Datum values[Natts_pg_foreign_data_wrapper];
- bool nulls[Natts_pg_foreign_data_wrapper];
- bool replaces[Natts_pg_foreign_data_wrapper];
int noldmembers;
int nnewmembers;
Oid *oldmembers;
@@ -2339,10 +2325,6 @@ ExecGrant_Fdw(InternalGrant *istmt)
nnewmembers = aclmembers(new_acl, &newmembers);
/* finished building new ACL value, now insert it */
- MemSet(values, 0, sizeof(values));
- MemSet(nulls, false, sizeof(nulls));
- MemSet(replaces, false, sizeof(replaces));
-
replaces[Anum_pg_foreign_data_wrapper_fdwacl - 1] = true;
values[Anum_pg_foreign_data_wrapper_fdwacl - 1] = PointerGetDatum(new_acl);
@@ -2376,6 +2358,9 @@ ExecGrant_Fdw(InternalGrant *istmt)
static void
ExecGrant_ForeignServer(InternalGrant *istmt)
{
+ Datum values[Natts_pg_foreign_server] = {0};
+ bool nulls[Natts_pg_foreign_server] = {0};
+ bool replaces[Natts_pg_foreign_server] = {0};
Relation relation;
ListCell *cell;
@@ -2398,9 +2383,6 @@ ExecGrant_ForeignServer(InternalGrant *istmt)
Oid ownerId;
HeapTuple tuple;
HeapTuple newtuple;
- Datum values[Natts_pg_foreign_server];
- bool nulls[Natts_pg_foreign_server];
- bool replaces[Natts_pg_foreign_server];
int noldmembers;
int nnewmembers;
Oid *oldmembers;
@@ -2465,10 +2447,6 @@ ExecGrant_ForeignServer(InternalGrant *istmt)
nnewmembers = aclmembers(new_acl, &newmembers);
/* finished building new ACL value, now insert it */
- MemSet(values, 0, sizeof(values));
- MemSet(nulls, false, sizeof(nulls));
- MemSet(replaces, false, sizeof(replaces));
-
replaces[Anum_pg_foreign_server_srvacl - 1] = true;
values[Anum_pg_foreign_server_srvacl - 1] = PointerGetDatum(new_acl);
@@ -2501,6 +2479,9 @@ ExecGrant_ForeignServer(InternalGrant *istmt)
static void
ExecGrant_Function(InternalGrant *istmt)
{
+ Datum values[Natts_pg_proc] = {0};
+ bool nulls[Natts_pg_proc] = {0};
+ bool replaces[Natts_pg_proc] = {0};
Relation relation;
ListCell *cell;
@@ -2523,9 +2504,6 @@ ExecGrant_Function(InternalGrant *istmt)
Oid ownerId;
HeapTuple tuple;
HeapTuple newtuple;
- Datum values[Natts_pg_proc];
- bool nulls[Natts_pg_proc];
- bool replaces[Natts_pg_proc];
int noldmembers;
int nnewmembers;
Oid *oldmembers;
@@ -2589,10 +2567,6 @@ ExecGrant_Function(InternalGrant *istmt)
nnewmembers = aclmembers(new_acl, &newmembers);
/* finished building new ACL value, now insert it */
- MemSet(values, 0, sizeof(values));
- MemSet(nulls, false, sizeof(nulls));
- MemSet(replaces, false, sizeof(replaces));
-
replaces[Anum_pg_proc_proacl - 1] = true;
values[Anum_pg_proc_proacl - 1] = PointerGetDatum(new_acl);
@@ -2624,6 +2598,9 @@ ExecGrant_Function(InternalGrant *istmt)
static void
ExecGrant_Language(InternalGrant *istmt)
{
+ Datum values[Natts_pg_language] = {0};
+ bool nulls[Natts_pg_language] = {0};
+ bool replaces[Natts_pg_language] = {0};
Relation relation;
ListCell *cell;
@@ -2646,9 +2623,6 @@ ExecGrant_Language(InternalGrant *istmt)
Oid ownerId;
HeapTuple tuple;
HeapTuple newtuple;
- Datum values[Natts_pg_language];
- bool nulls[Natts_pg_language];
- bool replaces[Natts_pg_language];
int noldmembers;
int nnewmembers;
Oid *oldmembers;
@@ -2720,10 +2694,6 @@ ExecGrant_Language(InternalGrant *istmt)
nnewmembers = aclmembers(new_acl, &newmembers);
/* finished building new ACL value, now insert it */
- MemSet(values, 0, sizeof(values));
- MemSet(nulls, false, sizeof(nulls));
- MemSet(replaces, false, sizeof(replaces));
-
replaces[Anum_pg_language_lanacl - 1] = true;
values[Anum_pg_language_lanacl - 1] = PointerGetDatum(new_acl);
@@ -2755,6 +2725,9 @@ ExecGrant_Language(InternalGrant *istmt)
static void
ExecGrant_Largeobject(InternalGrant *istmt)
{
+ Datum values[Natts_pg_largeobject_metadata] = {0};
+ bool nulls[Natts_pg_largeobject_metadata] = {0};
+ bool replaces[Natts_pg_largeobject_metadata] = {0};
Relation relation;
ListCell *cell;
@@ -2778,9 +2751,6 @@ ExecGrant_Largeobject(InternalGrant *istmt)
Oid grantorId;
Oid ownerId;
HeapTuple newtuple;
- Datum values[Natts_pg_largeobject_metadata];
- bool nulls[Natts_pg_largeobject_metadata];
- bool replaces[Natts_pg_largeobject_metadata];
int noldmembers;
int nnewmembers;
Oid *oldmembers;
@@ -2858,10 +2828,6 @@ ExecGrant_Largeobject(InternalGrant *istmt)
nnewmembers = aclmembers(new_acl, &newmembers);
/* finished building new ACL value, now insert it */
- MemSet(values, 0, sizeof(values));
- MemSet(nulls, false, sizeof(nulls));
- MemSet(replaces, false, sizeof(replaces));
-
replaces[Anum_pg_largeobject_metadata_lomacl - 1] = true;
values[Anum_pg_largeobject_metadata_lomacl - 1]
= PointerGetDatum(new_acl);
@@ -2895,6 +2861,9 @@ ExecGrant_Largeobject(InternalGrant *istmt)
static void
ExecGrant_Namespace(InternalGrant *istmt)
{
+ Datum values[Natts_pg_namespace] = {0};
+ bool nulls[Natts_pg_namespace] = {0};
+ bool replaces[Natts_pg_namespace] = {0};
Relation relation;
ListCell *cell;
@@ -2917,9 +2886,6 @@ ExecGrant_Namespace(InternalGrant *istmt)
Oid ownerId;
HeapTuple tuple;
HeapTuple newtuple;
- Datum values[Natts_pg_namespace];
- bool nulls[Natts_pg_namespace];
- bool replaces[Natts_pg_namespace];
int noldmembers;
int nnewmembers;
Oid *oldmembers;
@@ -2984,10 +2950,6 @@ ExecGrant_Namespace(InternalGrant *istmt)
nnewmembers = aclmembers(new_acl, &newmembers);
/* finished building new ACL value, now insert it */
- MemSet(values, 0, sizeof(values));
- MemSet(nulls, false, sizeof(nulls));
- MemSet(replaces, false, sizeof(replaces));
-
replaces[Anum_pg_namespace_nspacl - 1] = true;
values[Anum_pg_namespace_nspacl - 1] = PointerGetDatum(new_acl);
@@ -3019,6 +2981,9 @@ ExecGrant_Namespace(InternalGrant *istmt)
static void
ExecGrant_Tablespace(InternalGrant *istmt)
{
+ Datum values[Natts_pg_tablespace] = {0};
+ bool nulls[Natts_pg_tablespace] = {0};
+ bool replaces[Natts_pg_tablespace] = {0};
Relation relation;
ListCell *cell;
@@ -3040,9 +3005,6 @@ ExecGrant_Tablespace(InternalGrant *istmt)
Oid grantorId;
Oid ownerId;
HeapTuple newtuple;
- Datum values[Natts_pg_tablespace];
- bool nulls[Natts_pg_tablespace];
- bool replaces[Natts_pg_tablespace];
int noldmembers;
int nnewmembers;
Oid *oldmembers;
@@ -3108,10 +3070,6 @@ ExecGrant_Tablespace(InternalGrant *istmt)
nnewmembers = aclmembers(new_acl, &newmembers);
/* finished building new ACL value, now insert it */
- MemSet(values, 0, sizeof(values));
- MemSet(nulls, false, sizeof(nulls));
- MemSet(replaces, false, sizeof(replaces));
-
replaces[Anum_pg_tablespace_spcacl - 1] = true;
values[Anum_pg_tablespace_spcacl - 1] = PointerGetDatum(new_acl);
@@ -3139,6 +3097,9 @@ ExecGrant_Tablespace(InternalGrant *istmt)
static void
ExecGrant_Type(InternalGrant *istmt)
{
+ Datum values[Natts_pg_type] = {0};
+ bool nulls[Natts_pg_type] = {0};
+ bool replaces[Natts_pg_type] = {0};
Relation relation;
ListCell *cell;
@@ -3160,9 +3121,6 @@ ExecGrant_Type(InternalGrant *istmt)
Oid grantorId;
Oid ownerId;
HeapTuple newtuple;
- Datum values[Natts_pg_type];
- bool nulls[Natts_pg_type];
- bool replaces[Natts_pg_type];
int noldmembers;
int nnewmembers;
Oid *oldmembers;
@@ -3242,10 +3200,6 @@ ExecGrant_Type(InternalGrant *istmt)
nnewmembers = aclmembers(new_acl, &newmembers);
/* finished building new ACL value, now insert it */
- MemSet(values, 0, sizeof(values));
- MemSet(nulls, false, sizeof(nulls));
- MemSet(replaces, false, sizeof(replaces));
-
replaces[Anum_pg_type_typacl - 1] = true;
values[Anum_pg_type_typacl - 1] = PointerGetDatum(new_acl);
@@ -3384,13 +3338,9 @@ ExecGrant_Parameter(InternalGrant *istmt)
{
/* finished building new ACL value, now insert it */
HeapTuple newtuple;
- Datum values[Natts_pg_parameter_acl];
- bool nulls[Natts_pg_parameter_acl];
- bool replaces[Natts_pg_parameter_acl];
-
- MemSet(values, 0, sizeof(values));
- MemSet(nulls, false, sizeof(nulls));
- MemSet(replaces, false, sizeof(replaces));
+ Datum values[Natts_pg_parameter_acl] = {0};
+ bool nulls[Natts_pg_parameter_acl] = {0};
+ bool replaces[Natts_pg_parameter_acl] = {0};
replaces[Anum_pg_parameter_acl_paracl - 1] = true;
values[Anum_pg_parameter_acl_paracl - 1] = PointerGetDatum(new_acl);
@@ -6419,16 +6369,12 @@ recordExtensionInitPrivWorker(Oid objoid, Oid classoid, int objsubid, Acl *new_a
/* If we find an entry, update it with the latest ACL. */
if (HeapTupleIsValid(oldtuple))
{
- Datum values[Natts_pg_init_privs];
- bool nulls[Natts_pg_init_privs];
- bool replace[Natts_pg_init_privs];
-
/* If we have a new ACL to set, then update the row with it. */
if (new_acl)
{
- MemSet(values, 0, sizeof(values));
- MemSet(nulls, false, sizeof(nulls));
- MemSet(replace, false, sizeof(replace));
+ Datum values[Natts_pg_init_privs] = {0};
+ bool nulls[Natts_pg_init_privs] = {0};
+ bool replace[Natts_pg_init_privs] = {0};
values[Anum_pg_init_privs_initprivs - 1] = PointerGetDatum(new_acl);
replace[Anum_pg_init_privs_initprivs - 1] = true;
@@ -6446,9 +6392,6 @@ recordExtensionInitPrivWorker(Oid objoid, Oid classoid, int objsubid, Acl *new_a
}
else
{
- Datum values[Natts_pg_init_privs];
- bool nulls[Natts_pg_init_privs];
-
/*
* Only add a new entry if the new ACL is non-NULL.
*
@@ -6457,9 +6400,10 @@ recordExtensionInitPrivWorker(Oid objoid, Oid classoid, int objsubid, Acl *new_a
*/
if (new_acl)
{
- /* No entry found, so add it. */
- MemSet(nulls, false, sizeof(nulls));
+ Datum values[Natts_pg_init_privs] = {0};
+ bool nulls[Natts_pg_init_privs] = {0};
+ /* No entry found, so add it. */
values[Anum_pg_init_privs_objoid - 1] = ObjectIdGetDatum(objoid);
values[Anum_pg_init_privs_classoid - 1] = ObjectIdGetDatum(classoid);
values[Anum_pg_init_privs_objsubid - 1] = Int32GetDatum(objsubid);
diff --git a/src/backend/catalog/dependency.c b/src/backend/catalog/dependency.c
index de10923391..5cbd72ce10 100644
--- a/src/backend/catalog/dependency.c
+++ b/src/backend/catalog/dependency.c
@@ -1635,12 +1635,11 @@ recordDependencyOnSingleRelExpr(const ObjectAddress *depender,
bool reverse_self)
{
find_expr_references_context context;
- RangeTblEntry rte;
+ RangeTblEntry rte = {0};
context.addrs = new_object_addresses();
/* We gin up a rather bogus rangetable list to handle Vars */
- MemSet(&rte, 0, sizeof(rte));
rte.type = T_RangeTblEntry;
rte.rtekind = RTE_RELATION;
rte.relid = relId;
diff --git a/src/backend/catalog/heap.c b/src/backend/catalog/heap.c
index e770ea6eb8..9b03579e6e 100644
--- a/src/backend/catalog/heap.c
+++ b/src/backend/catalog/heap.c
@@ -1709,15 +1709,11 @@ RemoveAttributeById(Oid relid, AttrNumber attnum)
/* clear the missing value if any */
if (attStruct->atthasmissing)
{
- Datum valuesAtt[Natts_pg_attribute];
- bool nullsAtt[Natts_pg_attribute];
- bool replacesAtt[Natts_pg_attribute];
+ Datum valuesAtt[Natts_pg_attribute] = {0};
+ bool nullsAtt[Natts_pg_attribute] = {0};
+ bool replacesAtt[Natts_pg_attribute] = {0};
/* update the tuple - set atthasmissing and attmissingval */
- MemSet(valuesAtt, 0, sizeof(valuesAtt));
- MemSet(nullsAtt, false, sizeof(nullsAtt));
- MemSet(replacesAtt, false, sizeof(replacesAtt));
-
valuesAtt[Anum_pg_attribute_atthasmissing - 1] =
BoolGetDatum(false);
replacesAtt[Anum_pg_attribute_atthasmissing - 1] = true;
@@ -2006,9 +2002,9 @@ RelationClearMissing(Relation rel)
void
SetAttrMissing(Oid relid, char *attname, char *value)
{
- Datum valuesAtt[Natts_pg_attribute];
- bool nullsAtt[Natts_pg_attribute];
- bool replacesAtt[Natts_pg_attribute];
+ Datum valuesAtt[Natts_pg_attribute] = {0};
+ bool nullsAtt[Natts_pg_attribute] = {0};
+ bool replacesAtt[Natts_pg_attribute] = {0};
Datum missingval;
Form_pg_attribute attStruct;
Relation attrrel,
@@ -2041,10 +2037,6 @@ SetAttrMissing(Oid relid, char *attname, char *value)
Int32GetDatum(attStruct->atttypmod));
/* update the tuple - set atthasmissing and attmissingval */
- MemSet(valuesAtt, 0, sizeof(valuesAtt));
- MemSet(nullsAtt, false, sizeof(nullsAtt));
- MemSet(replacesAtt, false, sizeof(replacesAtt));
-
valuesAtt[Anum_pg_attribute_atthasmissing - 1] = BoolGetDatum(true);
replacesAtt[Anum_pg_attribute_atthasmissing - 1] = true;
valuesAtt[Anum_pg_attribute_attmissingval - 1] = missingval;
@@ -3321,7 +3313,7 @@ StorePartitionKey(Relation rel,
Relation pg_partitioned_table;
HeapTuple tuple;
Datum values[Natts_pg_partitioned_table];
- bool nulls[Natts_pg_partitioned_table];
+ bool nulls[Natts_pg_partitioned_table] = {0};
ObjectAddress myself;
ObjectAddress referenced;
ObjectAddresses *addrs;
@@ -3347,8 +3339,6 @@ StorePartitionKey(Relation rel,
pg_partitioned_table = table_open(PartitionedRelationId, RowExclusiveLock);
- MemSet(nulls, false, sizeof(nulls));
-
/* Only this can ever be NULL */
if (!partexprDatum)
nulls[Anum_pg_partitioned_table_partexprs - 1] = true;
diff --git a/src/backend/catalog/index.c b/src/backend/catalog/index.c
index c5d463ac55..d7192f35e3 100644
--- a/src/backend/catalog/index.c
+++ b/src/backend/catalog/index.c
@@ -554,7 +554,7 @@ UpdateIndexRelation(Oid indexoid,
Datum exprsDatum;
Datum predDatum;
Datum values[Natts_pg_index];
- bool nulls[Natts_pg_index];
+ bool nulls[Natts_pg_index] = {0};
Relation pg_index;
HeapTuple tuple;
int i;
@@ -608,8 +608,6 @@ UpdateIndexRelation(Oid indexoid,
/*
* Build a pg_index tuple
*/
- MemSet(nulls, false, sizeof(nulls));
-
values[Anum_pg_index_indexrelid - 1] = ObjectIdGetDatum(indexoid);
values[Anum_pg_index_indrelid - 1] = ObjectIdGetDatum(heapoid);
values[Anum_pg_index_indnatts - 1] = Int16GetDatum(indexInfo->ii_NumIndexAttrs);
diff --git a/src/backend/catalog/pg_attrdef.c b/src/backend/catalog/pg_attrdef.c
index c5d4a9912e..1a14093a9a 100644
--- a/src/backend/catalog/pg_attrdef.c
+++ b/src/backend/catalog/pg_attrdef.c
@@ -111,15 +111,12 @@ StoreAttrDefault(Relation rel, AttrNumber attnum,
Expr *expr2 = (Expr *) expr;
EState *estate = NULL;
ExprContext *econtext;
- Datum valuesAtt[Natts_pg_attribute];
- bool nullsAtt[Natts_pg_attribute];
- bool replacesAtt[Natts_pg_attribute];
+ Datum valuesAtt[Natts_pg_attribute] = {0};
+ bool nullsAtt[Natts_pg_attribute] = {0};
+ bool replacesAtt[Natts_pg_attribute] = {0};
Datum missingval = (Datum) 0;
bool missingIsNull = true;
- MemSet(valuesAtt, 0, sizeof(valuesAtt));
- MemSet(nullsAtt, false, sizeof(nullsAtt));
- MemSet(replacesAtt, false, sizeof(replacesAtt));
valuesAtt[Anum_pg_attribute_atthasdef - 1] = true;
replacesAtt[Anum_pg_attribute_atthasdef - 1] = true;
diff --git a/src/backend/catalog/pg_cast.c b/src/backend/catalog/pg_cast.c
index 4857f6468d..1812bb7fcc 100644
--- a/src/backend/catalog/pg_cast.c
+++ b/src/backend/catalog/pg_cast.c
@@ -47,7 +47,7 @@ CastCreate(Oid sourcetypeid, Oid targettypeid, Oid funcid, char castcontext,
HeapTuple tuple;
Oid castid;
Datum values[Natts_pg_cast];
- bool nulls[Natts_pg_cast];
+ bool nulls[Natts_pg_cast] = {0};
ObjectAddress myself,
referenced;
ObjectAddresses *addrs;
@@ -78,8 +78,6 @@ CastCreate(Oid sourcetypeid, Oid targettypeid, Oid funcid, char castcontext,
values[Anum_pg_cast_castcontext - 1] = CharGetDatum(castcontext);
values[Anum_pg_cast_castmethod - 1] = CharGetDatum(castmethod);
- MemSet(nulls, false, sizeof(nulls));
-
tuple = heap_form_tuple(RelationGetDescr(relation), values, nulls);
CatalogTupleInsert(relation, tuple);
diff --git a/src/backend/catalog/pg_parameter_acl.c b/src/backend/catalog/pg_parameter_acl.c
index 2decee909b..0570e811d1 100644
--- a/src/backend/catalog/pg_parameter_acl.c
+++ b/src/backend/catalog/pg_parameter_acl.c
@@ -74,8 +74,8 @@ ParameterAclCreate(const char *parameter)
Relation rel;
TupleDesc tupDesc;
HeapTuple tuple;
- Datum values[Natts_pg_parameter_acl];
- bool nulls[Natts_pg_parameter_acl];
+ Datum values[Natts_pg_parameter_acl] = {0};
+ bool nulls[Natts_pg_parameter_acl] = {0};
/*
* To prevent cluttering pg_parameter_acl with useless entries, insist
@@ -98,8 +98,6 @@ ParameterAclCreate(const char *parameter)
*/
rel = table_open(ParameterAclRelationId, RowExclusiveLock);
tupDesc = RelationGetDescr(rel);
- MemSet(values, 0, sizeof(values));
- MemSet(nulls, false, sizeof(nulls));
parameterId = GetNewOidWithIndex(rel,
ParameterAclOidIndexId,
Anum_pg_parameter_acl_oid);
diff --git a/src/backend/catalog/pg_publication.c b/src/backend/catalog/pg_publication.c
index c365de3a72..4ff692cb5e 100644
--- a/src/backend/catalog/pg_publication.c
+++ b/src/backend/catalog/pg_publication.c
@@ -1162,15 +1162,12 @@ pg_get_publication_tables(PG_FUNCTION_ARGS)
HeapTuple pubtuple = NULL;
HeapTuple rettuple;
Oid relid = list_nth_oid(tables, funcctx->call_cntr);
- Datum values[NUM_PUBLICATION_TABLES_ELEM];
- bool nulls[NUM_PUBLICATION_TABLES_ELEM];
+ Datum values[NUM_PUBLICATION_TABLES_ELEM] = {0};
+ bool nulls[NUM_PUBLICATION_TABLES_ELEM] = {0};
/*
* Form tuple with appropriate data.
*/
- MemSet(nulls, 0, sizeof(nulls));
- MemSet(values, 0, sizeof(values));
-
publication = GetPublicationByName(pubname, false);
values[0] = ObjectIdGetDatum(relid);
diff --git a/src/backend/commands/copyfromparse.c b/src/backend/commands/copyfromparse.c
index 57813b3458..cef0f2c279 100644
--- a/src/backend/commands/copyfromparse.c
+++ b/src/backend/commands/copyfromparse.c
@@ -869,7 +869,7 @@ NextCopyFrom(CopyFromState cstate, ExprContext *econtext,
/* Initialize all values for row to NULL */
MemSet(values, 0, num_phys_attrs * sizeof(Datum));
- MemSet(nulls, true, num_phys_attrs * sizeof(bool));
+ memset(nulls, true, num_phys_attrs * sizeof(bool));
if (!cstate->opts.binary)
{
diff --git a/src/backend/commands/dbcommands.c b/src/backend/commands/dbcommands.c
index 1901b434c5..099d369b2f 100644
--- a/src/backend/commands/dbcommands.c
+++ b/src/backend/commands/dbcommands.c
@@ -689,8 +689,8 @@ createdb(ParseState *pstate, const CreatedbStmt *stmt)
volatile Oid dst_deftablespace;
Relation pg_database_rel;
HeapTuple tuple;
- Datum new_record[Natts_pg_database];
- bool new_record_nulls[Natts_pg_database];
+ Datum new_record[Natts_pg_database] = {0};
+ bool new_record_nulls[Natts_pg_database] = {0};
Oid dboid = InvalidOid;
Oid datdba;
ListCell *option;
@@ -1296,9 +1296,6 @@ createdb(ParseState *pstate, const CreatedbStmt *stmt)
(dblocprovider != COLLPROVIDER_ICU && !dbiculocale));
/* Form tuple */
- MemSet(new_record, 0, sizeof(new_record));
- MemSet(new_record_nulls, false, sizeof(new_record_nulls));
-
new_record[Anum_pg_database_oid - 1] = ObjectIdGetDatum(dboid);
new_record[Anum_pg_database_datname - 1] =
DirectFunctionCall1(namein, CStringGetDatum(dbname));
@@ -1822,9 +1819,6 @@ movedb(const char *dbname, const char *tblspcname)
newtuple;
Oid src_tblspcoid,
dst_tblspcoid;
- Datum new_record[Natts_pg_database];
- bool new_record_nulls[Natts_pg_database];
- bool new_record_repl[Natts_pg_database];
ScanKeyData scankey;
SysScanDesc sysscan;
AclResult aclresult;
@@ -2003,6 +1997,10 @@ movedb(const char *dbname, const char *tblspcname)
PG_ENSURE_ERROR_CLEANUP(movedb_failure_callback,
PointerGetDatum(&fparms));
{
+ Datum new_record[Natts_pg_database] = {0};
+ bool new_record_nulls[Natts_pg_database] = {0};
+ bool new_record_repl[Natts_pg_database] = {0};
+
/*
* Copy files from the old tablespace to the new one
*/
@@ -2042,10 +2040,6 @@ movedb(const char *dbname, const char *tblspcname)
(errcode(ERRCODE_UNDEFINED_DATABASE),
errmsg("database \"%s\" does not exist", dbname)));
- MemSet(new_record, 0, sizeof(new_record));
- MemSet(new_record_nulls, false, sizeof(new_record_nulls));
- MemSet(new_record_repl, false, sizeof(new_record_repl));
-
new_record[Anum_pg_database_dattablespace - 1] = ObjectIdGetDatum(dst_tblspcoid);
new_record_repl[Anum_pg_database_dattablespace - 1] = true;
@@ -2194,9 +2188,9 @@ AlterDatabase(ParseState *pstate, AlterDatabaseStmt *stmt, bool isTopLevel)
DefElem *dallowconnections = NULL;
DefElem *dconnlimit = NULL;
DefElem *dtablespace = NULL;
- Datum new_record[Natts_pg_database];
- bool new_record_nulls[Natts_pg_database];
- bool new_record_repl[Natts_pg_database];
+ Datum new_record[Natts_pg_database] = {0};
+ bool new_record_nulls[Natts_pg_database] = {0};
+ bool new_record_repl[Natts_pg_database] = {0};
/* Extract options from the statement node tree */
foreach(option, stmt->options)
@@ -2305,10 +2299,6 @@ AlterDatabase(ParseState *pstate, AlterDatabaseStmt *stmt, bool isTopLevel)
/*
* Build an updated tuple, perusing the information just obtained
*/
- MemSet(new_record, 0, sizeof(new_record));
- MemSet(new_record_nulls, false, sizeof(new_record_nulls));
- MemSet(new_record_repl, false, sizeof(new_record_repl));
-
if (distemplate)
{
new_record[Anum_pg_database_datistemplate - 1] = BoolGetDatum(dbistemplate);
@@ -2492,8 +2482,8 @@ AlterDatabaseOwner(const char *dbname, Oid newOwnerId)
if (datForm->datdba != newOwnerId)
{
Datum repl_val[Natts_pg_database];
- bool repl_null[Natts_pg_database];
- bool repl_repl[Natts_pg_database];
+ bool repl_null[Natts_pg_database] = {0};
+ bool repl_repl[Natts_pg_database] = {0};
Acl *newAcl;
Datum aclDatum;
bool isNull;
@@ -2521,9 +2511,6 @@ AlterDatabaseOwner(const char *dbname, Oid newOwnerId)
(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
errmsg("permission denied to change owner of database")));
- memset(repl_null, false, sizeof(repl_null));
- memset(repl_repl, false, sizeof(repl_repl));
-
repl_repl[Anum_pg_database_datdba - 1] = true;
repl_val[Anum_pg_database_datdba - 1] = ObjectIdGetDatum(newOwnerId);
diff --git a/src/backend/commands/event_trigger.c b/src/backend/commands/event_trigger.c
index f46f86474a..eef3e5d56e 100644
--- a/src/backend/commands/event_trigger.c
+++ b/src/backend/commands/event_trigger.c
@@ -1310,14 +1310,11 @@ pg_event_trigger_dropped_objects(PG_FUNCTION_ARGS)
{
SQLDropObject *obj;
int i = 0;
- Datum values[12];
- bool nulls[12];
+ Datum values[12] = {0};
+ bool nulls[12] = {0};
obj = slist_container(SQLDropObject, next, iter.cur);
- MemSet(values, 0, sizeof(values));
- MemSet(nulls, 0, sizeof(nulls));
-
/* classid */
values[i++] = ObjectIdGetDatum(obj->address.classId);
@@ -1840,7 +1837,7 @@ pg_event_trigger_ddl_commands(PG_FUNCTION_ARGS)
{
CollectedCommand *cmd = lfirst(lc);
Datum values[9];
- bool nulls[9];
+ bool nulls[9] = {0};
ObjectAddress addr;
int i = 0;
@@ -1858,8 +1855,6 @@ pg_event_trigger_ddl_commands(PG_FUNCTION_ARGS)
!OidIsValid(cmd->d.simple.address.objectId))
continue;
- MemSet(nulls, 0, sizeof(nulls));
-
switch (cmd->type)
{
case SCT_Simple:
diff --git a/src/backend/commands/functioncmds.c b/src/backend/commands/functioncmds.c
index b016eecb2c..f51cfe6df1 100644
--- a/src/backend/commands/functioncmds.c
+++ b/src/backend/commands/functioncmds.c
@@ -1806,8 +1806,7 @@ CreateTransform(CreateTransformStmt *stmt)
AclResult aclresult;
Form_pg_proc procstruct;
Datum values[Natts_pg_transform];
- bool nulls[Natts_pg_transform];
- bool replaces[Natts_pg_transform];
+ bool nulls[Natts_pg_transform] = {0};
Oid transformid;
HeapTuple tuple;
HeapTuple newtuple;
@@ -1913,8 +1912,6 @@ CreateTransform(CreateTransformStmt *stmt)
values[Anum_pg_transform_trffromsql - 1] = ObjectIdGetDatum(fromsqlfuncid);
values[Anum_pg_transform_trftosql - 1] = ObjectIdGetDatum(tosqlfuncid);
- MemSet(nulls, false, sizeof(nulls));
-
relation = table_open(TransformRelationId, RowExclusiveLock);
tuple = SearchSysCache2(TRFTYPELANG,
@@ -1922,6 +1919,8 @@ CreateTransform(CreateTransformStmt *stmt)
ObjectIdGetDatum(langid));
if (HeapTupleIsValid(tuple))
{
+ bool replaces[Natts_pg_transform] = {0};
+
Form_pg_transform form = (Form_pg_transform) GETSTRUCT(tuple);
if (!stmt->replace)
@@ -1931,7 +1930,6 @@ CreateTransform(CreateTransformStmt *stmt)
format_type_be(typeid),
stmt->lang)));
- MemSet(replaces, false, sizeof(replaces));
replaces[Anum_pg_transform_trffromsql - 1] = true;
replaces[Anum_pg_transform_trftosql - 1] = true;
diff --git a/src/backend/commands/prepare.c b/src/backend/commands/prepare.c
index 2333aae467..579825c159 100644
--- a/src/backend/commands/prepare.c
+++ b/src/backend/commands/prepare.c
@@ -685,12 +685,10 @@ pg_prepared_statement(PG_FUNCTION_ARGS)
{
TupleDesc result_desc;
Datum values[8];
- bool nulls[8];
+ bool nulls[8] = {0};
result_desc = prep_stmt->plansource->resultDesc;
- MemSet(nulls, 0, sizeof(nulls));
-
values[0] = CStringGetTextDatum(prep_stmt->stmt_name);
values[1] = CStringGetTextDatum(prep_stmt->plansource->query_string);
values[2] = TimestampTzGetDatum(prep_stmt->prepare_time);
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index ef5b34a312..18f7a4ae86 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -9013,15 +9013,15 @@ ATAddForeignKeyConstraint(List **wqueue, AlteredTableInfo *tab, Relation rel,
bool recurse, bool recursing, LOCKMODE lockmode)
{
Relation pkrel;
- int16 pkattnum[INDEX_MAX_KEYS];
- int16 fkattnum[INDEX_MAX_KEYS];
- Oid pktypoid[INDEX_MAX_KEYS];
- Oid fktypoid[INDEX_MAX_KEYS];
- Oid opclasses[INDEX_MAX_KEYS];
- Oid pfeqoperators[INDEX_MAX_KEYS];
- Oid ppeqoperators[INDEX_MAX_KEYS];
- Oid ffeqoperators[INDEX_MAX_KEYS];
- int16 fkdelsetcols[INDEX_MAX_KEYS];
+ int16 pkattnum[INDEX_MAX_KEYS] = {0};
+ int16 fkattnum[INDEX_MAX_KEYS] = {0};
+ Oid pktypoid[INDEX_MAX_KEYS] = {0};
+ Oid fktypoid[INDEX_MAX_KEYS] = {0};
+ Oid opclasses[INDEX_MAX_KEYS] = {0};
+ Oid pfeqoperators[INDEX_MAX_KEYS] = {0};
+ Oid ppeqoperators[INDEX_MAX_KEYS] = {0};
+ Oid ffeqoperators[INDEX_MAX_KEYS] = {0};
+ int16 fkdelsetcols[INDEX_MAX_KEYS] = {0};
int i;
int numfks,
numpks,
@@ -9113,16 +9113,6 @@ ATAddForeignKeyConstraint(List **wqueue, AlteredTableInfo *tab, Relation rel,
* Look up the referencing attributes to make sure they exist, and record
* their attnums and type OIDs.
*/
- MemSet(pkattnum, 0, sizeof(pkattnum));
- MemSet(fkattnum, 0, sizeof(fkattnum));
- MemSet(pktypoid, 0, sizeof(pktypoid));
- MemSet(fktypoid, 0, sizeof(fktypoid));
- MemSet(opclasses, 0, sizeof(opclasses));
- MemSet(pfeqoperators, 0, sizeof(pfeqoperators));
- MemSet(ppeqoperators, 0, sizeof(ppeqoperators));
- MemSet(ffeqoperators, 0, sizeof(ffeqoperators));
- MemSet(fkdelsetcols, 0, sizeof(fkdelsetcols));
-
numfks = transformColumnNameList(RelationGetRelid(rel),
fkconstraint->fk_attrs,
fkattnum, fktypoid);
@@ -11498,7 +11488,7 @@ validateForeignKeyConstraint(char *conname,
{
TupleTableSlot *slot;
TableScanDesc scan;
- Trigger trig;
+ Trigger trig = {0};
Snapshot snapshot;
MemoryContext oldcxt;
MemoryContext perTupCxt;
@@ -11509,7 +11499,6 @@ validateForeignKeyConstraint(char *conname,
/*
* Build a trigger call structure; we'll need it either way.
*/
- MemSet(&trig, 0, sizeof(trig));
trig.tgoid = InvalidOid;
trig.tgname = conname;
trig.tgenabled = TRIGGER_FIRES_ON_ORIGIN;
@@ -12783,15 +12772,11 @@ ATExecAlterColumnType(AlteredTableInfo *tab, Relation rel,
int one = 1;
bool isNull;
- Datum valuesAtt[Natts_pg_attribute];
- bool nullsAtt[Natts_pg_attribute];
- bool replacesAtt[Natts_pg_attribute];
+ Datum valuesAtt[Natts_pg_attribute] = {0};
+ bool nullsAtt[Natts_pg_attribute] = {0};
+ bool replacesAtt[Natts_pg_attribute] = {0};
HeapTuple newTup;
- MemSet(valuesAtt, 0, sizeof(valuesAtt));
- MemSet(nullsAtt, false, sizeof(nullsAtt));
- MemSet(replacesAtt, false, sizeof(replacesAtt));
-
missingval = array_get_element(missingval,
1,
&one,
@@ -19219,7 +19204,7 @@ ATDetachCheckNoForeignKeyRefs(Relation partition)
HeapTuple tuple;
Form_pg_constraint constrForm;
Relation rel;
- Trigger trig;
+ Trigger trig = {0};
tuple = SearchSysCache1(CONSTROID, ObjectIdGetDatum(constrOid));
if (!HeapTupleIsValid(tuple))
@@ -19232,7 +19217,6 @@ ATDetachCheckNoForeignKeyRefs(Relation partition)
/* prevent data changes into the referencing table until commit */
rel = table_open(constrForm->conrelid, ShareLock);
- MemSet(&trig, 0, sizeof(trig));
trig.tgoid = InvalidOid;
trig.tgname = NameStr(constrForm->conname);
trig.tgenabled = TRIGGER_FIRES_ON_ORIGIN;
diff --git a/src/backend/commands/tablespace.c b/src/backend/commands/tablespace.c
index c8bdd9992a..cb7d46089a 100644
--- a/src/backend/commands/tablespace.c
+++ b/src/backend/commands/tablespace.c
@@ -238,7 +238,7 @@ CreateTableSpace(CreateTableSpaceStmt *stmt)
#ifdef HAVE_SYMLINK
Relation rel;
Datum values[Natts_pg_tablespace];
- bool nulls[Natts_pg_tablespace];
+ bool nulls[Natts_pg_tablespace] = {0};
HeapTuple tuple;
Oid tablespaceoid;
char *location;
@@ -340,8 +340,6 @@ CreateTableSpace(CreateTableSpaceStmt *stmt)
*/
rel = table_open(TableSpaceRelationId, RowExclusiveLock);
- MemSet(nulls, false, sizeof(nulls));
-
if (IsBinaryUpgrade)
{
/* Use binary-upgrade override for tablespace oid */
diff --git a/src/backend/commands/typecmds.c b/src/backend/commands/typecmds.c
index 4f5e7c7ccb..4f58d29aa5 100644
--- a/src/backend/commands/typecmds.c
+++ b/src/backend/commands/typecmds.c
@@ -2570,9 +2570,9 @@ AlterDomainDefault(List *names, Node *defaultRaw)
Relation rel;
char *defaultValue;
Node *defaultExpr = NULL; /* NULL if no default specified */
- Datum new_record[Natts_pg_type];
- bool new_record_nulls[Natts_pg_type];
- bool new_record_repl[Natts_pg_type];
+ Datum new_record[Natts_pg_type] = {0};
+ bool new_record_nulls[Natts_pg_type] = {0};
+ bool new_record_repl[Natts_pg_type] = {0};
HeapTuple newtuple;
Form_pg_type typTup;
ObjectAddress address;
@@ -2593,9 +2593,6 @@ AlterDomainDefault(List *names, Node *defaultRaw)
checkDomainOwner(tup);
/* Setup new tuple */
- MemSet(new_record, (Datum) 0, sizeof(new_record));
- MemSet(new_record_nulls, false, sizeof(new_record_nulls));
- MemSet(new_record_repl, false, sizeof(new_record_repl));
/* Store the new default into the tuple */
if (defaultRaw)
diff --git a/src/backend/commands/user.c b/src/backend/commands/user.c
index 984305ba31..8f4cc86eda 100644
--- a/src/backend/commands/user.c
+++ b/src/backend/commands/user.c
@@ -74,8 +74,8 @@ CreateRole(ParseState *pstate, CreateRoleStmt *stmt)
Relation pg_authid_rel;
TupleDesc pg_authid_dsc;
HeapTuple tuple;
- Datum new_record[Natts_pg_authid];
- bool new_record_nulls[Natts_pg_authid];
+ Datum new_record[Natts_pg_authid] = {0};
+ bool new_record_nulls[Natts_pg_authid] = {0};
Oid roleid;
ListCell *item;
ListCell *option;
@@ -338,12 +338,8 @@ CreateRole(ParseState *pstate, CreateRoleStmt *stmt)
/*
* Build a tuple to insert
*/
- MemSet(new_record, 0, sizeof(new_record));
- MemSet(new_record_nulls, false, sizeof(new_record_nulls));
-
new_record[Anum_pg_authid_rolname - 1] =
DirectFunctionCall1(namein, CStringGetDatum(stmt->role));
-
new_record[Anum_pg_authid_rolsuper - 1] = BoolGetDatum(issuper);
new_record[Anum_pg_authid_rolinherit - 1] = BoolGetDatum(inherit);
new_record[Anum_pg_authid_rolcreaterole - 1] = BoolGetDatum(createrole);
@@ -492,9 +488,9 @@ CreateRole(ParseState *pstate, CreateRoleStmt *stmt)
Oid
AlterRole(ParseState *pstate, AlterRoleStmt *stmt)
{
- Datum new_record[Natts_pg_authid];
- bool new_record_nulls[Natts_pg_authid];
- bool new_record_repl[Natts_pg_authid];
+ Datum new_record[Natts_pg_authid] = {0};
+ bool new_record_nulls[Natts_pg_authid] = {0};
+ bool new_record_repl[Natts_pg_authid] = {0};
Relation pg_authid_rel;
TupleDesc pg_authid_dsc;
HeapTuple tuple,
@@ -691,9 +687,6 @@ AlterRole(ParseState *pstate, AlterRoleStmt *stmt)
/*
* Build an updated tuple, perusing the information just obtained
*/
- MemSet(new_record, 0, sizeof(new_record));
- MemSet(new_record_nulls, false, sizeof(new_record_nulls));
- MemSet(new_record_repl, false, sizeof(new_record_repl));
/*
* issuper/createrole/etc
@@ -1440,9 +1433,8 @@ AddRoleMems(const char *rolename, Oid roleid,
Oid memberid = lfirst_oid(iditem);
HeapTuple authmem_tuple;
HeapTuple tuple;
- Datum new_record[Natts_pg_auth_members];
- bool new_record_nulls[Natts_pg_auth_members];
- bool new_record_repl[Natts_pg_auth_members];
+ Datum new_record[Natts_pg_auth_members] = {0};
+ bool new_record_nulls[Natts_pg_auth_members] = {0};
/*
* pg_database_owner is never a role member. Lifting this restriction
@@ -1500,10 +1492,6 @@ AddRoleMems(const char *rolename, Oid roleid,
}
/* Build a tuple to insert or update */
- MemSet(new_record, 0, sizeof(new_record));
- MemSet(new_record_nulls, false, sizeof(new_record_nulls));
- MemSet(new_record_repl, false, sizeof(new_record_repl));
-
new_record[Anum_pg_auth_members_roleid - 1] = ObjectIdGetDatum(roleid);
new_record[Anum_pg_auth_members_member - 1] = ObjectIdGetDatum(memberid);
new_record[Anum_pg_auth_members_grantor - 1] = ObjectIdGetDatum(grantorId);
@@ -1511,6 +1499,8 @@ AddRoleMems(const char *rolename, Oid roleid,
if (HeapTupleIsValid(authmem_tuple))
{
+ bool new_record_repl[Natts_pg_auth_members] = {0};
+
new_record_repl[Anum_pg_auth_members_grantor - 1] = true;
new_record_repl[Anum_pg_auth_members_admin_option - 1] = true;
tuple = heap_modify_tuple(authmem_tuple, pg_authmem_dsc,
@@ -1614,15 +1604,11 @@ DelRoleMems(const char *rolename, Oid roleid,
{
/* Just turn off the admin option */
HeapTuple tuple;
- Datum new_record[Natts_pg_auth_members];
- bool new_record_nulls[Natts_pg_auth_members];
- bool new_record_repl[Natts_pg_auth_members];
+ Datum new_record[Natts_pg_auth_members] = {0};
+ bool new_record_nulls[Natts_pg_auth_members] = {0};
+ bool new_record_repl[Natts_pg_auth_members] = {0};
/* Build a tuple to update with */
- MemSet(new_record, 0, sizeof(new_record));
- MemSet(new_record_nulls, false, sizeof(new_record_nulls));
- MemSet(new_record_repl, false, sizeof(new_record_repl));
-
new_record[Anum_pg_auth_members_admin_option - 1] = BoolGetDatum(false);
new_record_repl[Anum_pg_auth_members_admin_option - 1] = true;
diff --git a/src/backend/libpq/auth.c b/src/backend/libpq/auth.c
index 2d9ab7edce..53fb7ca628 100644
--- a/src/backend/libpq/auth.c
+++ b/src/backend/libpq/auth.c
@@ -3022,7 +3022,7 @@ PerformRadiusTransaction(const char *server, const char *secret, const char *por
struct sockaddr_in localaddr;
struct sockaddr_in remoteaddr;
#endif
- struct addrinfo hint;
+ struct addrinfo hint = {0};
struct addrinfo *serveraddrs;
int port;
socklen_t addrsize;
@@ -3038,7 +3038,6 @@ PerformRadiusTransaction(const char *server, const char *secret, const char *por
if (identifier == NULL)
identifier = "postgresql";
- MemSet(&hint, 0, sizeof(hint));
hint.ai_socktype = SOCK_DGRAM;
hint.ai_family = AF_UNSPEC;
port = atoi(portstr);
diff --git a/src/backend/libpq/pqcomm.c b/src/backend/libpq/pqcomm.c
index 75392a8bb7..803d166640 100644
--- a/src/backend/libpq/pqcomm.c
+++ b/src/backend/libpq/pqcomm.c
@@ -331,7 +331,7 @@ StreamServerPort(int family, const char *hostName, unsigned short portNumber,
char *service;
struct addrinfo *addrs = NULL,
*addr;
- struct addrinfo hint;
+ struct addrinfo hint = {0};
int listen_index = 0;
int added = 0;
@@ -343,7 +343,6 @@ StreamServerPort(int family, const char *hostName, unsigned short portNumber,
#endif
/* Initialize hint structure */
- MemSet(&hint, 0, sizeof(hint));
hint.ai_family = family;
hint.ai_flags = AI_PASSIVE;
hint.ai_socktype = SOCK_STREAM;
diff --git a/src/backend/optimizer/path/costsize.c b/src/backend/optimizer/path/costsize.c
index fcc26b01a4..1e0f1880c5 100644
--- a/src/backend/optimizer/path/costsize.c
+++ b/src/backend/optimizer/path/costsize.c
@@ -2926,13 +2926,12 @@ cost_agg(Path *path, PlannerInfo *root,
double output_tuples;
Cost startup_cost;
Cost total_cost;
- AggClauseCosts dummy_aggcosts;
+ const AggClauseCosts dummy_aggcosts = {0};
/* Use all-zero per-aggregate costs if NULL is passed */
if (aggcosts == NULL)
{
Assert(aggstrategy == AGG_HASHED);
- MemSet(&dummy_aggcosts, 0, sizeof(AggClauseCosts));
aggcosts = &dummy_aggcosts;
}
diff --git a/src/backend/optimizer/path/indxpath.c b/src/backend/optimizer/path/indxpath.c
index 0ef70ad7f1..9c1b6305d3 100644
--- a/src/backend/optimizer/path/indxpath.c
+++ b/src/backend/optimizer/path/indxpath.c
@@ -238,9 +238,6 @@ create_index_paths(PlannerInfo *root, RelOptInfo *rel)
List *bitindexpaths;
List *bitjoinpaths;
List *joinorclauses;
- IndexClauseSet rclauseset;
- IndexClauseSet jclauseset;
- IndexClauseSet eclauseset;
ListCell *lc;
/* Skip the whole mess if no indexes */
@@ -253,6 +250,9 @@ create_index_paths(PlannerInfo *root, RelOptInfo *rel)
/* Examine each index in turn */
foreach(lc, rel->indexlist)
{
+ IndexClauseSet rclauseset = {0};
+ IndexClauseSet jclauseset = {0};
+ IndexClauseSet eclauseset = {0};
IndexOptInfo *index = (IndexOptInfo *) lfirst(lc);
/* Protect limited-size array in IndexClauseSets */
@@ -269,7 +269,6 @@ create_index_paths(PlannerInfo *root, RelOptInfo *rel)
/*
* Identify the restriction clauses that can match the index.
*/
- MemSet(&rclauseset, 0, sizeof(rclauseset));
match_restriction_clauses_to_index(root, index, &rclauseset);
/*
@@ -286,7 +285,6 @@ create_index_paths(PlannerInfo *root, RelOptInfo *rel)
* step finds only "loose" join clauses that have not been merged into
* EquivalenceClasses. Also, collect join OR clauses for later.
*/
- MemSet(&jclauseset, 0, sizeof(jclauseset));
match_join_clauses_to_index(root, rel, index,
&jclauseset, &joinorclauses);
@@ -294,7 +292,6 @@ create_index_paths(PlannerInfo *root, RelOptInfo *rel)
* Look for EquivalenceClasses that can generate joinclauses matching
* the index.
*/
- MemSet(&eclauseset, 0, sizeof(eclauseset));
match_eclass_clauses_to_index(root, index,
&eclauseset);
diff --git a/src/backend/optimizer/plan/planner.c b/src/backend/optimizer/plan/planner.c
index 06ad856eac..77cbe681e5 100644
--- a/src/backend/optimizer/plan/planner.c
+++ b/src/backend/optimizer/plan/planner.c
@@ -3350,9 +3350,8 @@ create_grouping_paths(PlannerInfo *root,
Query *parse = root->parse;
RelOptInfo *grouped_rel;
RelOptInfo *partially_grouped_rel;
- AggClauseCosts agg_costs;
+ AggClauseCosts agg_costs = {0};
- MemSet(&agg_costs, 0, sizeof(AggClauseCosts));
get_agg_clause_costs(root, AGGSPLIT_SIMPLE, &agg_costs);
/*
@@ -5908,16 +5907,14 @@ expression_planner_with_deps(Expr *expr,
List **invalItems)
{
Node *result;
- PlannerGlobal glob;
- PlannerInfo root;
+ PlannerGlobal glob = {0};
+ PlannerInfo root = {0};
/* Make up dummy planner state so we can use setrefs machinery */
- MemSet(&glob, 0, sizeof(glob));
glob.type = T_PlannerGlobal;
glob.relationOids = NIL;
glob.invalItems = NIL;
- MemSet(&root, 0, sizeof(root));
root.type = T_PlannerInfo;
root.glob = &glob;
diff --git a/src/backend/optimizer/plan/setrefs.c b/src/backend/optimizer/plan/setrefs.c
index 9cef92cab2..f7fb2b3e6d 100644
--- a/src/backend/optimizer/plan/setrefs.c
+++ b/src/backend/optimizer/plan/setrefs.c
@@ -3285,18 +3285,16 @@ extract_query_dependencies(Node *query,
List **invalItems,
bool *hasRowSecurity)
{
- PlannerGlobal glob;
- PlannerInfo root;
+ PlannerGlobal glob = {0};
+ PlannerInfo root = {0};
/* Make up dummy planner state so we can use this module's machinery */
- MemSet(&glob, 0, sizeof(glob));
glob.type = T_PlannerGlobal;
glob.relationOids = NIL;
glob.invalItems = NIL;
/* Hack: we use glob.dependsOnRole to collect hasRowSecurity flags */
glob.dependsOnRole = false;
- MemSet(&root, 0, sizeof(root));
root.type = T_PlannerInfo;
root.glob = &glob;
diff --git a/src/backend/parser/parse_target.c b/src/backend/parser/parse_target.c
index 2a1d44b813..d69cb58b6a 100644
--- a/src/backend/parser/parse_target.c
+++ b/src/backend/parser/parse_target.c
@@ -1594,9 +1594,8 @@ expandRecordVariable(ParseState *pstate, Var *var, int levelsup)
* to. We have to build an additional level of ParseState
* to keep in step with varlevelsup in the subselect.
*/
- ParseState mypstate;
+ ParseState mypstate = {0};
- MemSet(&mypstate, 0, sizeof(mypstate));
mypstate.parentParseState = pstate;
mypstate.p_rtable = rte->subquery->rtable;
/* don't bother filling the rest of the fake pstate */
@@ -1649,10 +1648,9 @@ expandRecordVariable(ParseState *pstate, Var *var, int levelsup)
* in step with varlevelsup in the CTE; furthermore it
* could be an outer CTE.
*/
- ParseState mypstate;
+ ParseState mypstate = {0};
Index levelsup;
- MemSet(&mypstate, 0, sizeof(mypstate));
/* this loop must work, since GetCTEForRTE did */
for (levelsup = 0;
levelsup < rte->ctelevelsup + netlevelsup;
diff --git a/src/backend/replication/logical/launcher.c b/src/backend/replication/logical/launcher.c
index 2bdab53e19..3bbd522724 100644
--- a/src/backend/replication/logical/launcher.c
+++ b/src/backend/replication/logical/launcher.c
@@ -938,8 +938,8 @@ pg_stat_get_subscription(PG_FUNCTION_ARGS)
for (i = 0; i < max_logical_replication_workers; i++)
{
/* for each row */
- Datum values[PG_STAT_GET_SUBSCRIPTION_COLS];
- bool nulls[PG_STAT_GET_SUBSCRIPTION_COLS];
+ Datum values[PG_STAT_GET_SUBSCRIPTION_COLS] = {0};
+ bool nulls[PG_STAT_GET_SUBSCRIPTION_COLS] = {0};
int worker_pid;
LogicalRepWorker worker;
@@ -953,9 +953,6 @@ pg_stat_get_subscription(PG_FUNCTION_ARGS)
worker_pid = worker.proc->pid;
- MemSet(values, 0, sizeof(values));
- MemSet(nulls, 0, sizeof(nulls));
-
values[0] = ObjectIdGetDatum(worker.subid);
if (OidIsValid(worker.relid))
values[1] = ObjectIdGetDatum(worker.relid);
diff --git a/src/backend/replication/walsender.c b/src/backend/replication/walsender.c
index 3c407ab964..ef2ca3fef7 100644
--- a/src/backend/replication/walsender.c
+++ b/src/backend/replication/walsender.c
@@ -402,7 +402,7 @@ IdentifySystem(void)
TupOutputState *tstate;
TupleDesc tupdesc;
Datum values[4];
- bool nulls[4];
+ bool nulls[4] = {0};
TimeLineID currTLI;
/*
@@ -437,7 +437,6 @@ IdentifySystem(void)
}
dest = CreateDestReceiver(DestRemoteSimple);
- MemSet(nulls, false, sizeof(nulls));
/* need a tuple descriptor representing four columns */
tupdesc = CreateTemplateTupleDesc(4);
@@ -483,7 +482,7 @@ ReadReplicationSlot(ReadReplicationSlotCmd *cmd)
DestReceiver *dest;
TupOutputState *tstate;
TupleDesc tupdesc;
- Datum values[READ_REPLICATION_SLOT_COLS];
+ Datum values[READ_REPLICATION_SLOT_COLS] = {0};
bool nulls[READ_REPLICATION_SLOT_COLS];
tupdesc = CreateTemplateTupleDesc(READ_REPLICATION_SLOT_COLS);
@@ -495,8 +494,7 @@ ReadReplicationSlot(ReadReplicationSlotCmd *cmd)
TupleDescInitBuiltinEntry(tupdesc, (AttrNumber) 3, "restart_tli",
INT8OID, -1, 0);
- MemSet(values, 0, READ_REPLICATION_SLOT_COLS * sizeof(Datum));
- MemSet(nulls, true, READ_REPLICATION_SLOT_COLS * sizeof(bool));
+ memset(nulls, true, READ_REPLICATION_SLOT_COLS * sizeof(bool));
LWLockAcquire(ReplicationSlotControlLock, LW_SHARED);
slot = SearchNamedReplicationSlot(cmd->slotname, false);
@@ -859,13 +857,12 @@ StartReplication(StartReplicationCmd *cmd)
TupOutputState *tstate;
TupleDesc tupdesc;
Datum values[2];
- bool nulls[2];
+ bool nulls[2] = {0};
snprintf(startpos_str, sizeof(startpos_str), "%X/%X",
LSN_FORMAT_ARGS(sendTimeLineValidUpto));
dest = CreateDestReceiver(DestRemoteSimple);
- MemSet(nulls, false, sizeof(nulls));
/*
* Need a tuple descriptor representing two columns. int8 may seem
@@ -1043,7 +1040,7 @@ CreateReplicationSlot(CreateReplicationSlotCmd *cmd)
TupOutputState *tstate;
TupleDesc tupdesc;
Datum values[4];
- bool nulls[4];
+ bool nulls[4] = {0};
Assert(!MyReplicationSlot);
@@ -1178,7 +1175,6 @@ CreateReplicationSlot(CreateReplicationSlotCmd *cmd)
LSN_FORMAT_ARGS(MyReplicationSlot->data.confirmed_flush));
dest = CreateDestReceiver(DestRemoteSimple);
- MemSet(nulls, false, sizeof(nulls));
/*----------
* Need a tuple descriptor representing four columns:
@@ -3527,7 +3523,6 @@ pg_stat_get_wal_senders(PG_FUNCTION_ARGS)
}
}
- memset(nulls, 0, sizeof(nulls));
values[0] = Int32GetDatum(pid);
if (!has_privs_of_role(GetUserId(), ROLE_PG_READ_ALL_STATS))
@@ -3537,10 +3532,12 @@ pg_stat_get_wal_senders(PG_FUNCTION_ARGS)
* can see details. Other users only get the pid value to know
* it's a walsender, but no details.
*/
- MemSet(&nulls[1], true, PG_STAT_GET_WAL_SENDERS_COLS - 1);
+ nulls[0] = false;
+ memset(&nulls[1], true, PG_STAT_GET_WAL_SENDERS_COLS - 1);
}
else
{
+ memset(nulls, 0, sizeof(nulls));
values[1] = CStringGetTextDatum(WalSndGetStateString(state));
if (XLogRecPtrIsInvalid(sentPtr))
diff --git a/src/backend/rewrite/rewriteDefine.c b/src/backend/rewrite/rewriteDefine.c
index 185bf5fbff..a5a1fb887f 100644
--- a/src/backend/rewrite/rewriteDefine.c
+++ b/src/backend/rewrite/rewriteDefine.c
@@ -67,8 +67,7 @@ InsertRule(const char *rulname,
char *evqual = nodeToString(event_qual);
char *actiontree = nodeToString((Node *) action);
Datum values[Natts_pg_rewrite];
- bool nulls[Natts_pg_rewrite];
- bool replaces[Natts_pg_rewrite];
+ bool nulls[Natts_pg_rewrite] = {0};
NameData rname;
Relation pg_rewrite_desc;
HeapTuple tup,
@@ -81,8 +80,6 @@ InsertRule(const char *rulname,
/*
* Set up *nulls and *values arrays
*/
- MemSet(nulls, false, sizeof(nulls));
-
namestrcpy(&rname, rulname);
values[Anum_pg_rewrite_rulename - 1] = NameGetDatum(&rname);
values[Anum_pg_rewrite_ev_class - 1] = ObjectIdGetDatum(eventrel_oid);
@@ -106,6 +103,8 @@ InsertRule(const char *rulname,
if (HeapTupleIsValid(oldtup))
{
+ bool replaces[Natts_pg_rewrite] = {0};
+
if (!replace)
ereport(ERROR,
(errcode(ERRCODE_DUPLICATE_OBJECT),
@@ -115,7 +114,6 @@ InsertRule(const char *rulname,
/*
* When replacing, we don't need to replace every attribute
*/
- MemSet(replaces, false, sizeof(replaces));
replaces[Anum_pg_rewrite_ev_type - 1] = true;
replaces[Anum_pg_rewrite_is_instead - 1] = true;
replaces[Anum_pg_rewrite_ev_qual - 1] = true;
diff --git a/src/backend/storage/lmgr/lock.c b/src/backend/storage/lmgr/lock.c
index 5f5803f681..ae6a1b1116 100644
--- a/src/backend/storage/lmgr/lock.c
+++ b/src/backend/storage/lmgr/lock.c
@@ -597,13 +597,12 @@ DoLockModesConflict(LOCKMODE mode1, LOCKMODE mode2)
bool
LockHeldByMe(const LOCKTAG *locktag, LOCKMODE lockmode)
{
- LOCALLOCKTAG localtag;
+ LOCALLOCKTAG localtag = {0};
LOCALLOCK *locallock;
/*
* See if there is a LOCALLOCK entry for this lock and lockmode
*/
- MemSet(&localtag, 0, sizeof(localtag)); /* must clear padding */
localtag.lock = *locktag;
localtag.mode = lockmode;
@@ -635,7 +634,7 @@ LockHasWaiters(const LOCKTAG *locktag, LOCKMODE lockmode, bool sessionLock)
{
LOCKMETHODID lockmethodid = locktag->locktag_lockmethodid;
LockMethod lockMethodTable;
- LOCALLOCKTAG localtag;
+ LOCALLOCKTAG localtag = {0};
LOCALLOCK *locallock;
LOCK *lock;
PROCLOCK *proclock;
@@ -658,7 +657,6 @@ LockHasWaiters(const LOCKTAG *locktag, LOCKMODE lockmode, bool sessionLock)
/*
* Find the LOCALLOCK entry for this lock and lockmode
*/
- MemSet(&localtag, 0, sizeof(localtag)); /* must clear padding */
localtag.lock = *locktag;
localtag.mode = lockmode;
@@ -777,7 +775,7 @@ LockAcquireExtended(const LOCKTAG *locktag,
{
LOCKMETHODID lockmethodid = locktag->locktag_lockmethodid;
LockMethod lockMethodTable;
- LOCALLOCKTAG localtag;
+ LOCALLOCKTAG localtag = {0};
LOCALLOCK *locallock;
LOCK *lock;
PROCLOCK *proclock;
@@ -820,7 +818,6 @@ LockAcquireExtended(const LOCKTAG *locktag,
/*
* Find or create a LOCALLOCK entry for this lock and lockmode
*/
- MemSet(&localtag, 0, sizeof(localtag)); /* must clear padding */
localtag.lock = *locktag;
localtag.mode = lockmode;
@@ -1976,7 +1973,7 @@ LockRelease(const LOCKTAG *locktag, LOCKMODE lockmode, bool sessionLock)
{
LOCKMETHODID lockmethodid = locktag->locktag_lockmethodid;
LockMethod lockMethodTable;
- LOCALLOCKTAG localtag;
+ LOCALLOCKTAG localtag = {0};
LOCALLOCK *locallock;
LOCK *lock;
PROCLOCK *proclock;
@@ -1999,7 +1996,6 @@ LockRelease(const LOCKTAG *locktag, LOCKMODE lockmode, bool sessionLock)
/*
* Find the LOCALLOCK entry for this lock and lockmode
*/
- MemSet(&localtag, 0, sizeof(localtag)); /* must clear padding */
localtag.lock = *locktag;
localtag.mode = lockmode;
diff --git a/src/backend/storage/lmgr/lwlock.c b/src/backend/storage/lmgr/lwlock.c
index fc5c76a48f..ccaa99b453 100644
--- a/src/backend/storage/lmgr/lwlock.c
+++ b/src/backend/storage/lmgr/lwlock.c
@@ -384,7 +384,7 @@ print_lwlock_stats(int code, Datum arg)
static lwlock_stats *
get_lwlock_stats_entry(LWLock *lock)
{
- lwlock_stats_key key;
+ lwlock_stats_key key = {0};
lwlock_stats *lwstats;
bool found;
@@ -397,7 +397,6 @@ get_lwlock_stats_entry(LWLock *lock)
return &lwlock_stats_dummy;
/* Fetch or create the entry. */
- MemSet(&key, 0, sizeof(key));
key.tranche = lock->tranche;
key.instance = lock;
lwstats = hash_search(lwlock_stats_htab, &key, HASH_ENTER, &found);
diff --git a/src/backend/utils/adt/acl.c b/src/backend/utils/adt/acl.c
index b7fd3bcf05..6fa58dd8eb 100644
--- a/src/backend/utils/adt/acl.c
+++ b/src/backend/utils/adt/acl.c
@@ -1785,7 +1785,7 @@ aclexplode(PG_FUNCTION_ARGS)
{
Datum result;
Datum values[4];
- bool nulls[4];
+ bool nulls[4] = {0};
HeapTuple tuple;
values[0] = ObjectIdGetDatum(aidata->ai_grantor);
@@ -1793,8 +1793,6 @@ aclexplode(PG_FUNCTION_ARGS)
values[2] = CStringGetTextDatum(convert_aclright_to_string(priv_bit));
values[3] = BoolGetDatum((ACLITEM_GET_GOPTIONS(*aidata) & priv_bit) != 0);
- MemSet(nulls, 0, sizeof(nulls));
-
tuple = heap_form_tuple(funcctx->tuple_desc, values, nulls);
result = HeapTupleGetDatum(tuple);
diff --git a/src/backend/utils/adt/arrayfuncs.c b/src/backend/utils/adt/arrayfuncs.c
index b0c37ede87..fb167f226a 100644
--- a/src/backend/utils/adt/arrayfuncs.c
+++ b/src/backend/utils/adt/arrayfuncs.c
@@ -742,11 +742,10 @@ ReadArrayStr(char *arrayStr,
bool eoArray = false;
bool hasnull;
int32 totbytes;
- int indx[MAXDIM],
+ int indx[MAXDIM] = {0},
prod[MAXDIM];
mda_get_prod(ndim, dim, prod);
- MemSet(indx, 0, sizeof(indx));
/* Initialize is-null markers to true */
memset(nulls, true, nitems * sizeof(bool));
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 4c12c4d663..8976f4e9f7 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4924,13 +4924,13 @@ pg_timezone_abbrevs(PG_FUNCTION_ARGS)
Datum result;
HeapTuple tuple;
Datum values[3];
- bool nulls[3];
+ bool nulls[3] = {0};
const datetkn *tp;
char buffer[TOKMAXLEN + 1];
int gmtoffset;
bool is_dst;
unsigned char *p;
- struct pg_itm_in itm_in;
+ struct pg_itm_in itm_in = {0};
Interval *resInterval;
/* stuff done only on the first call of the function */
@@ -5011,8 +5011,6 @@ pg_timezone_abbrevs(PG_FUNCTION_ARGS)
break;
}
- MemSet(nulls, 0, sizeof(nulls));
-
/*
* Convert name to text, using upcasing conversion that is the inverse of
* what ParseDateTime() uses.
@@ -5024,7 +5022,6 @@ pg_timezone_abbrevs(PG_FUNCTION_ARGS)
values[0] = CStringGetTextDatum(buffer);
/* Convert offset (in seconds) to an interval; can't overflow */
- MemSet(&itm_in, 0, sizeof(struct pg_itm_in));
itm_in.tm_usec = (int64) gmtoffset * USECS_PER_SEC;
resInterval = (Interval *) palloc(sizeof(Interval));
(void) itmin2interval(&itm_in, resInterval);
@@ -5051,13 +5048,13 @@ pg_timezone_names(PG_FUNCTION_ARGS)
pg_tzenum *tzenum;
pg_tz *tz;
Datum values[4];
- bool nulls[4];
+ bool nulls[4] = {0};
int tzoff;
struct pg_tm tm;
fsec_t fsec;
const char *tzn;
Interval *resInterval;
- struct pg_itm_in itm_in;
+ struct pg_itm_in itm_in = {0};
SetSingleFuncCall(fcinfo, 0);
@@ -5088,13 +5085,10 @@ pg_timezone_names(PG_FUNCTION_ARGS)
if (tzn && strlen(tzn) > 31)
continue;
- MemSet(nulls, 0, sizeof(nulls));
-
values[0] = CStringGetTextDatum(pg_get_timezone_name(tz));
values[1] = CStringGetTextDatum(tzn ? tzn : "");
/* Convert tzoff to an interval; can't overflow */
- MemSet(&itm_in, 0, sizeof(struct pg_itm_in));
itm_in.tm_usec = (int64) -tzoff * USECS_PER_SEC;
resInterval = (Interval *) palloc(sizeof(Interval));
(void) itmin2interval(&itm_in, resInterval);
diff --git a/src/backend/utils/adt/lockfuncs.c b/src/backend/utils/adt/lockfuncs.c
index dedee7af5c..613f5f9bec 100644
--- a/src/backend/utils/adt/lockfuncs.c
+++ b/src/backend/utils/adt/lockfuncs.c
@@ -172,8 +172,8 @@ pg_lock_status(PG_FUNCTION_ARGS)
LOCKMODE mode = 0;
const char *locktypename;
char tnbuf[32];
- Datum values[NUM_LOCK_STATUS_COLUMNS];
- bool nulls[NUM_LOCK_STATUS_COLUMNS];
+ Datum values[NUM_LOCK_STATUS_COLUMNS] = {0};
+ bool nulls[NUM_LOCK_STATUS_COLUMNS] = {0};
HeapTuple tuple;
Datum result;
LockInstanceData *instance;
@@ -230,9 +230,6 @@ pg_lock_status(PG_FUNCTION_ARGS)
/*
* Form tuple with appropriate data.
*/
- MemSet(values, 0, sizeof(values));
- MemSet(nulls, false, sizeof(nulls));
-
if (instance->locktag.locktag_type <= LOCKTAG_LAST_TYPE)
locktypename = LockTagTypeNames[instance->locktag.locktag_type];
else
@@ -359,8 +356,8 @@ pg_lock_status(PG_FUNCTION_ARGS)
PREDICATELOCKTARGETTAG *predTag = &(predLockData->locktags[mystatus->predLockIdx]);
SERIALIZABLEXACT *xact = &(predLockData->xacts[mystatus->predLockIdx]);
- Datum values[NUM_LOCK_STATUS_COLUMNS];
- bool nulls[NUM_LOCK_STATUS_COLUMNS];
+ Datum values[NUM_LOCK_STATUS_COLUMNS] = {0};
+ bool nulls[NUM_LOCK_STATUS_COLUMNS] = {0};
HeapTuple tuple;
Datum result;
@@ -369,8 +366,6 @@ pg_lock_status(PG_FUNCTION_ARGS)
/*
* Form tuple with appropriate data.
*/
- MemSet(values, 0, sizeof(values));
- MemSet(nulls, false, sizeof(nulls));
/* lock type */
lockType = GET_PREDICATELOCKTARGETTAG_TYPE(*predTag);
diff --git a/src/backend/utils/adt/partitionfuncs.c b/src/backend/utils/adt/partitionfuncs.c
index 0243bc061f..109dc8023e 100644
--- a/src/backend/utils/adt/partitionfuncs.c
+++ b/src/backend/utils/adt/partitionfuncs.c
@@ -113,8 +113,8 @@ pg_partition_tree(PG_FUNCTION_ARGS)
if (funcctx->call_cntr < list_length(partitions))
{
Datum result;
- Datum values[PG_PARTITION_TREE_COLS];
- bool nulls[PG_PARTITION_TREE_COLS];
+ Datum values[PG_PARTITION_TREE_COLS] = {0};
+ bool nulls[PG_PARTITION_TREE_COLS] = {0};
HeapTuple tuple;
Oid parentid = InvalidOid;
Oid relid = list_nth_oid(partitions, funcctx->call_cntr);
@@ -126,8 +126,6 @@ pg_partition_tree(PG_FUNCTION_ARGS)
/*
* Form tuple with appropriate data.
*/
- MemSet(nulls, 0, sizeof(nulls));
- MemSet(values, 0, sizeof(values));
/* relid */
values[0] = ObjectIdGetDatum(relid);
diff --git a/src/backend/utils/adt/pgstatfuncs.c b/src/backend/utils/adt/pgstatfuncs.c
index 893690dad5..0a6369fdba 100644
--- a/src/backend/utils/adt/pgstatfuncs.c
+++ b/src/backend/utils/adt/pgstatfuncs.c
@@ -488,13 +488,10 @@ pg_stat_get_progress_info(PG_FUNCTION_ARGS)
{
LocalPgBackendStatus *local_beentry;
PgBackendStatus *beentry;
- Datum values[PG_STAT_GET_PROGRESS_COLS];
- bool nulls[PG_STAT_GET_PROGRESS_COLS];
+ Datum values[PG_STAT_GET_PROGRESS_COLS] = {0};
+ bool nulls[PG_STAT_GET_PROGRESS_COLS] = {0};
int i;
- MemSet(values, 0, sizeof(values));
- MemSet(nulls, 0, sizeof(nulls));
-
local_beentry = pgstat_fetch_stat_local_beentry(curr_backend);
if (!local_beentry)
@@ -551,17 +548,14 @@ pg_stat_get_activity(PG_FUNCTION_ARGS)
for (curr_backend = 1; curr_backend <= num_backends; curr_backend++)
{
/* for each row */
- Datum values[PG_STAT_GET_ACTIVITY_COLS];
- bool nulls[PG_STAT_GET_ACTIVITY_COLS];
+ Datum values[PG_STAT_GET_ACTIVITY_COLS] = {0};
+ bool nulls[PG_STAT_GET_ACTIVITY_COLS] = {0};
LocalPgBackendStatus *local_beentry;
PgBackendStatus *beentry;
PGPROC *proc;
const char *wait_event_type = NULL;
const char *wait_event = NULL;
- MemSet(values, 0, sizeof(values));
- MemSet(nulls, 0, sizeof(nulls));
-
/* Get the next one in the list */
local_beentry = pgstat_fetch_stat_local_beentry(curr_backend);
if (!local_beentry)
@@ -1747,15 +1741,11 @@ pg_stat_get_wal(PG_FUNCTION_ARGS)
{
#define PG_STAT_GET_WAL_COLS 9
TupleDesc tupdesc;
- Datum values[PG_STAT_GET_WAL_COLS];
- bool nulls[PG_STAT_GET_WAL_COLS];
+ Datum values[PG_STAT_GET_WAL_COLS] = {0};
+ bool nulls[PG_STAT_GET_WAL_COLS] = {0};
char buf[256];
PgStat_WalStats *wal_stats;
- /* Initialise values and NULL flags arrays */
- MemSet(values, 0, sizeof(values));
- MemSet(nulls, 0, sizeof(nulls));
-
/* Initialise attributes information in the tuple descriptor */
tupdesc = CreateTemplateTupleDesc(PG_STAT_GET_WAL_COLS);
TupleDescInitEntry(tupdesc, (AttrNumber) 1, "wal_records",
@@ -1827,7 +1817,7 @@ pg_stat_get_slru(PG_FUNCTION_ARGS)
{
/* for each row */
Datum values[PG_STAT_GET_SLRU_COLS];
- bool nulls[PG_STAT_GET_SLRU_COLS];
+ bool nulls[PG_STAT_GET_SLRU_COLS] = {0};
PgStat_SLRUStats stat;
const char *name;
@@ -1837,8 +1827,6 @@ pg_stat_get_slru(PG_FUNCTION_ARGS)
break;
stat = stats[i];
- MemSet(values, 0, sizeof(values));
- MemSet(nulls, 0, sizeof(nulls));
values[0] = PointerGetDatum(cstring_to_text(name));
values[1] = Int64GetDatum(stat.blocks_zeroed);
@@ -2201,14 +2189,10 @@ Datum
pg_stat_get_archiver(PG_FUNCTION_ARGS)
{
TupleDesc tupdesc;
- Datum values[7];
- bool nulls[7];
+ Datum values[7] = {0};
+ bool nulls[7] = {0};
PgStat_ArchiverStats *archiver_stats;
- /* Initialise values and NULL flags arrays */
- MemSet(values, 0, sizeof(values));
- MemSet(nulls, 0, sizeof(nulls));
-
/* Initialise attributes information in the tuple descriptor */
tupdesc = CreateTemplateTupleDesc(7);
TupleDescInitEntry(tupdesc, (AttrNumber) 1, "archived_count",
@@ -2274,15 +2258,11 @@ pg_stat_get_replication_slot(PG_FUNCTION_ARGS)
text *slotname_text = PG_GETARG_TEXT_P(0);
NameData slotname;
TupleDesc tupdesc;
- Datum values[PG_STAT_GET_REPLICATION_SLOT_COLS];
- bool nulls[PG_STAT_GET_REPLICATION_SLOT_COLS];
+ Datum values[PG_STAT_GET_REPLICATION_SLOT_COLS] = {0};
+ bool nulls[PG_STAT_GET_REPLICATION_SLOT_COLS] = {0};
PgStat_StatReplSlotEntry *slotent;
PgStat_StatReplSlotEntry allzero;
- /* Initialise values and NULL flags arrays */
- MemSet(values, 0, sizeof(values));
- MemSet(nulls, 0, sizeof(nulls));
-
/* Initialise attributes information in the tuple descriptor */
tupdesc = CreateTemplateTupleDesc(PG_STAT_GET_REPLICATION_SLOT_COLS);
TupleDescInitEntry(tupdesc, (AttrNumber) 1, "slot_name",
@@ -2348,8 +2328,8 @@ pg_stat_get_subscription_stats(PG_FUNCTION_ARGS)
#define PG_STAT_GET_SUBSCRIPTION_STATS_COLS 4
Oid subid = PG_GETARG_OID(0);
TupleDesc tupdesc;
- Datum values[PG_STAT_GET_SUBSCRIPTION_STATS_COLS];
- bool nulls[PG_STAT_GET_SUBSCRIPTION_STATS_COLS];
+ Datum values[PG_STAT_GET_SUBSCRIPTION_STATS_COLS] = {0};
+ bool nulls[PG_STAT_GET_SUBSCRIPTION_STATS_COLS] = {0};
PgStat_StatSubEntry *subentry;
PgStat_StatSubEntry allzero;
@@ -2368,10 +2348,6 @@ pg_stat_get_subscription_stats(PG_FUNCTION_ARGS)
TIMESTAMPTZOID, -1, 0);
BlessTupleDesc(tupdesc);
- /* Initialise values and NULL flags arrays */
- MemSet(values, 0, sizeof(values));
- MemSet(nulls, 0, sizeof(nulls));
-
if (!subentry)
{
/* If the subscription is not found, initialise its stats */
diff --git a/src/backend/utils/adt/selfuncs.c b/src/backend/utils/adt/selfuncs.c
index fa1f589fad..6f99b5b243 100644
--- a/src/backend/utils/adt/selfuncs.c
+++ b/src/backend/utils/adt/selfuncs.c
@@ -6642,10 +6642,10 @@ btcostestimate(PlannerInfo *root, IndexPath *path, double loop_count,
double *indexPages)
{
IndexOptInfo *index = path->indexinfo;
- GenericCosts costs;
+ GenericCosts costs = {0};
Oid relid;
AttrNumber colnum;
- VariableStatData vardata;
+ VariableStatData vardata = {0};
double numIndexTuples;
Cost descentCost;
List *indexBoundQuals;
@@ -6797,7 +6797,6 @@ btcostestimate(PlannerInfo *root, IndexPath *path, double loop_count,
/*
* Now do generic index cost estimation.
*/
- MemSet(&costs, 0, sizeof(costs));
costs.numIndexTuples = numIndexTuples;
genericcostestimate(root, path, loop_count, &costs);
@@ -6842,8 +6841,6 @@ btcostestimate(PlannerInfo *root, IndexPath *path, double loop_count,
* ordering, but don't negate it entirely. Before 8.0 we divided the
* correlation by the number of columns, but that seems too strong.)
*/
- MemSet(&vardata, 0, sizeof(vardata));
-
if (index->indexkeys[0] != 0)
{
/* Simple variable --- look to stats for the underlying table */
@@ -6947,9 +6944,7 @@ hashcostestimate(PlannerInfo *root, IndexPath *path, double loop_count,
Selectivity *indexSelectivity, double *indexCorrelation,
double *indexPages)
{
- GenericCosts costs;
-
- MemSet(&costs, 0, sizeof(costs));
+ GenericCosts costs = {0};
genericcostestimate(root, path, loop_count, &costs);
@@ -6992,11 +6987,9 @@ gistcostestimate(PlannerInfo *root, IndexPath *path, double loop_count,
double *indexPages)
{
IndexOptInfo *index = path->indexinfo;
- GenericCosts costs;
+ GenericCosts costs = {0};
Cost descentCost;
- MemSet(&costs, 0, sizeof(costs));
-
genericcostestimate(root, path, loop_count, &costs);
/*
@@ -7049,11 +7042,9 @@ spgcostestimate(PlannerInfo *root, IndexPath *path, double loop_count,
double *indexPages)
{
IndexOptInfo *index = path->indexinfo;
- GenericCosts costs;
+ GenericCosts costs = {0};
Cost descentCost;
- MemSet(&costs, 0, sizeof(costs));
-
genericcostestimate(root, path, loop_count, &costs);
/*
diff --git a/src/backend/utils/adt/timestamp.c b/src/backend/utils/adt/timestamp.c
index f70f829d83..0a17f45e92 100644
--- a/src/backend/utils/adt/timestamp.c
+++ b/src/backend/utils/adt/timestamp.c
@@ -2403,7 +2403,7 @@ interval_cmp_value(const Interval *interval)
}
static int
-interval_cmp_internal(Interval *interval1, Interval *interval2)
+interval_cmp_internal(const Interval *interval1, const Interval *interval2)
{
INT128 span1 = interval_cmp_value(interval1);
INT128 span2 = interval_cmp_value(interval2);
@@ -5777,7 +5777,7 @@ generate_series_timestamp(PG_FUNCTION_ARGS)
Timestamp finish = PG_GETARG_TIMESTAMP(1);
Interval *step = PG_GETARG_INTERVAL_P(2);
MemoryContext oldcontext;
- Interval interval_zero;
+ Interval interval_zero = {0};
/* create a function context for cross-call persistence */
funcctx = SRF_FIRSTCALL_INIT();
@@ -5800,7 +5800,6 @@ generate_series_timestamp(PG_FUNCTION_ARGS)
fctx->step = *step;
/* Determine sign of the interval */
- MemSet(&interval_zero, 0, sizeof(Interval));
fctx->step_sign = interval_cmp_internal(&fctx->step, &interval_zero);
if (fctx->step_sign == 0)
@@ -5857,7 +5856,7 @@ generate_series_timestamptz(PG_FUNCTION_ARGS)
TimestampTz finish = PG_GETARG_TIMESTAMPTZ(1);
Interval *step = PG_GETARG_INTERVAL_P(2);
MemoryContext oldcontext;
- Interval interval_zero;
+ Interval interval_zero = {0};
/* create a function context for cross-call persistence */
funcctx = SRF_FIRSTCALL_INIT();
@@ -5880,7 +5879,6 @@ generate_series_timestamptz(PG_FUNCTION_ARGS)
fctx->step = *step;
/* Determine sign of the interval */
- MemSet(&interval_zero, 0, sizeof(Interval));
fctx->step_sign = interval_cmp_internal(&fctx->step, &interval_zero);
if (fctx->step_sign == 0)
diff --git a/src/backend/utils/adt/tsrank.c b/src/backend/utils/adt/tsrank.c
index 3858fc5928..7d78219b62 100644
--- a/src/backend/utils/adt/tsrank.c
+++ b/src/backend/utils/adt/tsrank.c
@@ -853,7 +853,7 @@ calc_rank_cd(const float4 *arrdata, TSVector txt, TSQuery query, int method)
int len,
i,
doclen = 0;
- CoverExt ext;
+ CoverExt ext = {0};
double Wdoc = 0.0;
double invws[lengthof(weights)];
double SumDist = 0.0,
@@ -883,7 +883,6 @@ calc_rank_cd(const float4 *arrdata, TSVector txt, TSQuery query, int method)
return 0.0;
}
- MemSet(&ext, 0, sizeof(CoverExt));
while (Cover(doc, doclen, &qr, &ext))
{
double Cpos = 0.0;
diff --git a/src/backend/utils/cache/relfilenumbermap.c b/src/backend/utils/cache/relfilenumbermap.c
index c4245d5ccd..ada0efa8f2 100644
--- a/src/backend/utils/cache/relfilenumbermap.c
+++ b/src/backend/utils/cache/relfilenumbermap.c
@@ -143,7 +143,7 @@ RelidByRelfilenumber(Oid reltablespace, RelFileNumber relfilenumber)
SysScanDesc scandesc;
Relation relation;
HeapTuple ntp;
- ScanKeyData skey[2];
+ ScanKeyData skey[2] = {0};
Oid relid;
if (RelfilenumberMapHash == NULL)
@@ -153,7 +153,6 @@ RelidByRelfilenumber(Oid reltablespace, RelFileNumber relfilenumber)
if (reltablespace == MyDatabaseTableSpace)
reltablespace = 0;
- MemSet(&key, 0, sizeof(key));
key.reltablespace = reltablespace;
key.relfilenumber = relfilenumber;
diff --git a/src/backend/utils/cache/ts_cache.c b/src/backend/utils/cache/ts_cache.c
index 24808dfbb1..70e88fd228 100644
--- a/src/backend/utils/cache/ts_cache.c
+++ b/src/backend/utils/cache/ts_cache.c
@@ -414,7 +414,7 @@ lookup_ts_config_cache(Oid cfgId)
ScanKeyData mapskey;
SysScanDesc mapscan;
HeapTuple maptup;
- ListDictionary maplists[MAXTOKENTYPE + 1];
+ ListDictionary maplists[MAXTOKENTYPE + 1] = {0};
Oid mapdicts[MAXDICTSPERTT];
int maxtokentype;
int ndicts;
@@ -468,7 +468,6 @@ lookup_ts_config_cache(Oid cfgId)
* see the entries in maptokentype order, and in mapseqno order for
* each token type, even though we didn't explicitly ask for that.
*/
- MemSet(maplists, 0, sizeof(maplists));
maxtokentype = 0;
ndicts = 0;
diff --git a/src/backend/utils/misc/ps_status.c b/src/backend/utils/misc/ps_status.c
index ec314c03f5..ca05b180c9 100644
--- a/src/backend/utils/misc/ps_status.c
+++ b/src/backend/utils/misc/ps_status.c
@@ -393,7 +393,7 @@ set_ps_display(const char *activity)
#ifdef PS_USE_CLOBBER_ARGV
/* pad unused memory; need only clobber remainder of old status string */
if (last_status_len > ps_buffer_cur_len)
- MemSet(ps_buffer + ps_buffer_cur_len, PS_PADDING,
+ memset(ps_buffer + ps_buffer_cur_len, PS_PADDING,
last_status_len - ps_buffer_cur_len);
last_status_len = ps_buffer_cur_len;
#endif /* PS_USE_CLOBBER_ARGV */
diff --git a/src/backend/utils/misc/timeout.c b/src/backend/utils/misc/timeout.c
index 6f5e08bc30..284b9153ea 100644
--- a/src/backend/utils/misc/timeout.c
+++ b/src/backend/utils/misc/timeout.c
@@ -211,13 +211,11 @@ schedule_alarm(TimestampTz now)
{
if (num_active_timeouts > 0)
{
- struct itimerval timeval;
+ struct itimerval timeval = {0};
TimestampTz nearest_timeout;
long secs;
int usecs;
- MemSet(&timeval, 0, sizeof(struct itimerval));
-
/*
* If we think there's a signal pending, but current time is more than
* 10ms past when the signal was due, then assume that the timeout
diff --git a/src/backend/utils/mmgr/portalmem.c b/src/backend/utils/mmgr/portalmem.c
index d549f66d4a..3a161bdb88 100644
--- a/src/backend/utils/mmgr/portalmem.c
+++ b/src/backend/utils/mmgr/portalmem.c
@@ -1146,14 +1146,12 @@ pg_cursor(PG_FUNCTION_ARGS)
{
Portal portal = hentry->portal;
Datum values[6];
- bool nulls[6];
+ bool nulls[6] = {0};
/* report only "visible" entries */
if (!portal->visible)
continue;
- MemSet(nulls, 0, sizeof(nulls));
-
values[0] = CStringGetTextDatum(portal->name);
values[1] = CStringGetTextDatum(portal->sourceText);
values[2] = BoolGetDatum(portal->cursorOptions & CURSOR_OPT_HOLD);
diff --git a/src/bin/pg_basebackup/pg_basebackup.c b/src/bin/pg_basebackup/pg_basebackup.c
index 4445a86aee..79b23fa7d7 100644
--- a/src/bin/pg_basebackup/pg_basebackup.c
+++ b/src/bin/pg_basebackup/pg_basebackup.c
@@ -447,7 +447,7 @@ reached_end_position(XLogRecPtr segendpos, uint32 timeline,
{
#ifndef WIN32
fd_set fds;
- struct timeval tv;
+ struct timeval tv = {0};
int r;
/*
@@ -457,16 +457,13 @@ reached_end_position(XLogRecPtr segendpos, uint32 timeline,
FD_ZERO(&fds);
FD_SET(bgpipe[0], &fds);
- MemSet(&tv, 0, sizeof(tv));
-
r = select(bgpipe[0] + 1, &fds, NULL, NULL, &tv);
if (r == 1)
{
- char xlogend[64];
+ char xlogend[64] = {0};
uint32 hi,
lo;
- MemSet(xlogend, 0, sizeof(xlogend));
r = read(bgpipe[0], xlogend, sizeof(xlogend) - 1);
if (r < 0)
pg_fatal("could not read from ready pipe: %m");
@@ -528,11 +525,10 @@ typedef struct
static int
LogStreamerMain(logstreamer_param *param)
{
- StreamCtl stream;
+ StreamCtl stream = {0};
in_log_streamer = true;
- MemSet(&stream, 0, sizeof(stream));
stream.startpos = param->startptr;
stream.timeline = param->timeline;
stream.sysidentifier = param->sysidentifier;
@@ -1952,7 +1948,6 @@ BaseBackup(char *compression_algorithm, char *compression_detail,
else
starttli = latesttli;
PQclear(res);
- MemSet(xlogend, 0, sizeof(xlogend));
if (verbose && includewal != NO_WAL)
pg_log_info("write-ahead log start point: %s on timeline %u",
diff --git a/src/bin/pg_basebackup/pg_receivewal.c b/src/bin/pg_basebackup/pg_receivewal.c
index ea3902c971..f064cff4ab 100644
--- a/src/bin/pg_basebackup/pg_receivewal.c
+++ b/src/bin/pg_basebackup/pg_receivewal.c
@@ -564,11 +564,9 @@ StreamLog(void)
{
XLogRecPtr serverpos;
TimeLineID servertli;
- StreamCtl stream;
+ StreamCtl stream = {0};
char *sysidentifier;
- MemSet(&stream, 0, sizeof(stream));
-
/*
* Connect in replication mode to the server
*/
diff --git a/src/bin/pg_basebackup/walmethods.c b/src/bin/pg_basebackup/walmethods.c
index ef4c11277a..e90aa0ba37 100644
--- a/src/bin/pg_basebackup/walmethods.c
+++ b/src/bin/pg_basebackup/walmethods.c
@@ -1111,9 +1111,8 @@ tar_close(Walfile f, WalCloseMethod method)
padding = tarPaddingBytesRequired(filesize);
if (padding)
{
- char zerobuf[TAR_BLOCK_SIZE];
+ char zerobuf[TAR_BLOCK_SIZE] = {0};
- MemSet(zerobuf, 0, padding);
if (tar_write(f, zerobuf, padding) != padding)
return -1;
}
@@ -1222,7 +1221,7 @@ tar_existsfile(const char *pathname)
static bool
tar_finish(void)
{
- char zerobuf[1024];
+ char zerobuf[1024] = {0};
tar_clear_error();
@@ -1233,7 +1232,6 @@ tar_finish(void)
}
/* A tarfile always ends with two empty blocks */
- MemSet(zerobuf, 0, sizeof(zerobuf));
if (tar_data->compression_algorithm == PG_COMPRESSION_NONE)
{
errno = 0;
diff --git a/src/common/ip.c b/src/common/ip.c
index cd73d49679..267103efb9 100644
--- a/src/common/ip.c
+++ b/src/common/ip.c
@@ -165,14 +165,12 @@ static int
getaddrinfo_unix(const char *path, const struct addrinfo *hintsp,
struct addrinfo **result)
{
- struct addrinfo hints;
+ struct addrinfo hints = {0};
struct addrinfo *aip;
struct sockaddr_un *unp;
*result = NULL;
- MemSet(&hints, 0, sizeof(hints));
-
if (strlen(path) >= sizeof(unp->sun_path))
return EAI_FAIL;
diff --git a/src/interfaces/libpq/fe-connect.c b/src/interfaces/libpq/fe-connect.c
index dc49387d6c..0362500386 100644
--- a/src/interfaces/libpq/fe-connect.c
+++ b/src/interfaces/libpq/fe-connect.c
@@ -2325,7 +2325,7 @@ keep_going: /* We will come back to here until there is
if (conn->try_next_host)
{
pg_conn_host *ch;
- struct addrinfo hint;
+ struct addrinfo hint = {0};
int thisport;
int ret;
char portstr[MAXPGPATH];
@@ -2364,7 +2364,6 @@ keep_going: /* We will come back to here until there is
ch = &conn->connhost[conn->whichhost];
/* Initialize hint structure */
- MemSet(&hint, 0, sizeof(hint));
hint.ai_socktype = SOCK_STREAM;
conn->addrlist_family = hint.ai_family = AF_UNSPEC;
diff --git a/src/pl/plperl/plperl.c b/src/pl/plperl/plperl.c
index edb93ec1c4..6272e093c5 100644
--- a/src/pl/plperl/plperl.c
+++ b/src/pl/plperl/plperl.c
@@ -1841,10 +1841,9 @@ plperl_call_handler(PG_FUNCTION_ARGS)
Datum retval = (Datum) 0;
plperl_call_data *volatile save_call_data = current_call_data;
plperl_interp_desc *volatile oldinterp = plperl_active_interp;
- plperl_call_data this_call_data;
+ plperl_call_data this_call_data = {0};
/* Initialize current-call status record */
- MemSet(&this_call_data, 0, sizeof(this_call_data));
this_call_data.fcinfo = fcinfo;
PG_TRY();
@@ -1882,16 +1881,13 @@ plperl_inline_handler(PG_FUNCTION_ARGS)
{
LOCAL_FCINFO(fake_fcinfo, 0);
InlineCodeBlock *codeblock = (InlineCodeBlock *) PG_GETARG_POINTER(0);
- FmgrInfo flinfo;
- plperl_proc_desc desc;
+ FmgrInfo flinfo = {0};
+ plperl_proc_desc desc = {0};
plperl_call_data *volatile save_call_data = current_call_data;
plperl_interp_desc *volatile oldinterp = plperl_active_interp;
- plperl_call_data this_call_data;
+ plperl_call_data this_call_data = {0};
ErrorContextCallback pl_error_context;
- /* Initialize current-call status record */
- MemSet(&this_call_data, 0, sizeof(this_call_data));
-
/* Set up a callback for error reporting */
pl_error_context.callback = plperl_inline_callback;
pl_error_context.previous = error_context_stack;
@@ -1904,8 +1900,6 @@ plperl_inline_handler(PG_FUNCTION_ARGS)
* with no arguments passed, and a result type of VOID.
*/
MemSet(fake_fcinfo, 0, SizeForFunctionCallInfo(0));
- MemSet(&flinfo, 0, sizeof(flinfo));
- MemSet(&desc, 0, sizeof(desc));
fake_fcinfo->flinfo = &flinfo;
flinfo.fn_oid = InvalidOid;
flinfo.fn_mcxt = CurrentMemoryContext;
diff --git a/src/pl/plpgsql/src/pl_handler.c b/src/pl/plpgsql/src/pl_handler.c
index 190d286f1c..1f8c9edfa8 100644
--- a/src/pl/plpgsql/src/pl_handler.c
+++ b/src/pl/plpgsql/src/pl_handler.c
@@ -317,7 +317,7 @@ plpgsql_inline_handler(PG_FUNCTION_ARGS)
LOCAL_FCINFO(fake_fcinfo, 0);
InlineCodeBlock *codeblock = castNode(InlineCodeBlock, DatumGetPointer(PG_GETARG_DATUM(0)));
PLpgSQL_function *func;
- FmgrInfo flinfo;
+ FmgrInfo flinfo = {0};
EState *simple_eval_estate;
ResourceOwner simple_eval_resowner;
Datum retval;
@@ -341,7 +341,6 @@ plpgsql_inline_handler(PG_FUNCTION_ARGS)
* with no arguments passed.
*/
MemSet(fake_fcinfo, 0, SizeForFunctionCallInfo(0));
- MemSet(&flinfo, 0, sizeof(flinfo));
fake_fcinfo->flinfo = &flinfo;
flinfo.fn_oid = InvalidOid;
flinfo.fn_mcxt = CurrentMemoryContext;
@@ -502,10 +501,10 @@ plpgsql_validator(PG_FUNCTION_ARGS)
if (check_function_bodies)
{
LOCAL_FCINFO(fake_fcinfo, 0);
- FmgrInfo flinfo;
+ FmgrInfo flinfo = {0};
int rc;
- TriggerData trigdata;
- EventTriggerData etrigdata;
+ TriggerData trigdata = {0};
+ EventTriggerData etrigdata = {0};
/*
* Connect to SPI manager (is this needed for compilation?)
@@ -518,19 +517,16 @@ plpgsql_validator(PG_FUNCTION_ARGS)
* plpgsql_compile().
*/
MemSet(fake_fcinfo, 0, SizeForFunctionCallInfo(0));
- MemSet(&flinfo, 0, sizeof(flinfo));
fake_fcinfo->flinfo = &flinfo;
flinfo.fn_oid = funcoid;
flinfo.fn_mcxt = CurrentMemoryContext;
if (is_dml_trigger)
{
- MemSet(&trigdata, 0, sizeof(trigdata));
trigdata.type = T_TriggerData;
fake_fcinfo->context = (Node *) &trigdata;
}
else if (is_event_trigger)
{
- MemSet(&etrigdata, 0, sizeof(etrigdata));
etrigdata.type = T_EventTriggerData;
fake_fcinfo->context = (Node *) &etrigdata;
}
diff --git a/src/pl/plpython/plpy_main.c b/src/pl/plpython/plpy_main.c
index 0bce106495..1df2dd536c 100644
--- a/src/pl/plpython/plpy_main.c
+++ b/src/pl/plpython/plpy_main.c
@@ -266,8 +266,8 @@ plpython3_inline_handler(PG_FUNCTION_ARGS)
{
LOCAL_FCINFO(fake_fcinfo, 0);
InlineCodeBlock *codeblock = (InlineCodeBlock *) DatumGetPointer(PG_GETARG_DATUM(0));
- FmgrInfo flinfo;
- PLyProcedure proc;
+ FmgrInfo flinfo = {0};
+ PLyProcedure proc = {0};
PLyExecutionContext *exec_ctx;
ErrorContextCallback plerrcontext;
@@ -278,12 +278,10 @@ plpython3_inline_handler(PG_FUNCTION_ARGS)
elog(ERROR, "SPI_connect failed");
MemSet(fcinfo, 0, SizeForFunctionCallInfo(0));
- MemSet(&flinfo, 0, sizeof(flinfo));
fake_fcinfo->flinfo = &flinfo;
flinfo.fn_oid = InvalidOid;
flinfo.fn_mcxt = CurrentMemoryContext;
- MemSet(&proc, 0, sizeof(PLyProcedure));
proc.mcxt = AllocSetContextCreate(TopMemoryContext,
"__plpython_inline_block",
ALLOCSET_DEFAULT_SIZES);
diff --git a/src/port/snprintf.c b/src/port/snprintf.c
index abb1c59770..d4cf368075 100644
--- a/src/port/snprintf.c
+++ b/src/port/snprintf.c
@@ -756,12 +756,10 @@ find_arguments(const char *format, va_list args,
int longflag;
int fmtpos;
int i;
- int last_dollar;
- PrintfArgType argtypes[PG_NL_ARGMAX + 1];
/* Initialize to "no dollar arguments known" */
- last_dollar = 0;
- MemSet(argtypes, 0, sizeof(argtypes));
+ int last_dollar = 0;
+ PrintfArgType argtypes[PG_NL_ARGMAX + 1] = {0};
/*
* This loop must accept the same format strings as the one in dopr().
diff --git a/src/test/modules/test_predtest/test_predtest.c b/src/test/modules/test_predtest/test_predtest.c
index 3b19e0eadc..2ce88cb624 100644
--- a/src/test/modules/test_predtest/test_predtest.c
+++ b/src/test/modules/test_predtest/test_predtest.c
@@ -50,7 +50,7 @@ test_predtest(PG_FUNCTION_ARGS)
strong_refuted_by,
weak_refuted_by;
Datum values[8];
- bool nulls[8];
+ bool nulls[8] = {0};
int i;
/* We use SPI to parse, plan, and execute the test query */
@@ -204,7 +204,6 @@ test_predtest(PG_FUNCTION_ARGS)
"w_r_holds", BOOLOID, -1, 0);
tupdesc = BlessTupleDesc(tupdesc);
- MemSet(nulls, 0, sizeof(nulls));
values[0] = BoolGetDatum(strong_implied_by);
values[1] = BoolGetDatum(weak_implied_by);
values[2] = BoolGetDatum(strong_refuted_by);
diff --git a/src/test/regress/regress.c b/src/test/regress/regress.c
index ba3532a51e..b88d70b6fc 100644
--- a/src/test/regress/regress.c
+++ b/src/test/regress/regress.c
@@ -1110,7 +1110,7 @@ test_enc_conversion(PG_FUNCTION_ARGS)
int convertedbytes;
int dstlen;
Datum values[2];
- bool nulls[2];
+ bool nulls[2] = {0};
HeapTuple tuple;
if (src_encoding < 0)
@@ -1199,7 +1199,6 @@ test_enc_conversion(PG_FUNCTION_ARGS)
pfree(dst);
}
- MemSet(nulls, 0, sizeof(nulls));
values[0] = Int32GetDatum(convertedbytes);
values[1] = PointerGetDatum(retval);
tuple = heap_form_tuple(tupdesc, values, nulls);
diff --git a/src/tools/msvc/MSBuildProject.pm b/src/tools/msvc/MSBuildProject.pm
index f24d9e5348..5e2a300127 100644
--- a/src/tools/msvc/MSBuildProject.pm
+++ b/src/tools/msvc/MSBuildProject.pm
@@ -331,7 +331,7 @@ sub WriteItemDefinitionGroup
<ObjectFileName>.\\$cfgname\\$self->{name}\\</ObjectFileName>
<ProgramDataBaseFileName>.\\$cfgname\\$self->{name}\\</ProgramDataBaseFileName>
<BrowseInformation>false</BrowseInformation>
- <WarningLevel>Level3</WarningLevel>
+ <WarningLevel>Level4</WarningLevel>
<SuppressStartupBanner>true</SuppressStartupBanner>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
<CompileAs>Default</CompileAs>
On 07.07.22 13:16, Alvaro Herrera wrote:
On 2022-Jul-07, Peter Eisentraut wrote:
diff --git a/src/bin/pg_basebackup/pg_basebackup.c b/src/bin/pg_basebackup/pg_basebackup.c index 4445a86aee..79b23fa7d7 100644 --- a/src/bin/pg_basebackup/pg_basebackup.c +++ b/src/bin/pg_basebackup/pg_basebackup.c@@ -1952,7 +1948,6 @@ BaseBackup(char *compression_algorithm, char *compression_detail,
else
starttli = latesttli;
PQclear(res);
- MemSet(xlogend, 0, sizeof(xlogend));if (verbose && includewal != NO_WAL)
pg_log_info("write-ahead log start point: %s on timeline %u",You removed the MemSet here, but there's no corresponding
initialization.
Maybe that was an oversight by me, but it seems to me that that
initialization was useless anyway, since xlogend is later
unconditionally overwritten anyway.
diff --git a/src/port/snprintf.c b/src/port/snprintf.c index abb1c59770..e646b0e642 100644 --- a/src/port/snprintf.c +++ b/src/port/snprintf.c @@ -756,12 +756,9 @@ find_arguments(const char *format, va_list args, int longflag; int fmtpos; int i; - int last_dollar; - PrintfArgType argtypes[PG_NL_ARGMAX + 1]; - /* Initialize to "no dollar arguments known" */ - last_dollar = 0; - MemSet(argtypes, 0, sizeof(argtypes)); + int last_dollar = 0; + PrintfArgType argtypes[PG_NL_ARGMAX + 1] = {0};pgindent will insert a blank line before the comment, which I personally
find quite ugly (because it splits the block of declarations).
Yeah. I think I can convert that to an end-of-line comment instead.
Em qui., 7 de jul. de 2022 às 14:01, Ranier Vilela <ranier.vf@gmail.com>
escreveu:
Attached the v1 of your patch.
I think that all is safe to switch MemSet by {0}.
Here the rebased patch v2, against latest head.
regards,
Ranier Vilela
Attachments:
v2-0001-WIP-Replace-MemSet-calls-with-struct-initialization.patchapplication/octet-stream; name=v2-0001-WIP-Replace-MemSet-calls-with-struct-initialization.patchDownload
diff --git a/contrib/amcheck/verify_heapam.c b/contrib/amcheck/verify_heapam.c
index e488f5e234..4cd4354278 100644
--- a/contrib/amcheck/verify_heapam.c
+++ b/contrib/amcheck/verify_heapam.c
@@ -554,17 +554,15 @@ report_corruption_internal(Tuplestorestate *tupstore, TupleDesc tupdesc,
BlockNumber blkno, OffsetNumber offnum,
AttrNumber attnum, char *msg)
{
- Datum values[HEAPCHECK_RELATION_COLS];
- bool nulls[HEAPCHECK_RELATION_COLS];
+ Datum values[HEAPCHECK_RELATION_COLS] = {0};
+ bool nulls[HEAPCHECK_RELATION_COLS] = {0};
HeapTuple tuple;
- MemSet(values, 0, sizeof(values));
- MemSet(nulls, 0, sizeof(nulls));
values[0] = Int64GetDatum(blkno);
values[1] = Int32GetDatum(offnum);
values[2] = Int32GetDatum(attnum);
- nulls[2] = (attnum < 0);
values[3] = CStringGetTextDatum(msg);
+ nulls[2] = (attnum < 0);
/*
* In principle, there is nothing to prevent a scan over a large, highly
diff --git a/contrib/bloom/blcost.c b/contrib/bloom/blcost.c
index d42e4e9628..d4b1c76303 100644
--- a/contrib/bloom/blcost.c
+++ b/contrib/bloom/blcost.c
@@ -26,9 +26,7 @@ blcostestimate(PlannerInfo *root, IndexPath *path, double loop_count,
double *indexPages)
{
IndexOptInfo *index = path->indexinfo;
- GenericCosts costs;
-
- MemSet(&costs, 0, sizeof(costs));
+ GenericCosts costs = {0};
/* We have to visit all index tuples anyway */
costs.numIndexTuples = index->tuples;
diff --git a/contrib/pageinspect/brinfuncs.c b/contrib/pageinspect/brinfuncs.c
index 879276e6de..f4c959ecab 100644
--- a/contrib/pageinspect/brinfuncs.c
+++ b/contrib/pageinspect/brinfuncs.c
@@ -202,7 +202,7 @@ brin_page_items(PG_FUNCTION_ARGS)
for (;;)
{
Datum values[7];
- bool nulls[7];
+ bool nulls[7] = {0};
/*
* This loop is called once for every attribute of every tuple in the
@@ -230,8 +230,6 @@ brin_page_items(PG_FUNCTION_ARGS)
else
attno++;
- MemSet(nulls, 0, sizeof(nulls));
-
if (unusedItem)
{
values[0] = UInt16GetDatum(offset);
@@ -334,7 +332,7 @@ brin_metapage_info(PG_FUNCTION_ARGS)
BrinMetaPageData *meta;
TupleDesc tupdesc;
Datum values[4];
- bool nulls[4];
+ bool nulls[4] = {0};
HeapTuple htup;
if (!superuser())
@@ -354,7 +352,6 @@ brin_metapage_info(PG_FUNCTION_ARGS)
/* Extract values from the metapage */
meta = (BrinMetaPageData *) PageGetContents(page);
- MemSet(nulls, 0, sizeof(nulls));
values[0] = CStringGetTextDatum(psprintf("0x%08X", meta->brinMagic));
values[1] = Int32GetDatum(meta->brinVersion);
values[2] = Int32GetDatum(meta->pagesPerRange);
diff --git a/contrib/pageinspect/hashfuncs.c b/contrib/pageinspect/hashfuncs.c
index 5287dbe1a3..81815392d7 100644
--- a/contrib/pageinspect/hashfuncs.c
+++ b/contrib/pageinspect/hashfuncs.c
@@ -238,7 +238,7 @@ hash_page_stats(PG_FUNCTION_ARGS)
Page page;
int j;
Datum values[9];
- bool nulls[9];
+ bool nulls[9] = {0};
HashPageStat stat;
HeapTuple tuple;
TupleDesc tupleDesc;
@@ -261,8 +261,6 @@ hash_page_stats(PG_FUNCTION_ARGS)
elog(ERROR, "return type must be a row type");
tupleDesc = BlessTupleDesc(tupleDesc);
- MemSet(nulls, 0, sizeof(nulls));
-
j = 0;
values[j++] = Int32GetDatum(stat.live_items);
values[j++] = Int32GetDatum(stat.dead_items);
@@ -303,7 +301,7 @@ hash_page_items(PG_FUNCTION_ARGS)
Page page;
Datum result;
Datum values[3];
- bool nulls[3];
+ bool nulls[3] = {0};
uint32 hashkey;
HeapTuple tuple;
FuncCallContext *fctx;
@@ -361,8 +359,6 @@ hash_page_items(PG_FUNCTION_ARGS)
itup = (IndexTuple) PageGetItem(uargs->page, id);
- MemSet(nulls, 0, sizeof(nulls));
-
j = 0;
values[j++] = Int32GetDatum((int32) uargs->offset);
values[j++] = PointerGetDatum(&itup->t_tid);
@@ -409,7 +405,7 @@ hash_bitmap_info(PG_FUNCTION_ARGS)
int i,
j;
Datum values[3];
- bool nulls[3];
+ bool nulls[3] = {0};
uint32 *freep;
if (!superuser())
@@ -495,8 +491,6 @@ hash_bitmap_info(PG_FUNCTION_ARGS)
elog(ERROR, "return type must be a row type");
tupleDesc = BlessTupleDesc(tupleDesc);
- MemSet(nulls, 0, sizeof(nulls));
-
j = 0;
values[j++] = Int64GetDatum((int64) bitmapblkno);
values[j++] = Int32GetDatum(bitmapbit);
@@ -526,7 +520,7 @@ hash_metapage_info(PG_FUNCTION_ARGS)
int i,
j;
Datum values[16];
- bool nulls[16];
+ bool nulls[16] = {0};
Datum spares[HASH_MAX_SPLITPOINTS];
Datum mapp[HASH_MAX_BITMAPS];
@@ -544,8 +538,6 @@ hash_metapage_info(PG_FUNCTION_ARGS)
metad = HashPageGetMeta(page);
- MemSet(nulls, 0, sizeof(nulls));
-
j = 0;
values[j++] = Int64GetDatum((int64) metad->hashm_magic);
values[j++] = Int64GetDatum((int64) metad->hashm_version);
diff --git a/contrib/pageinspect/heapfuncs.c b/contrib/pageinspect/heapfuncs.c
index a654234c6b..952f5ed57e 100644
--- a/contrib/pageinspect/heapfuncs.c
+++ b/contrib/pageinspect/heapfuncs.c
@@ -181,13 +181,11 @@ heap_page_items(PG_FUNCTION_ARGS)
Datum result;
ItemId id;
Datum values[14];
- bool nulls[14];
+ bool nulls[14] = {0};
uint16 lp_offset;
uint16 lp_flags;
uint16 lp_len;
- memset(nulls, 0, sizeof(nulls));
-
/* Extract information from the line pointer */
id = PageGetItemId(page, inter_call_data->offset);
@@ -507,8 +505,8 @@ Datum
heap_tuple_infomask_flags(PG_FUNCTION_ARGS)
{
#define HEAP_TUPLE_INFOMASK_COLS 2
- Datum values[HEAP_TUPLE_INFOMASK_COLS];
- bool nulls[HEAP_TUPLE_INFOMASK_COLS];
+ Datum values[HEAP_TUPLE_INFOMASK_COLS] = {0};
+ bool nulls[HEAP_TUPLE_INFOMASK_COLS] = {0};
uint16 t_infomask = PG_GETARG_INT16(0);
uint16 t_infomask2 = PG_GETARG_INT16(1);
int cnt = 0;
@@ -530,10 +528,6 @@ heap_tuple_infomask_flags(PG_FUNCTION_ARGS)
bitcnt = pg_popcount((const char *) &t_infomask, sizeof(uint16)) +
pg_popcount((const char *) &t_infomask2, sizeof(uint16));
- /* Initialize values and NULL flags arrays */
- MemSet(values, 0, sizeof(values));
- MemSet(nulls, 0, sizeof(nulls));
-
/* If no flags, return a set of empty arrays */
if (bitcnt <= 0)
{
diff --git a/contrib/pg_prewarm/autoprewarm.c b/contrib/pg_prewarm/autoprewarm.c
index 13eee4a137..ee20e9b085 100644
--- a/contrib/pg_prewarm/autoprewarm.c
+++ b/contrib/pg_prewarm/autoprewarm.c
@@ -814,12 +814,11 @@ apw_detach_shmem(int code, Datum arg)
static void
apw_start_leader_worker(void)
{
- BackgroundWorker worker;
+ BackgroundWorker worker = {0};
BackgroundWorkerHandle *handle;
BgwHandleStatus status;
pid_t pid;
- MemSet(&worker, 0, sizeof(BackgroundWorker));
worker.bgw_flags = BGWORKER_SHMEM_ACCESS;
worker.bgw_start_time = BgWorkerStart_ConsistentState;
strcpy(worker.bgw_library_name, "pg_prewarm");
@@ -856,10 +855,9 @@ apw_start_leader_worker(void)
static void
apw_start_database_worker(void)
{
- BackgroundWorker worker;
+ BackgroundWorker worker = {0};
BackgroundWorkerHandle *handle;
- MemSet(&worker, 0, sizeof(BackgroundWorker));
worker.bgw_flags =
BGWORKER_SHMEM_ACCESS | BGWORKER_BACKEND_DATABASE_CONNECTION;
worker.bgw_start_time = BgWorkerStart_ConsistentState;
diff --git a/contrib/pg_stat_statements/pg_stat_statements.c b/contrib/pg_stat_statements/pg_stat_statements.c
index 4acfddcdb8..b4d4231dc6 100644
--- a/contrib/pg_stat_statements/pg_stat_statements.c
+++ b/contrib/pg_stat_statements/pg_stat_statements.c
@@ -1854,8 +1854,8 @@ pg_stat_statements_info(PG_FUNCTION_ARGS)
{
pgssGlobalStats stats;
TupleDesc tupdesc;
- Datum values[PG_STAT_STATEMENTS_INFO_COLS];
- bool nulls[PG_STAT_STATEMENTS_INFO_COLS];
+ Datum values[PG_STAT_STATEMENTS_INFO_COLS] = {0};
+ bool nulls[PG_STAT_STATEMENTS_INFO_COLS] = {0};
if (!pgss || !pgss_hash)
ereport(ERROR,
@@ -1866,9 +1866,6 @@ pg_stat_statements_info(PG_FUNCTION_ARGS)
if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE)
elog(ERROR, "return type must be a row type");
- MemSet(values, 0, sizeof(values));
- MemSet(nulls, 0, sizeof(nulls));
-
/* Read global statistics for pg_stat_statements */
{
volatile pgssSharedState *s = (volatile pgssSharedState *) pgss;
diff --git a/contrib/pg_trgm/trgm_regexp.c b/contrib/pg_trgm/trgm_regexp.c
index 58d32ba946..a155d4c13d 100644
--- a/contrib/pg_trgm/trgm_regexp.c
+++ b/contrib/pg_trgm/trgm_regexp.c
@@ -905,7 +905,7 @@ static void
transformGraph(TrgmNFA *trgmNFA)
{
HASHCTL hashCtl;
- TrgmStateKey initkey;
+ TrgmStateKey initkey = {0};
TrgmState *initstate;
ListCell *lc;
@@ -926,7 +926,6 @@ transformGraph(TrgmNFA *trgmNFA)
trgmNFA->nstates = 0;
/* Create initial state: ambiguous prefix, NFA's initial state */
- MemSet(&initkey, 0, sizeof(initkey));
initkey.prefix.colors[0] = COLOR_UNKNOWN;
initkey.prefix.colors[1] = COLOR_UNKNOWN;
initkey.nstate = pg_reg_getinitialstate(trgmNFA->regex);
@@ -1014,22 +1013,19 @@ processState(TrgmNFA *trgmNFA, TrgmState *state)
*
* Note that we don't generate any actual arcs here. addArcs will do that
* later, after we have identified all the enter keys for this state.
+ *
+ * Ensure any pad bytes in destKey are zero, since it may get used as a
+ * hashtable key by getState.
*/
static void
addKey(TrgmNFA *trgmNFA, TrgmState *state, TrgmStateKey *key)
{
regex_arc_t *arcs;
- TrgmStateKey destKey;
+ TrgmStateKey destKey = {0};
ListCell *cell;
int i,
arcsCount;
- /*
- * Ensure any pad bytes in destKey are zero, since it may get used as a
- * hashtable key by getState.
- */
- MemSet(&destKey, 0, sizeof(destKey));
-
/*
* Compare key to each existing enter key of the state to check for
* redundancy. We can drop either old key(s) or the new key if we find
@@ -1195,22 +1191,19 @@ addKeyToQueue(TrgmNFA *trgmNFA, TrgmStateKey *key)
/*
* Add outgoing arcs from given state, whose enter keys are all now known.
+ *
+ * Ensure any pad bytes in destKey are zero, since it may get used as a
+ * hashtable key by getState.
*/
static void
addArcs(TrgmNFA *trgmNFA, TrgmState *state)
{
- TrgmStateKey destKey;
+ TrgmStateKey destKey = {0};
ListCell *cell;
regex_arc_t *arcs;
int arcsCount,
i;
- /*
- * Ensure any pad bytes in destKey are zero, since it may get used as a
- * hashtable key by getState.
- */
- MemSet(&destKey, 0, sizeof(destKey));
-
/*
* Iterate over enter keys associated with this expanded-graph state. This
* includes both the state's own stateKey, and any enter keys we added to
diff --git a/contrib/pg_visibility/pg_visibility.c b/contrib/pg_visibility/pg_visibility.c
index 4e2e9ea9bb..a95f73ec79 100644
--- a/contrib/pg_visibility/pg_visibility.c
+++ b/contrib/pg_visibility/pg_visibility.c
@@ -75,7 +75,7 @@ pg_visibility_map(PG_FUNCTION_ARGS)
Buffer vmbuffer = InvalidBuffer;
TupleDesc tupdesc;
Datum values[2];
- bool nulls[2];
+ bool nulls[2] = {0};
rel = relation_open(relid, AccessShareLock);
@@ -88,7 +88,6 @@ pg_visibility_map(PG_FUNCTION_ARGS)
errmsg("invalid block number")));
tupdesc = pg_visibility_tupdesc(false, false);
- MemSet(nulls, 0, sizeof(nulls));
mapbits = (int32) visibilitymap_get_status(rel, blkno, &vmbuffer);
if (vmbuffer != InvalidBuffer)
@@ -117,7 +116,7 @@ pg_visibility(PG_FUNCTION_ARGS)
Page page;
TupleDesc tupdesc;
Datum values[3];
- bool nulls[3];
+ bool nulls[3] = {0};
rel = relation_open(relid, AccessShareLock);
@@ -130,7 +129,6 @@ pg_visibility(PG_FUNCTION_ARGS)
errmsg("invalid block number")));
tupdesc = pg_visibility_tupdesc(false, true);
- MemSet(nulls, 0, sizeof(nulls));
mapbits = (int32) visibilitymap_get_status(rel, blkno, &vmbuffer);
if (vmbuffer != InvalidBuffer)
@@ -188,10 +186,9 @@ pg_visibility_map_rel(PG_FUNCTION_ARGS)
if (info->next < info->count)
{
Datum values[3];
- bool nulls[3];
+ bool nulls[3] = {0};
HeapTuple tuple;
- MemSet(nulls, 0, sizeof(nulls));
values[0] = Int64GetDatum(info->next);
values[1] = BoolGetDatum((info->bits[info->next] & (1 << 0)) != 0);
values[2] = BoolGetDatum((info->bits[info->next] & (1 << 1)) != 0);
@@ -233,10 +230,9 @@ pg_visibility_rel(PG_FUNCTION_ARGS)
if (info->next < info->count)
{
Datum values[4];
- bool nulls[4];
+ bool nulls[4] = {0};
HeapTuple tuple;
- MemSet(nulls, 0, sizeof(nulls));
values[0] = Int64GetDatum(info->next);
values[1] = BoolGetDatum((info->bits[info->next] & (1 << 0)) != 0);
values[2] = BoolGetDatum((info->bits[info->next] & (1 << 1)) != 0);
@@ -266,7 +262,7 @@ pg_visibility_map_summary(PG_FUNCTION_ARGS)
int64 all_frozen = 0;
TupleDesc tupdesc;
Datum values[2];
- bool nulls[2];
+ bool nulls[2] = {0};
rel = relation_open(relid, AccessShareLock);
@@ -300,7 +296,6 @@ pg_visibility_map_summary(PG_FUNCTION_ARGS)
TupleDescInitEntry(tupdesc, (AttrNumber) 2, "all_frozen", INT8OID, -1, 0);
tupdesc = BlessTupleDesc(tupdesc);
- MemSet(nulls, 0, sizeof(nulls));
values[0] = Int64GetDatum(all_visible);
values[1] = Int64GetDatum(all_frozen);
diff --git a/contrib/pg_walinspect/pg_walinspect.c b/contrib/pg_walinspect/pg_walinspect.c
index a082dfb331..9081787634 100644
--- a/contrib/pg_walinspect/pg_walinspect.c
+++ b/contrib/pg_walinspect/pg_walinspect.c
@@ -229,8 +229,8 @@ pg_get_wal_record_info(PG_FUNCTION_ARGS)
{
#define PG_GET_WAL_RECORD_INFO_COLS 11
Datum result;
- Datum values[PG_GET_WAL_RECORD_INFO_COLS];
- bool nulls[PG_GET_WAL_RECORD_INFO_COLS];
+ Datum values[PG_GET_WAL_RECORD_INFO_COLS] = {0};
+ bool nulls[PG_GET_WAL_RECORD_INFO_COLS] = {0};
XLogRecPtr lsn;
XLogRecPtr curr_lsn;
XLogRecPtr first_record;
@@ -266,9 +266,6 @@ pg_get_wal_record_info(PG_FUNCTION_ARGS)
errmsg("could not read WAL at %X/%X",
LSN_FORMAT_ARGS(first_record))));
- MemSet(values, 0, sizeof(values));
- MemSet(nulls, 0, sizeof(nulls));
-
GetWALRecordInfo(xlogreader, first_record, values, nulls,
PG_GET_WAL_RECORD_INFO_COLS);
@@ -334,8 +331,8 @@ GetWALRecordsInfo(FunctionCallInfo fcinfo, XLogRecPtr start_lsn,
XLogRecPtr first_record;
XLogReaderState *xlogreader;
ReturnSetInfo *rsinfo = (ReturnSetInfo *) fcinfo->resultinfo;
- Datum values[PG_GET_WAL_RECORDS_INFO_COLS];
- bool nulls[PG_GET_WAL_RECORDS_INFO_COLS];
+ Datum values[PG_GET_WAL_RECORDS_INFO_COLS] = {0};
+ bool nulls[PG_GET_WAL_RECORDS_INFO_COLS] = {0};
SetSingleFuncCall(fcinfo, 0);
@@ -343,9 +340,6 @@ GetWALRecordsInfo(FunctionCallInfo fcinfo, XLogRecPtr start_lsn,
Assert(xlogreader);
- MemSet(values, 0, sizeof(values));
- MemSet(nulls, 0, sizeof(nulls));
-
while (ReadNextXLogRecord(xlogreader, first_record) &&
xlogreader->EndRecPtr <= end_lsn)
{
@@ -556,17 +550,15 @@ GetWalStats(FunctionCallInfo fcinfo, XLogRecPtr start_lsn,
#define PG_GET_WAL_STATS_COLS 9
XLogRecPtr first_record;
XLogReaderState *xlogreader;
- XLogStats stats;
+ XLogStats stats = {0};
ReturnSetInfo *rsinfo = (ReturnSetInfo *) fcinfo->resultinfo;
- Datum values[PG_GET_WAL_STATS_COLS];
- bool nulls[PG_GET_WAL_STATS_COLS];
+ Datum values[PG_GET_WAL_STATS_COLS] = {0};
+ bool nulls[PG_GET_WAL_STATS_COLS] = {0};
SetSingleFuncCall(fcinfo, 0);
xlogreader = InitXLogReaderState(start_lsn, &first_record);
- MemSet(&stats, 0, sizeof(stats));
-
while (ReadNextXLogRecord(xlogreader, first_record) &&
xlogreader->EndRecPtr <= end_lsn)
{
@@ -578,9 +570,6 @@ GetWalStats(FunctionCallInfo fcinfo, XLogRecPtr start_lsn,
pfree(xlogreader->private_data);
XLogReaderFree(xlogreader);
- MemSet(values, 0, sizeof(values));
- MemSet(nulls, 0, sizeof(nulls));
-
GetXLogSummaryStats(&stats, rsinfo, values, nulls,
PG_GET_WAL_STATS_COLS,
stats_per_record);
diff --git a/contrib/pgstattuple/pgstatindex.c b/contrib/pgstattuple/pgstatindex.c
index e1048e47ff..d69ac1c93d 100644
--- a/contrib/pgstattuple/pgstatindex.c
+++ b/contrib/pgstattuple/pgstatindex.c
@@ -575,7 +575,7 @@ pgstathashindex(PG_FUNCTION_ARGS)
HeapTuple tuple;
TupleDesc tupleDesc;
Datum values[8];
- bool nulls[8];
+ bool nulls[8] = {0};
Buffer metabuf;
HashMetaPage metap;
float8 free_percent;
@@ -697,7 +697,6 @@ pgstathashindex(PG_FUNCTION_ARGS)
/*
* Build and return the tuple
*/
- MemSet(nulls, 0, sizeof(nulls));
values[0] = Int32GetDatum(stats.version);
values[1] = Int64GetDatum((int64) stats.bucket_pages);
values[2] = Int64GetDatum((int64) stats.overflow_pages);
diff --git a/contrib/postgres_fdw/connection.c b/contrib/postgres_fdw/connection.c
index cffb6f8310..939d114f02 100644
--- a/contrib/postgres_fdw/connection.c
+++ b/contrib/postgres_fdw/connection.c
@@ -1678,8 +1678,8 @@ postgres_fdw_get_connections(PG_FUNCTION_ARGS)
while ((entry = (ConnCacheEntry *) hash_seq_search(&scan)))
{
ForeignServer *server;
- Datum values[POSTGRES_FDW_GET_CONNECTIONS_COLS];
- bool nulls[POSTGRES_FDW_GET_CONNECTIONS_COLS];
+ Datum values[POSTGRES_FDW_GET_CONNECTIONS_COLS] = {0};
+ bool nulls[POSTGRES_FDW_GET_CONNECTIONS_COLS] = {0};
/* We only look for open remote connections */
if (!entry->conn)
@@ -1687,9 +1687,6 @@ postgres_fdw_get_connections(PG_FUNCTION_ARGS)
server = GetForeignServerExtended(entry->serverid, FSV_MISSING_OK);
- MemSet(values, 0, sizeof(values));
- MemSet(nulls, 0, sizeof(nulls));
-
/*
* The foreign server may have been dropped in current explicit
* transaction. It is not possible to drop the server from another
diff --git a/contrib/postgres_fdw/postgres_fdw.c b/contrib/postgres_fdw/postgres_fdw.c
index 955a428e3d..cfac539008 100644
--- a/contrib/postgres_fdw/postgres_fdw.c
+++ b/contrib/postgres_fdw/postgres_fdw.c
@@ -3307,7 +3307,7 @@ estimate_path_cost_size(PlannerInfo *root,
{
RelOptInfo *outerrel = fpinfo->outerrel;
PgFdwRelationInfo *ofpinfo;
- AggClauseCosts aggcosts;
+ AggClauseCosts aggcosts = {0};
double input_rows;
int numGroupCols;
double numGroups = 1;
@@ -3331,7 +3331,6 @@ estimate_path_cost_size(PlannerInfo *root,
input_rows = ofpinfo->rows;
/* Collect statistics about aggregates for estimating costs. */
- MemSet(&aggcosts, 0, sizeof(AggClauseCosts));
if (root->parse->hasAggs)
{
get_agg_clause_costs(root, AGGSPLIT_SIMPLE, &aggcosts);
diff --git a/contrib/tablefunc/tablefunc.c b/contrib/tablefunc/tablefunc.c
index e308228bde..6452111e19 100644
--- a/contrib/tablefunc/tablefunc.c
+++ b/contrib/tablefunc/tablefunc.c
@@ -127,9 +127,8 @@ typedef struct crosstab_cat_desc
#define crosstab_HashTableLookup(HASHTAB, CATNAME, CATDESC) \
do { \
- crosstab_HashEnt *hentry; char key[MAX_CATNAME_LEN]; \
+ crosstab_HashEnt *hentry; char key[MAX_CATNAME_LEN] = {0}; \
\
- MemSet(key, 0, MAX_CATNAME_LEN); \
snprintf(key, MAX_CATNAME_LEN - 1, "%s", CATNAME); \
hentry = (crosstab_HashEnt*) hash_search(HASHTAB, \
key, HASH_FIND, NULL); \
@@ -141,9 +140,8 @@ do { \
#define crosstab_HashTableInsert(HASHTAB, CATDESC) \
do { \
- crosstab_HashEnt *hentry; bool found; char key[MAX_CATNAME_LEN]; \
+ crosstab_HashEnt *hentry; bool found; char key[MAX_CATNAME_LEN] = {0}; \
\
- MemSet(key, 0, MAX_CATNAME_LEN); \
snprintf(key, MAX_CATNAME_LEN - 1, "%s", CATDESC->catname); \
hentry = (crosstab_HashEnt*) hash_search(HASHTAB, \
key, HASH_ENTER, &found); \
diff --git a/src/backend/access/nbtree/nbtxlog.c b/src/backend/access/nbtree/nbtxlog.c
index ad489e33b3..14fe2d76c4 100644
--- a/src/backend/access/nbtree/nbtxlog.c
+++ b/src/backend/access/nbtree/nbtxlog.c
@@ -717,7 +717,7 @@ btree_xlog_mark_page_halfdead(uint8 info, XLogReaderState *record)
Buffer buffer;
Page page;
BTPageOpaque pageop;
- IndexTupleData trunctuple;
+ IndexTupleData trunctuple = {0};
/*
* In normal operation, we would lock all the pages this WAL record
@@ -780,7 +780,6 @@ btree_xlog_mark_page_halfdead(uint8 info, XLogReaderState *record)
* Construct a dummy high key item that points to top parent page (value
* is InvalidBlockNumber when the top parent page is the leaf page itself)
*/
- MemSet(&trunctuple, 0, sizeof(IndexTupleData));
trunctuple.t_info = sizeof(IndexTupleData);
BTreeTupleSetTopParent(&trunctuple, xlrec->topparent);
@@ -898,7 +897,7 @@ btree_xlog_unlink_page(uint8 info, XLogReaderState *record)
* we'll delete in the subtree undergoing deletion.
*/
Buffer leafbuf;
- IndexTupleData trunctuple;
+ IndexTupleData trunctuple = {0};
Assert(!isleaf);
@@ -915,7 +914,6 @@ btree_xlog_unlink_page(uint8 info, XLogReaderState *record)
pageop->btpo_cycleid = 0;
/* Add a dummy hikey item */
- MemSet(&trunctuple, 0, sizeof(IndexTupleData));
trunctuple.t_info = sizeof(IndexTupleData);
BTreeTupleSetTopParent(&trunctuple, xlrec->leaftopparent);
diff --git a/src/backend/access/transam/twophase.c b/src/backend/access/transam/twophase.c
index 41b31c5c6f..dd330ce260 100644
--- a/src/backend/access/transam/twophase.c
+++ b/src/backend/access/transam/twophase.c
@@ -781,7 +781,7 @@ pg_prepared_xact(PG_FUNCTION_ARGS)
GlobalTransaction gxact = &status->array[status->currIdx++];
PGPROC *proc = &ProcGlobal->allProcs[gxact->pgprocno];
Datum values[5];
- bool nulls[5];
+ bool nulls[5] = {0};
HeapTuple tuple;
Datum result;
@@ -791,9 +791,6 @@ pg_prepared_xact(PG_FUNCTION_ARGS)
/*
* Form tuple with appropriate data.
*/
- MemSet(values, 0, sizeof(values));
- MemSet(nulls, 0, sizeof(nulls));
-
values[0] = TransactionIdGetDatum(proc->xid);
values[1] = CStringGetTextDatum(gxact->gid);
values[2] = TimestampTzGetDatum(gxact->prepared_at);
diff --git a/src/backend/access/transam/xlogfuncs.c b/src/backend/access/transam/xlogfuncs.c
index 02bd919ff6..ed79e3d9a3 100644
--- a/src/backend/access/transam/xlogfuncs.c
+++ b/src/backend/access/transam/xlogfuncs.c
@@ -107,7 +107,7 @@ pg_backup_stop(PG_FUNCTION_ARGS)
#define PG_STOP_BACKUP_V2_COLS 3
TupleDesc tupdesc;
Datum values[PG_STOP_BACKUP_V2_COLS];
- bool nulls[PG_STOP_BACKUP_V2_COLS];
+ bool nulls[PG_STOP_BACKUP_V2_COLS] = {0};
bool waitforarchive = PG_GETARG_BOOL(0);
XLogRecPtr stoppoint;
@@ -117,9 +117,6 @@ pg_backup_stop(PG_FUNCTION_ARGS)
if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE)
elog(ERROR, "return type must be a row type");
- MemSet(values, 0, sizeof(values));
- MemSet(nulls, 0, sizeof(nulls));
-
if (status != SESSION_BACKUP_RUNNING)
ereport(ERROR,
(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
diff --git a/src/backend/catalog/aclchk.c b/src/backend/catalog/aclchk.c
index 5f1726c095..0bd4557050 100644
--- a/src/backend/catalog/aclchk.c
+++ b/src/backend/catalog/aclchk.c
@@ -1188,9 +1188,6 @@ SetDefaultACL(InternalDefaultACL *iacls)
Acl *old_acl;
Acl *new_acl;
HeapTuple newtuple;
- Datum values[Natts_pg_default_acl];
- bool nulls[Natts_pg_default_acl];
- bool replaces[Natts_pg_default_acl];
int noldmembers;
int nnewmembers;
Oid *oldmembers;
@@ -1341,13 +1338,10 @@ SetDefaultACL(InternalDefaultACL *iacls)
}
else
{
+ Datum values[Natts_pg_default_acl] = {0};
+ bool nulls[Natts_pg_default_acl] = {0};
Oid defAclOid;
- /* Prepare to insert or update pg_default_acl entry */
- MemSet(values, 0, sizeof(values));
- MemSet(nulls, false, sizeof(nulls));
- MemSet(replaces, false, sizeof(replaces));
-
if (isNew)
{
/* insert new entry */
@@ -1364,6 +1358,8 @@ SetDefaultACL(InternalDefaultACL *iacls)
}
else
{
+ bool replaces[Natts_pg_default_acl] = {0};
+
defAclOid = ((Form_pg_default_acl) GETSTRUCT(tuple))->oid;
/* update existing entry */
@@ -1662,9 +1658,8 @@ ExecGrant_Attribute(InternalGrant *istmt, Oid relOid, const char *relname,
AclMode avail_goptions;
bool need_update;
HeapTuple newtuple;
- Datum values[Natts_pg_attribute];
- bool nulls[Natts_pg_attribute];
- bool replaces[Natts_pg_attribute];
+ Datum values[Natts_pg_attribute] = {0};
+ bool nulls[Natts_pg_attribute] = {0};
int noldmembers;
int nnewmembers;
Oid *oldmembers;
@@ -1745,9 +1740,6 @@ ExecGrant_Attribute(InternalGrant *istmt, Oid relOid, const char *relname,
nnewmembers = aclmembers(new_acl, &newmembers);
/* finished building new ACL value, now insert it */
- MemSet(values, 0, sizeof(values));
- MemSet(nulls, false, sizeof(nulls));
- MemSet(replaces, false, sizeof(replaces));
/*
* If the updated ACL is empty, we can set attacl to null, and maybe even
@@ -1766,10 +1758,12 @@ ExecGrant_Attribute(InternalGrant *istmt, Oid relOid, const char *relname,
nulls[Anum_pg_attribute_attacl - 1] = true;
need_update = !isNull;
}
- replaces[Anum_pg_attribute_attacl - 1] = true;
if (need_update)
{
+ bool replaces[Natts_pg_attribute] = {0};
+
+ replaces[Anum_pg_attribute_attacl - 1] = true;
newtuple = heap_modify_tuple(attr_tuple, RelationGetDescr(attRelation),
values, nulls, replaces);
@@ -1975,9 +1969,9 @@ ExecGrant_Relation(InternalGrant *istmt)
Acl *new_acl;
Oid grantorId;
HeapTuple newtuple;
- Datum values[Natts_pg_class];
- bool nulls[Natts_pg_class];
- bool replaces[Natts_pg_class];
+ Datum values[Natts_pg_class] = {0};
+ bool nulls[Natts_pg_class] = {0};
+ bool replaces[Natts_pg_class] = {0};
int nnewmembers;
Oid *newmembers;
ObjectType objtype;
@@ -2027,10 +2021,6 @@ ExecGrant_Relation(InternalGrant *istmt)
nnewmembers = aclmembers(new_acl, &newmembers);
/* finished building new ACL value, now insert it */
- MemSet(values, 0, sizeof(values));
- MemSet(nulls, false, sizeof(nulls));
- MemSet(replaces, false, sizeof(replaces));
-
replaces[Anum_pg_class_relacl - 1] = true;
values[Anum_pg_class_relacl - 1] = PointerGetDatum(new_acl);
@@ -2129,6 +2119,9 @@ ExecGrant_Relation(InternalGrant *istmt)
static void
ExecGrant_Database(InternalGrant *istmt)
{
+ Datum values[Natts_pg_database] = {0};
+ bool nulls[Natts_pg_database] = {0};
+ bool replaces[Natts_pg_database] = {0};
Relation relation;
ListCell *cell;
@@ -2150,9 +2143,6 @@ ExecGrant_Database(InternalGrant *istmt)
Oid grantorId;
Oid ownerId;
HeapTuple newtuple;
- Datum values[Natts_pg_database];
- bool nulls[Natts_pg_database];
- bool replaces[Natts_pg_database];
int noldmembers;
int nnewmembers;
Oid *oldmembers;
@@ -2217,10 +2207,6 @@ ExecGrant_Database(InternalGrant *istmt)
nnewmembers = aclmembers(new_acl, &newmembers);
/* finished building new ACL value, now insert it */
- MemSet(values, 0, sizeof(values));
- MemSet(nulls, false, sizeof(nulls));
- MemSet(replaces, false, sizeof(replaces));
-
replaces[Anum_pg_database_datacl - 1] = true;
values[Anum_pg_database_datacl - 1] = PointerGetDatum(new_acl);
@@ -2249,6 +2235,9 @@ ExecGrant_Database(InternalGrant *istmt)
static void
ExecGrant_Fdw(InternalGrant *istmt)
{
+ Datum values[Natts_pg_foreign_data_wrapper] = {0};
+ bool nulls[Natts_pg_foreign_data_wrapper] = {0};
+ bool replaces[Natts_pg_foreign_data_wrapper] = {0};
Relation relation;
ListCell *cell;
@@ -2271,9 +2260,6 @@ ExecGrant_Fdw(InternalGrant *istmt)
Oid ownerId;
HeapTuple tuple;
HeapTuple newtuple;
- Datum values[Natts_pg_foreign_data_wrapper];
- bool nulls[Natts_pg_foreign_data_wrapper];
- bool replaces[Natts_pg_foreign_data_wrapper];
int noldmembers;
int nnewmembers;
Oid *oldmembers;
@@ -2339,10 +2325,6 @@ ExecGrant_Fdw(InternalGrant *istmt)
nnewmembers = aclmembers(new_acl, &newmembers);
/* finished building new ACL value, now insert it */
- MemSet(values, 0, sizeof(values));
- MemSet(nulls, false, sizeof(nulls));
- MemSet(replaces, false, sizeof(replaces));
-
replaces[Anum_pg_foreign_data_wrapper_fdwacl - 1] = true;
values[Anum_pg_foreign_data_wrapper_fdwacl - 1] = PointerGetDatum(new_acl);
@@ -2376,6 +2358,9 @@ ExecGrant_Fdw(InternalGrant *istmt)
static void
ExecGrant_ForeignServer(InternalGrant *istmt)
{
+ Datum values[Natts_pg_foreign_server] = {0};
+ bool nulls[Natts_pg_foreign_server] = {0};
+ bool replaces[Natts_pg_foreign_server] = {0};
Relation relation;
ListCell *cell;
@@ -2398,9 +2383,6 @@ ExecGrant_ForeignServer(InternalGrant *istmt)
Oid ownerId;
HeapTuple tuple;
HeapTuple newtuple;
- Datum values[Natts_pg_foreign_server];
- bool nulls[Natts_pg_foreign_server];
- bool replaces[Natts_pg_foreign_server];
int noldmembers;
int nnewmembers;
Oid *oldmembers;
@@ -2465,10 +2447,6 @@ ExecGrant_ForeignServer(InternalGrant *istmt)
nnewmembers = aclmembers(new_acl, &newmembers);
/* finished building new ACL value, now insert it */
- MemSet(values, 0, sizeof(values));
- MemSet(nulls, false, sizeof(nulls));
- MemSet(replaces, false, sizeof(replaces));
-
replaces[Anum_pg_foreign_server_srvacl - 1] = true;
values[Anum_pg_foreign_server_srvacl - 1] = PointerGetDatum(new_acl);
@@ -2501,6 +2479,9 @@ ExecGrant_ForeignServer(InternalGrant *istmt)
static void
ExecGrant_Function(InternalGrant *istmt)
{
+ Datum values[Natts_pg_proc] = {0};
+ bool nulls[Natts_pg_proc] = {0};
+ bool replaces[Natts_pg_proc] = {0};
Relation relation;
ListCell *cell;
@@ -2523,9 +2504,6 @@ ExecGrant_Function(InternalGrant *istmt)
Oid ownerId;
HeapTuple tuple;
HeapTuple newtuple;
- Datum values[Natts_pg_proc];
- bool nulls[Natts_pg_proc];
- bool replaces[Natts_pg_proc];
int noldmembers;
int nnewmembers;
Oid *oldmembers;
@@ -2589,10 +2567,6 @@ ExecGrant_Function(InternalGrant *istmt)
nnewmembers = aclmembers(new_acl, &newmembers);
/* finished building new ACL value, now insert it */
- MemSet(values, 0, sizeof(values));
- MemSet(nulls, false, sizeof(nulls));
- MemSet(replaces, false, sizeof(replaces));
-
replaces[Anum_pg_proc_proacl - 1] = true;
values[Anum_pg_proc_proacl - 1] = PointerGetDatum(new_acl);
@@ -2624,6 +2598,9 @@ ExecGrant_Function(InternalGrant *istmt)
static void
ExecGrant_Language(InternalGrant *istmt)
{
+ Datum values[Natts_pg_language] = {0};
+ bool nulls[Natts_pg_language] = {0};
+ bool replaces[Natts_pg_language] = {0};
Relation relation;
ListCell *cell;
@@ -2646,9 +2623,6 @@ ExecGrant_Language(InternalGrant *istmt)
Oid ownerId;
HeapTuple tuple;
HeapTuple newtuple;
- Datum values[Natts_pg_language];
- bool nulls[Natts_pg_language];
- bool replaces[Natts_pg_language];
int noldmembers;
int nnewmembers;
Oid *oldmembers;
@@ -2720,10 +2694,6 @@ ExecGrant_Language(InternalGrant *istmt)
nnewmembers = aclmembers(new_acl, &newmembers);
/* finished building new ACL value, now insert it */
- MemSet(values, 0, sizeof(values));
- MemSet(nulls, false, sizeof(nulls));
- MemSet(replaces, false, sizeof(replaces));
-
replaces[Anum_pg_language_lanacl - 1] = true;
values[Anum_pg_language_lanacl - 1] = PointerGetDatum(new_acl);
@@ -2755,6 +2725,9 @@ ExecGrant_Language(InternalGrant *istmt)
static void
ExecGrant_Largeobject(InternalGrant *istmt)
{
+ Datum values[Natts_pg_largeobject_metadata] = {0};
+ bool nulls[Natts_pg_largeobject_metadata] = {0};
+ bool replaces[Natts_pg_largeobject_metadata] = {0};
Relation relation;
ListCell *cell;
@@ -2778,9 +2751,6 @@ ExecGrant_Largeobject(InternalGrant *istmt)
Oid grantorId;
Oid ownerId;
HeapTuple newtuple;
- Datum values[Natts_pg_largeobject_metadata];
- bool nulls[Natts_pg_largeobject_metadata];
- bool replaces[Natts_pg_largeobject_metadata];
int noldmembers;
int nnewmembers;
Oid *oldmembers;
@@ -2858,10 +2828,6 @@ ExecGrant_Largeobject(InternalGrant *istmt)
nnewmembers = aclmembers(new_acl, &newmembers);
/* finished building new ACL value, now insert it */
- MemSet(values, 0, sizeof(values));
- MemSet(nulls, false, sizeof(nulls));
- MemSet(replaces, false, sizeof(replaces));
-
replaces[Anum_pg_largeobject_metadata_lomacl - 1] = true;
values[Anum_pg_largeobject_metadata_lomacl - 1]
= PointerGetDatum(new_acl);
@@ -2895,6 +2861,9 @@ ExecGrant_Largeobject(InternalGrant *istmt)
static void
ExecGrant_Namespace(InternalGrant *istmt)
{
+ Datum values[Natts_pg_namespace] = {0};
+ bool nulls[Natts_pg_namespace] = {0};
+ bool replaces[Natts_pg_namespace] = {0};
Relation relation;
ListCell *cell;
@@ -2917,9 +2886,6 @@ ExecGrant_Namespace(InternalGrant *istmt)
Oid ownerId;
HeapTuple tuple;
HeapTuple newtuple;
- Datum values[Natts_pg_namespace];
- bool nulls[Natts_pg_namespace];
- bool replaces[Natts_pg_namespace];
int noldmembers;
int nnewmembers;
Oid *oldmembers;
@@ -2984,10 +2950,6 @@ ExecGrant_Namespace(InternalGrant *istmt)
nnewmembers = aclmembers(new_acl, &newmembers);
/* finished building new ACL value, now insert it */
- MemSet(values, 0, sizeof(values));
- MemSet(nulls, false, sizeof(nulls));
- MemSet(replaces, false, sizeof(replaces));
-
replaces[Anum_pg_namespace_nspacl - 1] = true;
values[Anum_pg_namespace_nspacl - 1] = PointerGetDatum(new_acl);
@@ -3019,6 +2981,9 @@ ExecGrant_Namespace(InternalGrant *istmt)
static void
ExecGrant_Tablespace(InternalGrant *istmt)
{
+ Datum values[Natts_pg_tablespace] = {0};
+ bool nulls[Natts_pg_tablespace] = {0};
+ bool replaces[Natts_pg_tablespace] = {0};
Relation relation;
ListCell *cell;
@@ -3040,9 +3005,6 @@ ExecGrant_Tablespace(InternalGrant *istmt)
Oid grantorId;
Oid ownerId;
HeapTuple newtuple;
- Datum values[Natts_pg_tablespace];
- bool nulls[Natts_pg_tablespace];
- bool replaces[Natts_pg_tablespace];
int noldmembers;
int nnewmembers;
Oid *oldmembers;
@@ -3108,10 +3070,6 @@ ExecGrant_Tablespace(InternalGrant *istmt)
nnewmembers = aclmembers(new_acl, &newmembers);
/* finished building new ACL value, now insert it */
- MemSet(values, 0, sizeof(values));
- MemSet(nulls, false, sizeof(nulls));
- MemSet(replaces, false, sizeof(replaces));
-
replaces[Anum_pg_tablespace_spcacl - 1] = true;
values[Anum_pg_tablespace_spcacl - 1] = PointerGetDatum(new_acl);
@@ -3139,6 +3097,9 @@ ExecGrant_Tablespace(InternalGrant *istmt)
static void
ExecGrant_Type(InternalGrant *istmt)
{
+ Datum values[Natts_pg_type] = {0};
+ bool nulls[Natts_pg_type] = {0};
+ bool replaces[Natts_pg_type] = {0};
Relation relation;
ListCell *cell;
@@ -3160,9 +3121,6 @@ ExecGrant_Type(InternalGrant *istmt)
Oid grantorId;
Oid ownerId;
HeapTuple newtuple;
- Datum values[Natts_pg_type];
- bool nulls[Natts_pg_type];
- bool replaces[Natts_pg_type];
int noldmembers;
int nnewmembers;
Oid *oldmembers;
@@ -3242,10 +3200,6 @@ ExecGrant_Type(InternalGrant *istmt)
nnewmembers = aclmembers(new_acl, &newmembers);
/* finished building new ACL value, now insert it */
- MemSet(values, 0, sizeof(values));
- MemSet(nulls, false, sizeof(nulls));
- MemSet(replaces, false, sizeof(replaces));
-
replaces[Anum_pg_type_typacl - 1] = true;
values[Anum_pg_type_typacl - 1] = PointerGetDatum(new_acl);
@@ -3384,13 +3338,9 @@ ExecGrant_Parameter(InternalGrant *istmt)
{
/* finished building new ACL value, now insert it */
HeapTuple newtuple;
- Datum values[Natts_pg_parameter_acl];
- bool nulls[Natts_pg_parameter_acl];
- bool replaces[Natts_pg_parameter_acl];
-
- MemSet(values, 0, sizeof(values));
- MemSet(nulls, false, sizeof(nulls));
- MemSet(replaces, false, sizeof(replaces));
+ Datum values[Natts_pg_parameter_acl] = {0};
+ bool nulls[Natts_pg_parameter_acl] = {0};
+ bool replaces[Natts_pg_parameter_acl] = {0};
replaces[Anum_pg_parameter_acl_paracl - 1] = true;
values[Anum_pg_parameter_acl_paracl - 1] = PointerGetDatum(new_acl);
@@ -6419,16 +6369,12 @@ recordExtensionInitPrivWorker(Oid objoid, Oid classoid, int objsubid, Acl *new_a
/* If we find an entry, update it with the latest ACL. */
if (HeapTupleIsValid(oldtuple))
{
- Datum values[Natts_pg_init_privs];
- bool nulls[Natts_pg_init_privs];
- bool replace[Natts_pg_init_privs];
-
/* If we have a new ACL to set, then update the row with it. */
if (new_acl)
{
- MemSet(values, 0, sizeof(values));
- MemSet(nulls, false, sizeof(nulls));
- MemSet(replace, false, sizeof(replace));
+ Datum values[Natts_pg_init_privs] = {0};
+ bool nulls[Natts_pg_init_privs] = {0};
+ bool replace[Natts_pg_init_privs] = {0};
values[Anum_pg_init_privs_initprivs - 1] = PointerGetDatum(new_acl);
replace[Anum_pg_init_privs_initprivs - 1] = true;
@@ -6446,9 +6392,6 @@ recordExtensionInitPrivWorker(Oid objoid, Oid classoid, int objsubid, Acl *new_a
}
else
{
- Datum values[Natts_pg_init_privs];
- bool nulls[Natts_pg_init_privs];
-
/*
* Only add a new entry if the new ACL is non-NULL.
*
@@ -6457,9 +6400,10 @@ recordExtensionInitPrivWorker(Oid objoid, Oid classoid, int objsubid, Acl *new_a
*/
if (new_acl)
{
- /* No entry found, so add it. */
- MemSet(nulls, false, sizeof(nulls));
+ Datum values[Natts_pg_init_privs] = {0};
+ bool nulls[Natts_pg_init_privs] = {0};
+ /* No entry found, so add it. */
values[Anum_pg_init_privs_objoid - 1] = ObjectIdGetDatum(objoid);
values[Anum_pg_init_privs_classoid - 1] = ObjectIdGetDatum(classoid);
values[Anum_pg_init_privs_objsubid - 1] = Int32GetDatum(objsubid);
diff --git a/src/backend/catalog/dependency.c b/src/backend/catalog/dependency.c
index de10923391..5cbd72ce10 100644
--- a/src/backend/catalog/dependency.c
+++ b/src/backend/catalog/dependency.c
@@ -1635,12 +1635,11 @@ recordDependencyOnSingleRelExpr(const ObjectAddress *depender,
bool reverse_self)
{
find_expr_references_context context;
- RangeTblEntry rte;
+ RangeTblEntry rte = {0};
context.addrs = new_object_addresses();
/* We gin up a rather bogus rangetable list to handle Vars */
- MemSet(&rte, 0, sizeof(rte));
rte.type = T_RangeTblEntry;
rte.rtekind = RTE_RELATION;
rte.relid = relId;
diff --git a/src/backend/catalog/heap.c b/src/backend/catalog/heap.c
index e770ea6eb8..9b03579e6e 100644
--- a/src/backend/catalog/heap.c
+++ b/src/backend/catalog/heap.c
@@ -1709,15 +1709,11 @@ RemoveAttributeById(Oid relid, AttrNumber attnum)
/* clear the missing value if any */
if (attStruct->atthasmissing)
{
- Datum valuesAtt[Natts_pg_attribute];
- bool nullsAtt[Natts_pg_attribute];
- bool replacesAtt[Natts_pg_attribute];
+ Datum valuesAtt[Natts_pg_attribute] = {0};
+ bool nullsAtt[Natts_pg_attribute] = {0};
+ bool replacesAtt[Natts_pg_attribute] = {0};
/* update the tuple - set atthasmissing and attmissingval */
- MemSet(valuesAtt, 0, sizeof(valuesAtt));
- MemSet(nullsAtt, false, sizeof(nullsAtt));
- MemSet(replacesAtt, false, sizeof(replacesAtt));
-
valuesAtt[Anum_pg_attribute_atthasmissing - 1] =
BoolGetDatum(false);
replacesAtt[Anum_pg_attribute_atthasmissing - 1] = true;
@@ -2006,9 +2002,9 @@ RelationClearMissing(Relation rel)
void
SetAttrMissing(Oid relid, char *attname, char *value)
{
- Datum valuesAtt[Natts_pg_attribute];
- bool nullsAtt[Natts_pg_attribute];
- bool replacesAtt[Natts_pg_attribute];
+ Datum valuesAtt[Natts_pg_attribute] = {0};
+ bool nullsAtt[Natts_pg_attribute] = {0};
+ bool replacesAtt[Natts_pg_attribute] = {0};
Datum missingval;
Form_pg_attribute attStruct;
Relation attrrel,
@@ -2041,10 +2037,6 @@ SetAttrMissing(Oid relid, char *attname, char *value)
Int32GetDatum(attStruct->atttypmod));
/* update the tuple - set atthasmissing and attmissingval */
- MemSet(valuesAtt, 0, sizeof(valuesAtt));
- MemSet(nullsAtt, false, sizeof(nullsAtt));
- MemSet(replacesAtt, false, sizeof(replacesAtt));
-
valuesAtt[Anum_pg_attribute_atthasmissing - 1] = BoolGetDatum(true);
replacesAtt[Anum_pg_attribute_atthasmissing - 1] = true;
valuesAtt[Anum_pg_attribute_attmissingval - 1] = missingval;
@@ -3321,7 +3313,7 @@ StorePartitionKey(Relation rel,
Relation pg_partitioned_table;
HeapTuple tuple;
Datum values[Natts_pg_partitioned_table];
- bool nulls[Natts_pg_partitioned_table];
+ bool nulls[Natts_pg_partitioned_table] = {0};
ObjectAddress myself;
ObjectAddress referenced;
ObjectAddresses *addrs;
@@ -3347,8 +3339,6 @@ StorePartitionKey(Relation rel,
pg_partitioned_table = table_open(PartitionedRelationId, RowExclusiveLock);
- MemSet(nulls, false, sizeof(nulls));
-
/* Only this can ever be NULL */
if (!partexprDatum)
nulls[Anum_pg_partitioned_table_partexprs - 1] = true;
diff --git a/src/backend/catalog/index.c b/src/backend/catalog/index.c
index c5d463ac55..d7192f35e3 100644
--- a/src/backend/catalog/index.c
+++ b/src/backend/catalog/index.c
@@ -554,7 +554,7 @@ UpdateIndexRelation(Oid indexoid,
Datum exprsDatum;
Datum predDatum;
Datum values[Natts_pg_index];
- bool nulls[Natts_pg_index];
+ bool nulls[Natts_pg_index] = {0};
Relation pg_index;
HeapTuple tuple;
int i;
@@ -608,8 +608,6 @@ UpdateIndexRelation(Oid indexoid,
/*
* Build a pg_index tuple
*/
- MemSet(nulls, false, sizeof(nulls));
-
values[Anum_pg_index_indexrelid - 1] = ObjectIdGetDatum(indexoid);
values[Anum_pg_index_indrelid - 1] = ObjectIdGetDatum(heapoid);
values[Anum_pg_index_indnatts - 1] = Int16GetDatum(indexInfo->ii_NumIndexAttrs);
diff --git a/src/backend/catalog/pg_attrdef.c b/src/backend/catalog/pg_attrdef.c
index c5d4a9912e..1a14093a9a 100644
--- a/src/backend/catalog/pg_attrdef.c
+++ b/src/backend/catalog/pg_attrdef.c
@@ -111,15 +111,12 @@ StoreAttrDefault(Relation rel, AttrNumber attnum,
Expr *expr2 = (Expr *) expr;
EState *estate = NULL;
ExprContext *econtext;
- Datum valuesAtt[Natts_pg_attribute];
- bool nullsAtt[Natts_pg_attribute];
- bool replacesAtt[Natts_pg_attribute];
+ Datum valuesAtt[Natts_pg_attribute] = {0};
+ bool nullsAtt[Natts_pg_attribute] = {0};
+ bool replacesAtt[Natts_pg_attribute] = {0};
Datum missingval = (Datum) 0;
bool missingIsNull = true;
- MemSet(valuesAtt, 0, sizeof(valuesAtt));
- MemSet(nullsAtt, false, sizeof(nullsAtt));
- MemSet(replacesAtt, false, sizeof(replacesAtt));
valuesAtt[Anum_pg_attribute_atthasdef - 1] = true;
replacesAtt[Anum_pg_attribute_atthasdef - 1] = true;
diff --git a/src/backend/catalog/pg_cast.c b/src/backend/catalog/pg_cast.c
index 4857f6468d..1812bb7fcc 100644
--- a/src/backend/catalog/pg_cast.c
+++ b/src/backend/catalog/pg_cast.c
@@ -47,7 +47,7 @@ CastCreate(Oid sourcetypeid, Oid targettypeid, Oid funcid, char castcontext,
HeapTuple tuple;
Oid castid;
Datum values[Natts_pg_cast];
- bool nulls[Natts_pg_cast];
+ bool nulls[Natts_pg_cast] = {0};
ObjectAddress myself,
referenced;
ObjectAddresses *addrs;
@@ -78,8 +78,6 @@ CastCreate(Oid sourcetypeid, Oid targettypeid, Oid funcid, char castcontext,
values[Anum_pg_cast_castcontext - 1] = CharGetDatum(castcontext);
values[Anum_pg_cast_castmethod - 1] = CharGetDatum(castmethod);
- MemSet(nulls, false, sizeof(nulls));
-
tuple = heap_form_tuple(RelationGetDescr(relation), values, nulls);
CatalogTupleInsert(relation, tuple);
diff --git a/src/backend/catalog/pg_parameter_acl.c b/src/backend/catalog/pg_parameter_acl.c
index 2decee909b..0570e811d1 100644
--- a/src/backend/catalog/pg_parameter_acl.c
+++ b/src/backend/catalog/pg_parameter_acl.c
@@ -74,8 +74,8 @@ ParameterAclCreate(const char *parameter)
Relation rel;
TupleDesc tupDesc;
HeapTuple tuple;
- Datum values[Natts_pg_parameter_acl];
- bool nulls[Natts_pg_parameter_acl];
+ Datum values[Natts_pg_parameter_acl] = {0};
+ bool nulls[Natts_pg_parameter_acl] = {0};
/*
* To prevent cluttering pg_parameter_acl with useless entries, insist
@@ -98,8 +98,6 @@ ParameterAclCreate(const char *parameter)
*/
rel = table_open(ParameterAclRelationId, RowExclusiveLock);
tupDesc = RelationGetDescr(rel);
- MemSet(values, 0, sizeof(values));
- MemSet(nulls, false, sizeof(nulls));
parameterId = GetNewOidWithIndex(rel,
ParameterAclOidIndexId,
Anum_pg_parameter_acl_oid);
diff --git a/src/backend/catalog/pg_publication.c b/src/backend/catalog/pg_publication.c
index c365de3a72..4ff692cb5e 100644
--- a/src/backend/catalog/pg_publication.c
+++ b/src/backend/catalog/pg_publication.c
@@ -1162,15 +1162,12 @@ pg_get_publication_tables(PG_FUNCTION_ARGS)
HeapTuple pubtuple = NULL;
HeapTuple rettuple;
Oid relid = list_nth_oid(tables, funcctx->call_cntr);
- Datum values[NUM_PUBLICATION_TABLES_ELEM];
- bool nulls[NUM_PUBLICATION_TABLES_ELEM];
+ Datum values[NUM_PUBLICATION_TABLES_ELEM] = {0};
+ bool nulls[NUM_PUBLICATION_TABLES_ELEM] = {0};
/*
* Form tuple with appropriate data.
*/
- MemSet(nulls, 0, sizeof(nulls));
- MemSet(values, 0, sizeof(values));
-
publication = GetPublicationByName(pubname, false);
values[0] = ObjectIdGetDatum(relid);
diff --git a/src/backend/commands/copyfromparse.c b/src/backend/commands/copyfromparse.c
index 57813b3458..cef0f2c279 100644
--- a/src/backend/commands/copyfromparse.c
+++ b/src/backend/commands/copyfromparse.c
@@ -869,7 +869,7 @@ NextCopyFrom(CopyFromState cstate, ExprContext *econtext,
/* Initialize all values for row to NULL */
MemSet(values, 0, num_phys_attrs * sizeof(Datum));
- MemSet(nulls, true, num_phys_attrs * sizeof(bool));
+ memset(nulls, true, num_phys_attrs * sizeof(bool));
if (!cstate->opts.binary)
{
diff --git a/src/backend/commands/dbcommands.c b/src/backend/commands/dbcommands.c
index 1901b434c5..099d369b2f 100644
--- a/src/backend/commands/dbcommands.c
+++ b/src/backend/commands/dbcommands.c
@@ -689,8 +689,8 @@ createdb(ParseState *pstate, const CreatedbStmt *stmt)
volatile Oid dst_deftablespace;
Relation pg_database_rel;
HeapTuple tuple;
- Datum new_record[Natts_pg_database];
- bool new_record_nulls[Natts_pg_database];
+ Datum new_record[Natts_pg_database] = {0};
+ bool new_record_nulls[Natts_pg_database] = {0};
Oid dboid = InvalidOid;
Oid datdba;
ListCell *option;
@@ -1296,9 +1296,6 @@ createdb(ParseState *pstate, const CreatedbStmt *stmt)
(dblocprovider != COLLPROVIDER_ICU && !dbiculocale));
/* Form tuple */
- MemSet(new_record, 0, sizeof(new_record));
- MemSet(new_record_nulls, false, sizeof(new_record_nulls));
-
new_record[Anum_pg_database_oid - 1] = ObjectIdGetDatum(dboid);
new_record[Anum_pg_database_datname - 1] =
DirectFunctionCall1(namein, CStringGetDatum(dbname));
@@ -1822,9 +1819,6 @@ movedb(const char *dbname, const char *tblspcname)
newtuple;
Oid src_tblspcoid,
dst_tblspcoid;
- Datum new_record[Natts_pg_database];
- bool new_record_nulls[Natts_pg_database];
- bool new_record_repl[Natts_pg_database];
ScanKeyData scankey;
SysScanDesc sysscan;
AclResult aclresult;
@@ -2003,6 +1997,10 @@ movedb(const char *dbname, const char *tblspcname)
PG_ENSURE_ERROR_CLEANUP(movedb_failure_callback,
PointerGetDatum(&fparms));
{
+ Datum new_record[Natts_pg_database] = {0};
+ bool new_record_nulls[Natts_pg_database] = {0};
+ bool new_record_repl[Natts_pg_database] = {0};
+
/*
* Copy files from the old tablespace to the new one
*/
@@ -2042,10 +2040,6 @@ movedb(const char *dbname, const char *tblspcname)
(errcode(ERRCODE_UNDEFINED_DATABASE),
errmsg("database \"%s\" does not exist", dbname)));
- MemSet(new_record, 0, sizeof(new_record));
- MemSet(new_record_nulls, false, sizeof(new_record_nulls));
- MemSet(new_record_repl, false, sizeof(new_record_repl));
-
new_record[Anum_pg_database_dattablespace - 1] = ObjectIdGetDatum(dst_tblspcoid);
new_record_repl[Anum_pg_database_dattablespace - 1] = true;
@@ -2194,9 +2188,9 @@ AlterDatabase(ParseState *pstate, AlterDatabaseStmt *stmt, bool isTopLevel)
DefElem *dallowconnections = NULL;
DefElem *dconnlimit = NULL;
DefElem *dtablespace = NULL;
- Datum new_record[Natts_pg_database];
- bool new_record_nulls[Natts_pg_database];
- bool new_record_repl[Natts_pg_database];
+ Datum new_record[Natts_pg_database] = {0};
+ bool new_record_nulls[Natts_pg_database] = {0};
+ bool new_record_repl[Natts_pg_database] = {0};
/* Extract options from the statement node tree */
foreach(option, stmt->options)
@@ -2305,10 +2299,6 @@ AlterDatabase(ParseState *pstate, AlterDatabaseStmt *stmt, bool isTopLevel)
/*
* Build an updated tuple, perusing the information just obtained
*/
- MemSet(new_record, 0, sizeof(new_record));
- MemSet(new_record_nulls, false, sizeof(new_record_nulls));
- MemSet(new_record_repl, false, sizeof(new_record_repl));
-
if (distemplate)
{
new_record[Anum_pg_database_datistemplate - 1] = BoolGetDatum(dbistemplate);
@@ -2492,8 +2482,8 @@ AlterDatabaseOwner(const char *dbname, Oid newOwnerId)
if (datForm->datdba != newOwnerId)
{
Datum repl_val[Natts_pg_database];
- bool repl_null[Natts_pg_database];
- bool repl_repl[Natts_pg_database];
+ bool repl_null[Natts_pg_database] = {0};
+ bool repl_repl[Natts_pg_database] = {0};
Acl *newAcl;
Datum aclDatum;
bool isNull;
@@ -2521,9 +2511,6 @@ AlterDatabaseOwner(const char *dbname, Oid newOwnerId)
(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
errmsg("permission denied to change owner of database")));
- memset(repl_null, false, sizeof(repl_null));
- memset(repl_repl, false, sizeof(repl_repl));
-
repl_repl[Anum_pg_database_datdba - 1] = true;
repl_val[Anum_pg_database_datdba - 1] = ObjectIdGetDatum(newOwnerId);
diff --git a/src/backend/commands/event_trigger.c b/src/backend/commands/event_trigger.c
index f46f86474a..eef3e5d56e 100644
--- a/src/backend/commands/event_trigger.c
+++ b/src/backend/commands/event_trigger.c
@@ -1310,14 +1310,11 @@ pg_event_trigger_dropped_objects(PG_FUNCTION_ARGS)
{
SQLDropObject *obj;
int i = 0;
- Datum values[12];
- bool nulls[12];
+ Datum values[12] = {0};
+ bool nulls[12] = {0};
obj = slist_container(SQLDropObject, next, iter.cur);
- MemSet(values, 0, sizeof(values));
- MemSet(nulls, 0, sizeof(nulls));
-
/* classid */
values[i++] = ObjectIdGetDatum(obj->address.classId);
@@ -1840,7 +1837,7 @@ pg_event_trigger_ddl_commands(PG_FUNCTION_ARGS)
{
CollectedCommand *cmd = lfirst(lc);
Datum values[9];
- bool nulls[9];
+ bool nulls[9] = {0};
ObjectAddress addr;
int i = 0;
@@ -1858,8 +1855,6 @@ pg_event_trigger_ddl_commands(PG_FUNCTION_ARGS)
!OidIsValid(cmd->d.simple.address.objectId))
continue;
- MemSet(nulls, 0, sizeof(nulls));
-
switch (cmd->type)
{
case SCT_Simple:
diff --git a/src/backend/commands/functioncmds.c b/src/backend/commands/functioncmds.c
index b016eecb2c..f51cfe6df1 100644
--- a/src/backend/commands/functioncmds.c
+++ b/src/backend/commands/functioncmds.c
@@ -1806,8 +1806,7 @@ CreateTransform(CreateTransformStmt *stmt)
AclResult aclresult;
Form_pg_proc procstruct;
Datum values[Natts_pg_transform];
- bool nulls[Natts_pg_transform];
- bool replaces[Natts_pg_transform];
+ bool nulls[Natts_pg_transform] = {0};
Oid transformid;
HeapTuple tuple;
HeapTuple newtuple;
@@ -1913,8 +1912,6 @@ CreateTransform(CreateTransformStmt *stmt)
values[Anum_pg_transform_trffromsql - 1] = ObjectIdGetDatum(fromsqlfuncid);
values[Anum_pg_transform_trftosql - 1] = ObjectIdGetDatum(tosqlfuncid);
- MemSet(nulls, false, sizeof(nulls));
-
relation = table_open(TransformRelationId, RowExclusiveLock);
tuple = SearchSysCache2(TRFTYPELANG,
@@ -1922,6 +1919,8 @@ CreateTransform(CreateTransformStmt *stmt)
ObjectIdGetDatum(langid));
if (HeapTupleIsValid(tuple))
{
+ bool replaces[Natts_pg_transform] = {0};
+
Form_pg_transform form = (Form_pg_transform) GETSTRUCT(tuple);
if (!stmt->replace)
@@ -1931,7 +1930,6 @@ CreateTransform(CreateTransformStmt *stmt)
format_type_be(typeid),
stmt->lang)));
- MemSet(replaces, false, sizeof(replaces));
replaces[Anum_pg_transform_trffromsql - 1] = true;
replaces[Anum_pg_transform_trftosql - 1] = true;
diff --git a/src/backend/commands/prepare.c b/src/backend/commands/prepare.c
index 2333aae467..579825c159 100644
--- a/src/backend/commands/prepare.c
+++ b/src/backend/commands/prepare.c
@@ -685,12 +685,10 @@ pg_prepared_statement(PG_FUNCTION_ARGS)
{
TupleDesc result_desc;
Datum values[8];
- bool nulls[8];
+ bool nulls[8] = {0};
result_desc = prep_stmt->plansource->resultDesc;
- MemSet(nulls, 0, sizeof(nulls));
-
values[0] = CStringGetTextDatum(prep_stmt->stmt_name);
values[1] = CStringGetTextDatum(prep_stmt->plansource->query_string);
values[2] = TimestampTzGetDatum(prep_stmt->prepare_time);
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index ef5b34a312..18f7a4ae86 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -9013,15 +9013,15 @@ ATAddForeignKeyConstraint(List **wqueue, AlteredTableInfo *tab, Relation rel,
bool recurse, bool recursing, LOCKMODE lockmode)
{
Relation pkrel;
- int16 pkattnum[INDEX_MAX_KEYS];
- int16 fkattnum[INDEX_MAX_KEYS];
- Oid pktypoid[INDEX_MAX_KEYS];
- Oid fktypoid[INDEX_MAX_KEYS];
- Oid opclasses[INDEX_MAX_KEYS];
- Oid pfeqoperators[INDEX_MAX_KEYS];
- Oid ppeqoperators[INDEX_MAX_KEYS];
- Oid ffeqoperators[INDEX_MAX_KEYS];
- int16 fkdelsetcols[INDEX_MAX_KEYS];
+ int16 pkattnum[INDEX_MAX_KEYS] = {0};
+ int16 fkattnum[INDEX_MAX_KEYS] = {0};
+ Oid pktypoid[INDEX_MAX_KEYS] = {0};
+ Oid fktypoid[INDEX_MAX_KEYS] = {0};
+ Oid opclasses[INDEX_MAX_KEYS] = {0};
+ Oid pfeqoperators[INDEX_MAX_KEYS] = {0};
+ Oid ppeqoperators[INDEX_MAX_KEYS] = {0};
+ Oid ffeqoperators[INDEX_MAX_KEYS] = {0};
+ int16 fkdelsetcols[INDEX_MAX_KEYS] = {0};
int i;
int numfks,
numpks,
@@ -9113,16 +9113,6 @@ ATAddForeignKeyConstraint(List **wqueue, AlteredTableInfo *tab, Relation rel,
* Look up the referencing attributes to make sure they exist, and record
* their attnums and type OIDs.
*/
- MemSet(pkattnum, 0, sizeof(pkattnum));
- MemSet(fkattnum, 0, sizeof(fkattnum));
- MemSet(pktypoid, 0, sizeof(pktypoid));
- MemSet(fktypoid, 0, sizeof(fktypoid));
- MemSet(opclasses, 0, sizeof(opclasses));
- MemSet(pfeqoperators, 0, sizeof(pfeqoperators));
- MemSet(ppeqoperators, 0, sizeof(ppeqoperators));
- MemSet(ffeqoperators, 0, sizeof(ffeqoperators));
- MemSet(fkdelsetcols, 0, sizeof(fkdelsetcols));
-
numfks = transformColumnNameList(RelationGetRelid(rel),
fkconstraint->fk_attrs,
fkattnum, fktypoid);
@@ -11498,7 +11488,7 @@ validateForeignKeyConstraint(char *conname,
{
TupleTableSlot *slot;
TableScanDesc scan;
- Trigger trig;
+ Trigger trig = {0};
Snapshot snapshot;
MemoryContext oldcxt;
MemoryContext perTupCxt;
@@ -11509,7 +11499,6 @@ validateForeignKeyConstraint(char *conname,
/*
* Build a trigger call structure; we'll need it either way.
*/
- MemSet(&trig, 0, sizeof(trig));
trig.tgoid = InvalidOid;
trig.tgname = conname;
trig.tgenabled = TRIGGER_FIRES_ON_ORIGIN;
@@ -12783,15 +12772,11 @@ ATExecAlterColumnType(AlteredTableInfo *tab, Relation rel,
int one = 1;
bool isNull;
- Datum valuesAtt[Natts_pg_attribute];
- bool nullsAtt[Natts_pg_attribute];
- bool replacesAtt[Natts_pg_attribute];
+ Datum valuesAtt[Natts_pg_attribute] = {0};
+ bool nullsAtt[Natts_pg_attribute] = {0};
+ bool replacesAtt[Natts_pg_attribute] = {0};
HeapTuple newTup;
- MemSet(valuesAtt, 0, sizeof(valuesAtt));
- MemSet(nullsAtt, false, sizeof(nullsAtt));
- MemSet(replacesAtt, false, sizeof(replacesAtt));
-
missingval = array_get_element(missingval,
1,
&one,
@@ -19219,7 +19204,7 @@ ATDetachCheckNoForeignKeyRefs(Relation partition)
HeapTuple tuple;
Form_pg_constraint constrForm;
Relation rel;
- Trigger trig;
+ Trigger trig = {0};
tuple = SearchSysCache1(CONSTROID, ObjectIdGetDatum(constrOid));
if (!HeapTupleIsValid(tuple))
@@ -19232,7 +19217,6 @@ ATDetachCheckNoForeignKeyRefs(Relation partition)
/* prevent data changes into the referencing table until commit */
rel = table_open(constrForm->conrelid, ShareLock);
- MemSet(&trig, 0, sizeof(trig));
trig.tgoid = InvalidOid;
trig.tgname = NameStr(constrForm->conname);
trig.tgenabled = TRIGGER_FIRES_ON_ORIGIN;
diff --git a/src/backend/commands/tablespace.c b/src/backend/commands/tablespace.c
index c8bdd9992a..cb7d46089a 100644
--- a/src/backend/commands/tablespace.c
+++ b/src/backend/commands/tablespace.c
@@ -238,7 +238,7 @@ CreateTableSpace(CreateTableSpaceStmt *stmt)
#ifdef HAVE_SYMLINK
Relation rel;
Datum values[Natts_pg_tablespace];
- bool nulls[Natts_pg_tablespace];
+ bool nulls[Natts_pg_tablespace] = {0};
HeapTuple tuple;
Oid tablespaceoid;
char *location;
@@ -340,8 +340,6 @@ CreateTableSpace(CreateTableSpaceStmt *stmt)
*/
rel = table_open(TableSpaceRelationId, RowExclusiveLock);
- MemSet(nulls, false, sizeof(nulls));
-
if (IsBinaryUpgrade)
{
/* Use binary-upgrade override for tablespace oid */
diff --git a/src/backend/commands/typecmds.c b/src/backend/commands/typecmds.c
index 4f5e7c7ccb..4f58d29aa5 100644
--- a/src/backend/commands/typecmds.c
+++ b/src/backend/commands/typecmds.c
@@ -2570,9 +2570,9 @@ AlterDomainDefault(List *names, Node *defaultRaw)
Relation rel;
char *defaultValue;
Node *defaultExpr = NULL; /* NULL if no default specified */
- Datum new_record[Natts_pg_type];
- bool new_record_nulls[Natts_pg_type];
- bool new_record_repl[Natts_pg_type];
+ Datum new_record[Natts_pg_type] = {0};
+ bool new_record_nulls[Natts_pg_type] = {0};
+ bool new_record_repl[Natts_pg_type] = {0};
HeapTuple newtuple;
Form_pg_type typTup;
ObjectAddress address;
@@ -2593,9 +2593,6 @@ AlterDomainDefault(List *names, Node *defaultRaw)
checkDomainOwner(tup);
/* Setup new tuple */
- MemSet(new_record, (Datum) 0, sizeof(new_record));
- MemSet(new_record_nulls, false, sizeof(new_record_nulls));
- MemSet(new_record_repl, false, sizeof(new_record_repl));
/* Store the new default into the tuple */
if (defaultRaw)
diff --git a/src/backend/commands/user.c b/src/backend/commands/user.c
index 984305ba31..8f4cc86eda 100644
--- a/src/backend/commands/user.c
+++ b/src/backend/commands/user.c
@@ -74,8 +74,8 @@ CreateRole(ParseState *pstate, CreateRoleStmt *stmt)
Relation pg_authid_rel;
TupleDesc pg_authid_dsc;
HeapTuple tuple;
- Datum new_record[Natts_pg_authid];
- bool new_record_nulls[Natts_pg_authid];
+ Datum new_record[Natts_pg_authid] = {0};
+ bool new_record_nulls[Natts_pg_authid] = {0};
Oid roleid;
ListCell *item;
ListCell *option;
@@ -338,12 +338,8 @@ CreateRole(ParseState *pstate, CreateRoleStmt *stmt)
/*
* Build a tuple to insert
*/
- MemSet(new_record, 0, sizeof(new_record));
- MemSet(new_record_nulls, false, sizeof(new_record_nulls));
-
new_record[Anum_pg_authid_rolname - 1] =
DirectFunctionCall1(namein, CStringGetDatum(stmt->role));
-
new_record[Anum_pg_authid_rolsuper - 1] = BoolGetDatum(issuper);
new_record[Anum_pg_authid_rolinherit - 1] = BoolGetDatum(inherit);
new_record[Anum_pg_authid_rolcreaterole - 1] = BoolGetDatum(createrole);
@@ -492,9 +488,9 @@ CreateRole(ParseState *pstate, CreateRoleStmt *stmt)
Oid
AlterRole(ParseState *pstate, AlterRoleStmt *stmt)
{
- Datum new_record[Natts_pg_authid];
- bool new_record_nulls[Natts_pg_authid];
- bool new_record_repl[Natts_pg_authid];
+ Datum new_record[Natts_pg_authid] = {0};
+ bool new_record_nulls[Natts_pg_authid] = {0};
+ bool new_record_repl[Natts_pg_authid] = {0};
Relation pg_authid_rel;
TupleDesc pg_authid_dsc;
HeapTuple tuple,
@@ -691,9 +687,6 @@ AlterRole(ParseState *pstate, AlterRoleStmt *stmt)
/*
* Build an updated tuple, perusing the information just obtained
*/
- MemSet(new_record, 0, sizeof(new_record));
- MemSet(new_record_nulls, false, sizeof(new_record_nulls));
- MemSet(new_record_repl, false, sizeof(new_record_repl));
/*
* issuper/createrole/etc
@@ -1440,9 +1433,8 @@ AddRoleMems(const char *rolename, Oid roleid,
Oid memberid = lfirst_oid(iditem);
HeapTuple authmem_tuple;
HeapTuple tuple;
- Datum new_record[Natts_pg_auth_members];
- bool new_record_nulls[Natts_pg_auth_members];
- bool new_record_repl[Natts_pg_auth_members];
+ Datum new_record[Natts_pg_auth_members] = {0};
+ bool new_record_nulls[Natts_pg_auth_members] = {0};
/*
* pg_database_owner is never a role member. Lifting this restriction
@@ -1500,10 +1492,6 @@ AddRoleMems(const char *rolename, Oid roleid,
}
/* Build a tuple to insert or update */
- MemSet(new_record, 0, sizeof(new_record));
- MemSet(new_record_nulls, false, sizeof(new_record_nulls));
- MemSet(new_record_repl, false, sizeof(new_record_repl));
-
new_record[Anum_pg_auth_members_roleid - 1] = ObjectIdGetDatum(roleid);
new_record[Anum_pg_auth_members_member - 1] = ObjectIdGetDatum(memberid);
new_record[Anum_pg_auth_members_grantor - 1] = ObjectIdGetDatum(grantorId);
@@ -1511,6 +1499,8 @@ AddRoleMems(const char *rolename, Oid roleid,
if (HeapTupleIsValid(authmem_tuple))
{
+ bool new_record_repl[Natts_pg_auth_members] = {0};
+
new_record_repl[Anum_pg_auth_members_grantor - 1] = true;
new_record_repl[Anum_pg_auth_members_admin_option - 1] = true;
tuple = heap_modify_tuple(authmem_tuple, pg_authmem_dsc,
@@ -1614,15 +1604,11 @@ DelRoleMems(const char *rolename, Oid roleid,
{
/* Just turn off the admin option */
HeapTuple tuple;
- Datum new_record[Natts_pg_auth_members];
- bool new_record_nulls[Natts_pg_auth_members];
- bool new_record_repl[Natts_pg_auth_members];
+ Datum new_record[Natts_pg_auth_members] = {0};
+ bool new_record_nulls[Natts_pg_auth_members] = {0};
+ bool new_record_repl[Natts_pg_auth_members] = {0};
/* Build a tuple to update with */
- MemSet(new_record, 0, sizeof(new_record));
- MemSet(new_record_nulls, false, sizeof(new_record_nulls));
- MemSet(new_record_repl, false, sizeof(new_record_repl));
-
new_record[Anum_pg_auth_members_admin_option - 1] = BoolGetDatum(false);
new_record_repl[Anum_pg_auth_members_admin_option - 1] = true;
diff --git a/src/backend/libpq/auth.c b/src/backend/libpq/auth.c
index 2d9ab7edce..53fb7ca628 100644
--- a/src/backend/libpq/auth.c
+++ b/src/backend/libpq/auth.c
@@ -3022,7 +3022,7 @@ PerformRadiusTransaction(const char *server, const char *secret, const char *por
struct sockaddr_in localaddr;
struct sockaddr_in remoteaddr;
#endif
- struct addrinfo hint;
+ struct addrinfo hint = {0};
struct addrinfo *serveraddrs;
int port;
socklen_t addrsize;
@@ -3038,7 +3038,6 @@ PerformRadiusTransaction(const char *server, const char *secret, const char *por
if (identifier == NULL)
identifier = "postgresql";
- MemSet(&hint, 0, sizeof(hint));
hint.ai_socktype = SOCK_DGRAM;
hint.ai_family = AF_UNSPEC;
port = atoi(portstr);
diff --git a/src/backend/libpq/pqcomm.c b/src/backend/libpq/pqcomm.c
index 75392a8bb7..803d166640 100644
--- a/src/backend/libpq/pqcomm.c
+++ b/src/backend/libpq/pqcomm.c
@@ -331,7 +331,7 @@ StreamServerPort(int family, const char *hostName, unsigned short portNumber,
char *service;
struct addrinfo *addrs = NULL,
*addr;
- struct addrinfo hint;
+ struct addrinfo hint = {0};
int listen_index = 0;
int added = 0;
@@ -343,7 +343,6 @@ StreamServerPort(int family, const char *hostName, unsigned short portNumber,
#endif
/* Initialize hint structure */
- MemSet(&hint, 0, sizeof(hint));
hint.ai_family = family;
hint.ai_flags = AI_PASSIVE;
hint.ai_socktype = SOCK_STREAM;
diff --git a/src/backend/optimizer/path/costsize.c b/src/backend/optimizer/path/costsize.c
index fcc26b01a4..1e0f1880c5 100644
--- a/src/backend/optimizer/path/costsize.c
+++ b/src/backend/optimizer/path/costsize.c
@@ -2926,13 +2926,12 @@ cost_agg(Path *path, PlannerInfo *root,
double output_tuples;
Cost startup_cost;
Cost total_cost;
- AggClauseCosts dummy_aggcosts;
+ const AggClauseCosts dummy_aggcosts = {0};
/* Use all-zero per-aggregate costs if NULL is passed */
if (aggcosts == NULL)
{
Assert(aggstrategy == AGG_HASHED);
- MemSet(&dummy_aggcosts, 0, sizeof(AggClauseCosts));
aggcosts = &dummy_aggcosts;
}
diff --git a/src/backend/optimizer/path/indxpath.c b/src/backend/optimizer/path/indxpath.c
index 0ef70ad7f1..9c1b6305d3 100644
--- a/src/backend/optimizer/path/indxpath.c
+++ b/src/backend/optimizer/path/indxpath.c
@@ -238,9 +238,6 @@ create_index_paths(PlannerInfo *root, RelOptInfo *rel)
List *bitindexpaths;
List *bitjoinpaths;
List *joinorclauses;
- IndexClauseSet rclauseset;
- IndexClauseSet jclauseset;
- IndexClauseSet eclauseset;
ListCell *lc;
/* Skip the whole mess if no indexes */
@@ -253,6 +250,9 @@ create_index_paths(PlannerInfo *root, RelOptInfo *rel)
/* Examine each index in turn */
foreach(lc, rel->indexlist)
{
+ IndexClauseSet rclauseset = {0};
+ IndexClauseSet jclauseset = {0};
+ IndexClauseSet eclauseset = {0};
IndexOptInfo *index = (IndexOptInfo *) lfirst(lc);
/* Protect limited-size array in IndexClauseSets */
@@ -269,7 +269,6 @@ create_index_paths(PlannerInfo *root, RelOptInfo *rel)
/*
* Identify the restriction clauses that can match the index.
*/
- MemSet(&rclauseset, 0, sizeof(rclauseset));
match_restriction_clauses_to_index(root, index, &rclauseset);
/*
@@ -286,7 +285,6 @@ create_index_paths(PlannerInfo *root, RelOptInfo *rel)
* step finds only "loose" join clauses that have not been merged into
* EquivalenceClasses. Also, collect join OR clauses for later.
*/
- MemSet(&jclauseset, 0, sizeof(jclauseset));
match_join_clauses_to_index(root, rel, index,
&jclauseset, &joinorclauses);
@@ -294,7 +292,6 @@ create_index_paths(PlannerInfo *root, RelOptInfo *rel)
* Look for EquivalenceClasses that can generate joinclauses matching
* the index.
*/
- MemSet(&eclauseset, 0, sizeof(eclauseset));
match_eclass_clauses_to_index(root, index,
&eclauseset);
diff --git a/src/backend/optimizer/plan/planner.c b/src/backend/optimizer/plan/planner.c
index 06ad856eac..77cbe681e5 100644
--- a/src/backend/optimizer/plan/planner.c
+++ b/src/backend/optimizer/plan/planner.c
@@ -3350,9 +3350,8 @@ create_grouping_paths(PlannerInfo *root,
Query *parse = root->parse;
RelOptInfo *grouped_rel;
RelOptInfo *partially_grouped_rel;
- AggClauseCosts agg_costs;
+ AggClauseCosts agg_costs = {0};
- MemSet(&agg_costs, 0, sizeof(AggClauseCosts));
get_agg_clause_costs(root, AGGSPLIT_SIMPLE, &agg_costs);
/*
@@ -5908,16 +5907,14 @@ expression_planner_with_deps(Expr *expr,
List **invalItems)
{
Node *result;
- PlannerGlobal glob;
- PlannerInfo root;
+ PlannerGlobal glob = {0};
+ PlannerInfo root = {0};
/* Make up dummy planner state so we can use setrefs machinery */
- MemSet(&glob, 0, sizeof(glob));
glob.type = T_PlannerGlobal;
glob.relationOids = NIL;
glob.invalItems = NIL;
- MemSet(&root, 0, sizeof(root));
root.type = T_PlannerInfo;
root.glob = &glob;
diff --git a/src/backend/optimizer/plan/setrefs.c b/src/backend/optimizer/plan/setrefs.c
index 9cef92cab2..f7fb2b3e6d 100644
--- a/src/backend/optimizer/plan/setrefs.c
+++ b/src/backend/optimizer/plan/setrefs.c
@@ -3285,18 +3285,16 @@ extract_query_dependencies(Node *query,
List **invalItems,
bool *hasRowSecurity)
{
- PlannerGlobal glob;
- PlannerInfo root;
+ PlannerGlobal glob = {0};
+ PlannerInfo root = {0};
/* Make up dummy planner state so we can use this module's machinery */
- MemSet(&glob, 0, sizeof(glob));
glob.type = T_PlannerGlobal;
glob.relationOids = NIL;
glob.invalItems = NIL;
/* Hack: we use glob.dependsOnRole to collect hasRowSecurity flags */
glob.dependsOnRole = false;
- MemSet(&root, 0, sizeof(root));
root.type = T_PlannerInfo;
root.glob = &glob;
diff --git a/src/backend/parser/parse_target.c b/src/backend/parser/parse_target.c
index 2a1d44b813..d69cb58b6a 100644
--- a/src/backend/parser/parse_target.c
+++ b/src/backend/parser/parse_target.c
@@ -1594,9 +1594,8 @@ expandRecordVariable(ParseState *pstate, Var *var, int levelsup)
* to. We have to build an additional level of ParseState
* to keep in step with varlevelsup in the subselect.
*/
- ParseState mypstate;
+ ParseState mypstate = {0};
- MemSet(&mypstate, 0, sizeof(mypstate));
mypstate.parentParseState = pstate;
mypstate.p_rtable = rte->subquery->rtable;
/* don't bother filling the rest of the fake pstate */
@@ -1649,10 +1648,9 @@ expandRecordVariable(ParseState *pstate, Var *var, int levelsup)
* in step with varlevelsup in the CTE; furthermore it
* could be an outer CTE.
*/
- ParseState mypstate;
+ ParseState mypstate = {0};
Index levelsup;
- MemSet(&mypstate, 0, sizeof(mypstate));
/* this loop must work, since GetCTEForRTE did */
for (levelsup = 0;
levelsup < rte->ctelevelsup + netlevelsup;
diff --git a/src/backend/replication/logical/launcher.c b/src/backend/replication/logical/launcher.c
index 2bdab53e19..3bbd522724 100644
--- a/src/backend/replication/logical/launcher.c
+++ b/src/backend/replication/logical/launcher.c
@@ -938,8 +938,8 @@ pg_stat_get_subscription(PG_FUNCTION_ARGS)
for (i = 0; i < max_logical_replication_workers; i++)
{
/* for each row */
- Datum values[PG_STAT_GET_SUBSCRIPTION_COLS];
- bool nulls[PG_STAT_GET_SUBSCRIPTION_COLS];
+ Datum values[PG_STAT_GET_SUBSCRIPTION_COLS] = {0};
+ bool nulls[PG_STAT_GET_SUBSCRIPTION_COLS] = {0};
int worker_pid;
LogicalRepWorker worker;
@@ -953,9 +953,6 @@ pg_stat_get_subscription(PG_FUNCTION_ARGS)
worker_pid = worker.proc->pid;
- MemSet(values, 0, sizeof(values));
- MemSet(nulls, 0, sizeof(nulls));
-
values[0] = ObjectIdGetDatum(worker.subid);
if (OidIsValid(worker.relid))
values[1] = ObjectIdGetDatum(worker.relid);
diff --git a/src/backend/replication/walsender.c b/src/backend/replication/walsender.c
index 3c407ab964..ef2ca3fef7 100644
--- a/src/backend/replication/walsender.c
+++ b/src/backend/replication/walsender.c
@@ -402,7 +402,7 @@ IdentifySystem(void)
TupOutputState *tstate;
TupleDesc tupdesc;
Datum values[4];
- bool nulls[4];
+ bool nulls[4] = {0};
TimeLineID currTLI;
/*
@@ -437,7 +437,6 @@ IdentifySystem(void)
}
dest = CreateDestReceiver(DestRemoteSimple);
- MemSet(nulls, false, sizeof(nulls));
/* need a tuple descriptor representing four columns */
tupdesc = CreateTemplateTupleDesc(4);
@@ -483,7 +482,7 @@ ReadReplicationSlot(ReadReplicationSlotCmd *cmd)
DestReceiver *dest;
TupOutputState *tstate;
TupleDesc tupdesc;
- Datum values[READ_REPLICATION_SLOT_COLS];
+ Datum values[READ_REPLICATION_SLOT_COLS] = {0};
bool nulls[READ_REPLICATION_SLOT_COLS];
tupdesc = CreateTemplateTupleDesc(READ_REPLICATION_SLOT_COLS);
@@ -495,8 +494,7 @@ ReadReplicationSlot(ReadReplicationSlotCmd *cmd)
TupleDescInitBuiltinEntry(tupdesc, (AttrNumber) 3, "restart_tli",
INT8OID, -1, 0);
- MemSet(values, 0, READ_REPLICATION_SLOT_COLS * sizeof(Datum));
- MemSet(nulls, true, READ_REPLICATION_SLOT_COLS * sizeof(bool));
+ memset(nulls, true, READ_REPLICATION_SLOT_COLS * sizeof(bool));
LWLockAcquire(ReplicationSlotControlLock, LW_SHARED);
slot = SearchNamedReplicationSlot(cmd->slotname, false);
@@ -859,13 +857,12 @@ StartReplication(StartReplicationCmd *cmd)
TupOutputState *tstate;
TupleDesc tupdesc;
Datum values[2];
- bool nulls[2];
+ bool nulls[2] = {0};
snprintf(startpos_str, sizeof(startpos_str), "%X/%X",
LSN_FORMAT_ARGS(sendTimeLineValidUpto));
dest = CreateDestReceiver(DestRemoteSimple);
- MemSet(nulls, false, sizeof(nulls));
/*
* Need a tuple descriptor representing two columns. int8 may seem
@@ -1043,7 +1040,7 @@ CreateReplicationSlot(CreateReplicationSlotCmd *cmd)
TupOutputState *tstate;
TupleDesc tupdesc;
Datum values[4];
- bool nulls[4];
+ bool nulls[4] = {0};
Assert(!MyReplicationSlot);
@@ -1178,7 +1175,6 @@ CreateReplicationSlot(CreateReplicationSlotCmd *cmd)
LSN_FORMAT_ARGS(MyReplicationSlot->data.confirmed_flush));
dest = CreateDestReceiver(DestRemoteSimple);
- MemSet(nulls, false, sizeof(nulls));
/*----------
* Need a tuple descriptor representing four columns:
@@ -3527,7 +3523,6 @@ pg_stat_get_wal_senders(PG_FUNCTION_ARGS)
}
}
- memset(nulls, 0, sizeof(nulls));
values[0] = Int32GetDatum(pid);
if (!has_privs_of_role(GetUserId(), ROLE_PG_READ_ALL_STATS))
@@ -3537,10 +3532,12 @@ pg_stat_get_wal_senders(PG_FUNCTION_ARGS)
* can see details. Other users only get the pid value to know
* it's a walsender, but no details.
*/
- MemSet(&nulls[1], true, PG_STAT_GET_WAL_SENDERS_COLS - 1);
+ nulls[0] = false;
+ memset(&nulls[1], true, PG_STAT_GET_WAL_SENDERS_COLS - 1);
}
else
{
+ memset(nulls, 0, sizeof(nulls));
values[1] = CStringGetTextDatum(WalSndGetStateString(state));
if (XLogRecPtrIsInvalid(sentPtr))
diff --git a/src/backend/rewrite/rewriteDefine.c b/src/backend/rewrite/rewriteDefine.c
index 185bf5fbff..a5a1fb887f 100644
--- a/src/backend/rewrite/rewriteDefine.c
+++ b/src/backend/rewrite/rewriteDefine.c
@@ -67,8 +67,7 @@ InsertRule(const char *rulname,
char *evqual = nodeToString(event_qual);
char *actiontree = nodeToString((Node *) action);
Datum values[Natts_pg_rewrite];
- bool nulls[Natts_pg_rewrite];
- bool replaces[Natts_pg_rewrite];
+ bool nulls[Natts_pg_rewrite] = {0};
NameData rname;
Relation pg_rewrite_desc;
HeapTuple tup,
@@ -81,8 +80,6 @@ InsertRule(const char *rulname,
/*
* Set up *nulls and *values arrays
*/
- MemSet(nulls, false, sizeof(nulls));
-
namestrcpy(&rname, rulname);
values[Anum_pg_rewrite_rulename - 1] = NameGetDatum(&rname);
values[Anum_pg_rewrite_ev_class - 1] = ObjectIdGetDatum(eventrel_oid);
@@ -106,6 +103,8 @@ InsertRule(const char *rulname,
if (HeapTupleIsValid(oldtup))
{
+ bool replaces[Natts_pg_rewrite] = {0};
+
if (!replace)
ereport(ERROR,
(errcode(ERRCODE_DUPLICATE_OBJECT),
@@ -115,7 +114,6 @@ InsertRule(const char *rulname,
/*
* When replacing, we don't need to replace every attribute
*/
- MemSet(replaces, false, sizeof(replaces));
replaces[Anum_pg_rewrite_ev_type - 1] = true;
replaces[Anum_pg_rewrite_is_instead - 1] = true;
replaces[Anum_pg_rewrite_ev_qual - 1] = true;
diff --git a/src/backend/storage/lmgr/lock.c b/src/backend/storage/lmgr/lock.c
index 5f5803f681..ae6a1b1116 100644
--- a/src/backend/storage/lmgr/lock.c
+++ b/src/backend/storage/lmgr/lock.c
@@ -597,13 +597,12 @@ DoLockModesConflict(LOCKMODE mode1, LOCKMODE mode2)
bool
LockHeldByMe(const LOCKTAG *locktag, LOCKMODE lockmode)
{
- LOCALLOCKTAG localtag;
+ LOCALLOCKTAG localtag = {0};
LOCALLOCK *locallock;
/*
* See if there is a LOCALLOCK entry for this lock and lockmode
*/
- MemSet(&localtag, 0, sizeof(localtag)); /* must clear padding */
localtag.lock = *locktag;
localtag.mode = lockmode;
@@ -635,7 +634,7 @@ LockHasWaiters(const LOCKTAG *locktag, LOCKMODE lockmode, bool sessionLock)
{
LOCKMETHODID lockmethodid = locktag->locktag_lockmethodid;
LockMethod lockMethodTable;
- LOCALLOCKTAG localtag;
+ LOCALLOCKTAG localtag = {0};
LOCALLOCK *locallock;
LOCK *lock;
PROCLOCK *proclock;
@@ -658,7 +657,6 @@ LockHasWaiters(const LOCKTAG *locktag, LOCKMODE lockmode, bool sessionLock)
/*
* Find the LOCALLOCK entry for this lock and lockmode
*/
- MemSet(&localtag, 0, sizeof(localtag)); /* must clear padding */
localtag.lock = *locktag;
localtag.mode = lockmode;
@@ -777,7 +775,7 @@ LockAcquireExtended(const LOCKTAG *locktag,
{
LOCKMETHODID lockmethodid = locktag->locktag_lockmethodid;
LockMethod lockMethodTable;
- LOCALLOCKTAG localtag;
+ LOCALLOCKTAG localtag = {0};
LOCALLOCK *locallock;
LOCK *lock;
PROCLOCK *proclock;
@@ -820,7 +818,6 @@ LockAcquireExtended(const LOCKTAG *locktag,
/*
* Find or create a LOCALLOCK entry for this lock and lockmode
*/
- MemSet(&localtag, 0, sizeof(localtag)); /* must clear padding */
localtag.lock = *locktag;
localtag.mode = lockmode;
@@ -1976,7 +1973,7 @@ LockRelease(const LOCKTAG *locktag, LOCKMODE lockmode, bool sessionLock)
{
LOCKMETHODID lockmethodid = locktag->locktag_lockmethodid;
LockMethod lockMethodTable;
- LOCALLOCKTAG localtag;
+ LOCALLOCKTAG localtag = {0};
LOCALLOCK *locallock;
LOCK *lock;
PROCLOCK *proclock;
@@ -1999,7 +1996,6 @@ LockRelease(const LOCKTAG *locktag, LOCKMODE lockmode, bool sessionLock)
/*
* Find the LOCALLOCK entry for this lock and lockmode
*/
- MemSet(&localtag, 0, sizeof(localtag)); /* must clear padding */
localtag.lock = *locktag;
localtag.mode = lockmode;
diff --git a/src/backend/storage/lmgr/lwlock.c b/src/backend/storage/lmgr/lwlock.c
index 38317edaf9..ce5e5c073f 100644
--- a/src/backend/storage/lmgr/lwlock.c
+++ b/src/backend/storage/lmgr/lwlock.c
@@ -384,7 +384,7 @@ print_lwlock_stats(int code, Datum arg)
static lwlock_stats *
get_lwlock_stats_entry(LWLock *lock)
{
- lwlock_stats_key key;
+ lwlock_stats_key key = {0};
lwlock_stats *lwstats;
bool found;
@@ -397,7 +397,6 @@ get_lwlock_stats_entry(LWLock *lock)
return &lwlock_stats_dummy;
/* Fetch or create the entry. */
- MemSet(&key, 0, sizeof(key));
key.tranche = lock->tranche;
key.instance = lock;
lwstats = hash_search(lwlock_stats_htab, &key, HASH_ENTER, &found);
diff --git a/src/backend/utils/adt/acl.c b/src/backend/utils/adt/acl.c
index b7fd3bcf05..6fa58dd8eb 100644
--- a/src/backend/utils/adt/acl.c
+++ b/src/backend/utils/adt/acl.c
@@ -1785,7 +1785,7 @@ aclexplode(PG_FUNCTION_ARGS)
{
Datum result;
Datum values[4];
- bool nulls[4];
+ bool nulls[4] = {0};
HeapTuple tuple;
values[0] = ObjectIdGetDatum(aidata->ai_grantor);
@@ -1793,8 +1793,6 @@ aclexplode(PG_FUNCTION_ARGS)
values[2] = CStringGetTextDatum(convert_aclright_to_string(priv_bit));
values[3] = BoolGetDatum((ACLITEM_GET_GOPTIONS(*aidata) & priv_bit) != 0);
- MemSet(nulls, 0, sizeof(nulls));
-
tuple = heap_form_tuple(funcctx->tuple_desc, values, nulls);
result = HeapTupleGetDatum(tuple);
diff --git a/src/backend/utils/adt/arrayfuncs.c b/src/backend/utils/adt/arrayfuncs.c
index b0c37ede87..fb167f226a 100644
--- a/src/backend/utils/adt/arrayfuncs.c
+++ b/src/backend/utils/adt/arrayfuncs.c
@@ -742,11 +742,10 @@ ReadArrayStr(char *arrayStr,
bool eoArray = false;
bool hasnull;
int32 totbytes;
- int indx[MAXDIM],
+ int indx[MAXDIM] = {0},
prod[MAXDIM];
mda_get_prod(ndim, dim, prod);
- MemSet(indx, 0, sizeof(indx));
/* Initialize is-null markers to true */
memset(nulls, true, nitems * sizeof(bool));
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 4c12c4d663..8976f4e9f7 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4924,13 +4924,13 @@ pg_timezone_abbrevs(PG_FUNCTION_ARGS)
Datum result;
HeapTuple tuple;
Datum values[3];
- bool nulls[3];
+ bool nulls[3] = {0};
const datetkn *tp;
char buffer[TOKMAXLEN + 1];
int gmtoffset;
bool is_dst;
unsigned char *p;
- struct pg_itm_in itm_in;
+ struct pg_itm_in itm_in = {0};
Interval *resInterval;
/* stuff done only on the first call of the function */
@@ -5011,8 +5011,6 @@ pg_timezone_abbrevs(PG_FUNCTION_ARGS)
break;
}
- MemSet(nulls, 0, sizeof(nulls));
-
/*
* Convert name to text, using upcasing conversion that is the inverse of
* what ParseDateTime() uses.
@@ -5024,7 +5022,6 @@ pg_timezone_abbrevs(PG_FUNCTION_ARGS)
values[0] = CStringGetTextDatum(buffer);
/* Convert offset (in seconds) to an interval; can't overflow */
- MemSet(&itm_in, 0, sizeof(struct pg_itm_in));
itm_in.tm_usec = (int64) gmtoffset * USECS_PER_SEC;
resInterval = (Interval *) palloc(sizeof(Interval));
(void) itmin2interval(&itm_in, resInterval);
@@ -5051,13 +5048,13 @@ pg_timezone_names(PG_FUNCTION_ARGS)
pg_tzenum *tzenum;
pg_tz *tz;
Datum values[4];
- bool nulls[4];
+ bool nulls[4] = {0};
int tzoff;
struct pg_tm tm;
fsec_t fsec;
const char *tzn;
Interval *resInterval;
- struct pg_itm_in itm_in;
+ struct pg_itm_in itm_in = {0};
SetSingleFuncCall(fcinfo, 0);
@@ -5088,13 +5085,10 @@ pg_timezone_names(PG_FUNCTION_ARGS)
if (tzn && strlen(tzn) > 31)
continue;
- MemSet(nulls, 0, sizeof(nulls));
-
values[0] = CStringGetTextDatum(pg_get_timezone_name(tz));
values[1] = CStringGetTextDatum(tzn ? tzn : "");
/* Convert tzoff to an interval; can't overflow */
- MemSet(&itm_in, 0, sizeof(struct pg_itm_in));
itm_in.tm_usec = (int64) -tzoff * USECS_PER_SEC;
resInterval = (Interval *) palloc(sizeof(Interval));
(void) itmin2interval(&itm_in, resInterval);
diff --git a/src/backend/utils/adt/lockfuncs.c b/src/backend/utils/adt/lockfuncs.c
index dedee7af5c..613f5f9bec 100644
--- a/src/backend/utils/adt/lockfuncs.c
+++ b/src/backend/utils/adt/lockfuncs.c
@@ -172,8 +172,8 @@ pg_lock_status(PG_FUNCTION_ARGS)
LOCKMODE mode = 0;
const char *locktypename;
char tnbuf[32];
- Datum values[NUM_LOCK_STATUS_COLUMNS];
- bool nulls[NUM_LOCK_STATUS_COLUMNS];
+ Datum values[NUM_LOCK_STATUS_COLUMNS] = {0};
+ bool nulls[NUM_LOCK_STATUS_COLUMNS] = {0};
HeapTuple tuple;
Datum result;
LockInstanceData *instance;
@@ -230,9 +230,6 @@ pg_lock_status(PG_FUNCTION_ARGS)
/*
* Form tuple with appropriate data.
*/
- MemSet(values, 0, sizeof(values));
- MemSet(nulls, false, sizeof(nulls));
-
if (instance->locktag.locktag_type <= LOCKTAG_LAST_TYPE)
locktypename = LockTagTypeNames[instance->locktag.locktag_type];
else
@@ -359,8 +356,8 @@ pg_lock_status(PG_FUNCTION_ARGS)
PREDICATELOCKTARGETTAG *predTag = &(predLockData->locktags[mystatus->predLockIdx]);
SERIALIZABLEXACT *xact = &(predLockData->xacts[mystatus->predLockIdx]);
- Datum values[NUM_LOCK_STATUS_COLUMNS];
- bool nulls[NUM_LOCK_STATUS_COLUMNS];
+ Datum values[NUM_LOCK_STATUS_COLUMNS] = {0};
+ bool nulls[NUM_LOCK_STATUS_COLUMNS] = {0};
HeapTuple tuple;
Datum result;
@@ -369,8 +366,6 @@ pg_lock_status(PG_FUNCTION_ARGS)
/*
* Form tuple with appropriate data.
*/
- MemSet(values, 0, sizeof(values));
- MemSet(nulls, false, sizeof(nulls));
/* lock type */
lockType = GET_PREDICATELOCKTARGETTAG_TYPE(*predTag);
diff --git a/src/backend/utils/adt/partitionfuncs.c b/src/backend/utils/adt/partitionfuncs.c
index 0243bc061f..109dc8023e 100644
--- a/src/backend/utils/adt/partitionfuncs.c
+++ b/src/backend/utils/adt/partitionfuncs.c
@@ -113,8 +113,8 @@ pg_partition_tree(PG_FUNCTION_ARGS)
if (funcctx->call_cntr < list_length(partitions))
{
Datum result;
- Datum values[PG_PARTITION_TREE_COLS];
- bool nulls[PG_PARTITION_TREE_COLS];
+ Datum values[PG_PARTITION_TREE_COLS] = {0};
+ bool nulls[PG_PARTITION_TREE_COLS] = {0};
HeapTuple tuple;
Oid parentid = InvalidOid;
Oid relid = list_nth_oid(partitions, funcctx->call_cntr);
@@ -126,8 +126,6 @@ pg_partition_tree(PG_FUNCTION_ARGS)
/*
* Form tuple with appropriate data.
*/
- MemSet(nulls, 0, sizeof(nulls));
- MemSet(values, 0, sizeof(values));
/* relid */
values[0] = ObjectIdGetDatum(relid);
diff --git a/src/backend/utils/adt/pgstatfuncs.c b/src/backend/utils/adt/pgstatfuncs.c
index 893690dad5..0a6369fdba 100644
--- a/src/backend/utils/adt/pgstatfuncs.c
+++ b/src/backend/utils/adt/pgstatfuncs.c
@@ -488,13 +488,10 @@ pg_stat_get_progress_info(PG_FUNCTION_ARGS)
{
LocalPgBackendStatus *local_beentry;
PgBackendStatus *beentry;
- Datum values[PG_STAT_GET_PROGRESS_COLS];
- bool nulls[PG_STAT_GET_PROGRESS_COLS];
+ Datum values[PG_STAT_GET_PROGRESS_COLS] = {0};
+ bool nulls[PG_STAT_GET_PROGRESS_COLS] = {0};
int i;
- MemSet(values, 0, sizeof(values));
- MemSet(nulls, 0, sizeof(nulls));
-
local_beentry = pgstat_fetch_stat_local_beentry(curr_backend);
if (!local_beentry)
@@ -551,17 +548,14 @@ pg_stat_get_activity(PG_FUNCTION_ARGS)
for (curr_backend = 1; curr_backend <= num_backends; curr_backend++)
{
/* for each row */
- Datum values[PG_STAT_GET_ACTIVITY_COLS];
- bool nulls[PG_STAT_GET_ACTIVITY_COLS];
+ Datum values[PG_STAT_GET_ACTIVITY_COLS] = {0};
+ bool nulls[PG_STAT_GET_ACTIVITY_COLS] = {0};
LocalPgBackendStatus *local_beentry;
PgBackendStatus *beentry;
PGPROC *proc;
const char *wait_event_type = NULL;
const char *wait_event = NULL;
- MemSet(values, 0, sizeof(values));
- MemSet(nulls, 0, sizeof(nulls));
-
/* Get the next one in the list */
local_beentry = pgstat_fetch_stat_local_beentry(curr_backend);
if (!local_beentry)
@@ -1747,15 +1741,11 @@ pg_stat_get_wal(PG_FUNCTION_ARGS)
{
#define PG_STAT_GET_WAL_COLS 9
TupleDesc tupdesc;
- Datum values[PG_STAT_GET_WAL_COLS];
- bool nulls[PG_STAT_GET_WAL_COLS];
+ Datum values[PG_STAT_GET_WAL_COLS] = {0};
+ bool nulls[PG_STAT_GET_WAL_COLS] = {0};
char buf[256];
PgStat_WalStats *wal_stats;
- /* Initialise values and NULL flags arrays */
- MemSet(values, 0, sizeof(values));
- MemSet(nulls, 0, sizeof(nulls));
-
/* Initialise attributes information in the tuple descriptor */
tupdesc = CreateTemplateTupleDesc(PG_STAT_GET_WAL_COLS);
TupleDescInitEntry(tupdesc, (AttrNumber) 1, "wal_records",
@@ -1827,7 +1817,7 @@ pg_stat_get_slru(PG_FUNCTION_ARGS)
{
/* for each row */
Datum values[PG_STAT_GET_SLRU_COLS];
- bool nulls[PG_STAT_GET_SLRU_COLS];
+ bool nulls[PG_STAT_GET_SLRU_COLS] = {0};
PgStat_SLRUStats stat;
const char *name;
@@ -1837,8 +1827,6 @@ pg_stat_get_slru(PG_FUNCTION_ARGS)
break;
stat = stats[i];
- MemSet(values, 0, sizeof(values));
- MemSet(nulls, 0, sizeof(nulls));
values[0] = PointerGetDatum(cstring_to_text(name));
values[1] = Int64GetDatum(stat.blocks_zeroed);
@@ -2201,14 +2189,10 @@ Datum
pg_stat_get_archiver(PG_FUNCTION_ARGS)
{
TupleDesc tupdesc;
- Datum values[7];
- bool nulls[7];
+ Datum values[7] = {0};
+ bool nulls[7] = {0};
PgStat_ArchiverStats *archiver_stats;
- /* Initialise values and NULL flags arrays */
- MemSet(values, 0, sizeof(values));
- MemSet(nulls, 0, sizeof(nulls));
-
/* Initialise attributes information in the tuple descriptor */
tupdesc = CreateTemplateTupleDesc(7);
TupleDescInitEntry(tupdesc, (AttrNumber) 1, "archived_count",
@@ -2274,15 +2258,11 @@ pg_stat_get_replication_slot(PG_FUNCTION_ARGS)
text *slotname_text = PG_GETARG_TEXT_P(0);
NameData slotname;
TupleDesc tupdesc;
- Datum values[PG_STAT_GET_REPLICATION_SLOT_COLS];
- bool nulls[PG_STAT_GET_REPLICATION_SLOT_COLS];
+ Datum values[PG_STAT_GET_REPLICATION_SLOT_COLS] = {0};
+ bool nulls[PG_STAT_GET_REPLICATION_SLOT_COLS] = {0};
PgStat_StatReplSlotEntry *slotent;
PgStat_StatReplSlotEntry allzero;
- /* Initialise values and NULL flags arrays */
- MemSet(values, 0, sizeof(values));
- MemSet(nulls, 0, sizeof(nulls));
-
/* Initialise attributes information in the tuple descriptor */
tupdesc = CreateTemplateTupleDesc(PG_STAT_GET_REPLICATION_SLOT_COLS);
TupleDescInitEntry(tupdesc, (AttrNumber) 1, "slot_name",
@@ -2348,8 +2328,8 @@ pg_stat_get_subscription_stats(PG_FUNCTION_ARGS)
#define PG_STAT_GET_SUBSCRIPTION_STATS_COLS 4
Oid subid = PG_GETARG_OID(0);
TupleDesc tupdesc;
- Datum values[PG_STAT_GET_SUBSCRIPTION_STATS_COLS];
- bool nulls[PG_STAT_GET_SUBSCRIPTION_STATS_COLS];
+ Datum values[PG_STAT_GET_SUBSCRIPTION_STATS_COLS] = {0};
+ bool nulls[PG_STAT_GET_SUBSCRIPTION_STATS_COLS] = {0};
PgStat_StatSubEntry *subentry;
PgStat_StatSubEntry allzero;
@@ -2368,10 +2348,6 @@ pg_stat_get_subscription_stats(PG_FUNCTION_ARGS)
TIMESTAMPTZOID, -1, 0);
BlessTupleDesc(tupdesc);
- /* Initialise values and NULL flags arrays */
- MemSet(values, 0, sizeof(values));
- MemSet(nulls, 0, sizeof(nulls));
-
if (!subentry)
{
/* If the subscription is not found, initialise its stats */
diff --git a/src/backend/utils/adt/selfuncs.c b/src/backend/utils/adt/selfuncs.c
index fa1f589fad..6f99b5b243 100644
--- a/src/backend/utils/adt/selfuncs.c
+++ b/src/backend/utils/adt/selfuncs.c
@@ -6642,10 +6642,10 @@ btcostestimate(PlannerInfo *root, IndexPath *path, double loop_count,
double *indexPages)
{
IndexOptInfo *index = path->indexinfo;
- GenericCosts costs;
+ GenericCosts costs = {0};
Oid relid;
AttrNumber colnum;
- VariableStatData vardata;
+ VariableStatData vardata = {0};
double numIndexTuples;
Cost descentCost;
List *indexBoundQuals;
@@ -6797,7 +6797,6 @@ btcostestimate(PlannerInfo *root, IndexPath *path, double loop_count,
/*
* Now do generic index cost estimation.
*/
- MemSet(&costs, 0, sizeof(costs));
costs.numIndexTuples = numIndexTuples;
genericcostestimate(root, path, loop_count, &costs);
@@ -6842,8 +6841,6 @@ btcostestimate(PlannerInfo *root, IndexPath *path, double loop_count,
* ordering, but don't negate it entirely. Before 8.0 we divided the
* correlation by the number of columns, but that seems too strong.)
*/
- MemSet(&vardata, 0, sizeof(vardata));
-
if (index->indexkeys[0] != 0)
{
/* Simple variable --- look to stats for the underlying table */
@@ -6947,9 +6944,7 @@ hashcostestimate(PlannerInfo *root, IndexPath *path, double loop_count,
Selectivity *indexSelectivity, double *indexCorrelation,
double *indexPages)
{
- GenericCosts costs;
-
- MemSet(&costs, 0, sizeof(costs));
+ GenericCosts costs = {0};
genericcostestimate(root, path, loop_count, &costs);
@@ -6992,11 +6987,9 @@ gistcostestimate(PlannerInfo *root, IndexPath *path, double loop_count,
double *indexPages)
{
IndexOptInfo *index = path->indexinfo;
- GenericCosts costs;
+ GenericCosts costs = {0};
Cost descentCost;
- MemSet(&costs, 0, sizeof(costs));
-
genericcostestimate(root, path, loop_count, &costs);
/*
@@ -7049,11 +7042,9 @@ spgcostestimate(PlannerInfo *root, IndexPath *path, double loop_count,
double *indexPages)
{
IndexOptInfo *index = path->indexinfo;
- GenericCosts costs;
+ GenericCosts costs = {0};
Cost descentCost;
- MemSet(&costs, 0, sizeof(costs));
-
genericcostestimate(root, path, loop_count, &costs);
/*
diff --git a/src/backend/utils/adt/timestamp.c b/src/backend/utils/adt/timestamp.c
index f70f829d83..0a17f45e92 100644
--- a/src/backend/utils/adt/timestamp.c
+++ b/src/backend/utils/adt/timestamp.c
@@ -2403,7 +2403,7 @@ interval_cmp_value(const Interval *interval)
}
static int
-interval_cmp_internal(Interval *interval1, Interval *interval2)
+interval_cmp_internal(const Interval *interval1, const Interval *interval2)
{
INT128 span1 = interval_cmp_value(interval1);
INT128 span2 = interval_cmp_value(interval2);
@@ -5777,7 +5777,7 @@ generate_series_timestamp(PG_FUNCTION_ARGS)
Timestamp finish = PG_GETARG_TIMESTAMP(1);
Interval *step = PG_GETARG_INTERVAL_P(2);
MemoryContext oldcontext;
- Interval interval_zero;
+ Interval interval_zero = {0};
/* create a function context for cross-call persistence */
funcctx = SRF_FIRSTCALL_INIT();
@@ -5800,7 +5800,6 @@ generate_series_timestamp(PG_FUNCTION_ARGS)
fctx->step = *step;
/* Determine sign of the interval */
- MemSet(&interval_zero, 0, sizeof(Interval));
fctx->step_sign = interval_cmp_internal(&fctx->step, &interval_zero);
if (fctx->step_sign == 0)
@@ -5857,7 +5856,7 @@ generate_series_timestamptz(PG_FUNCTION_ARGS)
TimestampTz finish = PG_GETARG_TIMESTAMPTZ(1);
Interval *step = PG_GETARG_INTERVAL_P(2);
MemoryContext oldcontext;
- Interval interval_zero;
+ Interval interval_zero = {0};
/* create a function context for cross-call persistence */
funcctx = SRF_FIRSTCALL_INIT();
@@ -5880,7 +5879,6 @@ generate_series_timestamptz(PG_FUNCTION_ARGS)
fctx->step = *step;
/* Determine sign of the interval */
- MemSet(&interval_zero, 0, sizeof(Interval));
fctx->step_sign = interval_cmp_internal(&fctx->step, &interval_zero);
if (fctx->step_sign == 0)
diff --git a/src/backend/utils/adt/tsrank.c b/src/backend/utils/adt/tsrank.c
index 3858fc5928..7d78219b62 100644
--- a/src/backend/utils/adt/tsrank.c
+++ b/src/backend/utils/adt/tsrank.c
@@ -853,7 +853,7 @@ calc_rank_cd(const float4 *arrdata, TSVector txt, TSQuery query, int method)
int len,
i,
doclen = 0;
- CoverExt ext;
+ CoverExt ext = {0};
double Wdoc = 0.0;
double invws[lengthof(weights)];
double SumDist = 0.0,
@@ -883,7 +883,6 @@ calc_rank_cd(const float4 *arrdata, TSVector txt, TSQuery query, int method)
return 0.0;
}
- MemSet(&ext, 0, sizeof(CoverExt));
while (Cover(doc, doclen, &qr, &ext))
{
double Cpos = 0.0;
diff --git a/src/backend/utils/cache/relfilenumbermap.c b/src/backend/utils/cache/relfilenumbermap.c
index c4245d5ccd..ada0efa8f2 100644
--- a/src/backend/utils/cache/relfilenumbermap.c
+++ b/src/backend/utils/cache/relfilenumbermap.c
@@ -143,7 +143,7 @@ RelidByRelfilenumber(Oid reltablespace, RelFileNumber relfilenumber)
SysScanDesc scandesc;
Relation relation;
HeapTuple ntp;
- ScanKeyData skey[2];
+ ScanKeyData skey[2] = {0};
Oid relid;
if (RelfilenumberMapHash == NULL)
@@ -153,7 +153,6 @@ RelidByRelfilenumber(Oid reltablespace, RelFileNumber relfilenumber)
if (reltablespace == MyDatabaseTableSpace)
reltablespace = 0;
- MemSet(&key, 0, sizeof(key));
key.reltablespace = reltablespace;
key.relfilenumber = relfilenumber;
diff --git a/src/backend/utils/cache/ts_cache.c b/src/backend/utils/cache/ts_cache.c
index 24808dfbb1..70e88fd228 100644
--- a/src/backend/utils/cache/ts_cache.c
+++ b/src/backend/utils/cache/ts_cache.c
@@ -414,7 +414,7 @@ lookup_ts_config_cache(Oid cfgId)
ScanKeyData mapskey;
SysScanDesc mapscan;
HeapTuple maptup;
- ListDictionary maplists[MAXTOKENTYPE + 1];
+ ListDictionary maplists[MAXTOKENTYPE + 1] = {0};
Oid mapdicts[MAXDICTSPERTT];
int maxtokentype;
int ndicts;
@@ -468,7 +468,6 @@ lookup_ts_config_cache(Oid cfgId)
* see the entries in maptokentype order, and in mapseqno order for
* each token type, even though we didn't explicitly ask for that.
*/
- MemSet(maplists, 0, sizeof(maplists));
maxtokentype = 0;
ndicts = 0;
diff --git a/src/backend/utils/misc/ps_status.c b/src/backend/utils/misc/ps_status.c
index 8520ce76bb..264d0ab1df 100644
--- a/src/backend/utils/misc/ps_status.c
+++ b/src/backend/utils/misc/ps_status.c
@@ -376,7 +376,7 @@ set_ps_display(const char *activity)
#ifdef PS_USE_CLOBBER_ARGV
/* pad unused memory; need only clobber remainder of old status string */
if (last_status_len > ps_buffer_cur_len)
- MemSet(ps_buffer + ps_buffer_cur_len, PS_PADDING,
+ memset(ps_buffer + ps_buffer_cur_len, PS_PADDING,
last_status_len - ps_buffer_cur_len);
last_status_len = ps_buffer_cur_len;
#endif /* PS_USE_CLOBBER_ARGV */
diff --git a/src/backend/utils/misc/timeout.c b/src/backend/utils/misc/timeout.c
index 6f5e08bc30..284b9153ea 100644
--- a/src/backend/utils/misc/timeout.c
+++ b/src/backend/utils/misc/timeout.c
@@ -211,13 +211,11 @@ schedule_alarm(TimestampTz now)
{
if (num_active_timeouts > 0)
{
- struct itimerval timeval;
+ struct itimerval timeval = {0};
TimestampTz nearest_timeout;
long secs;
int usecs;
- MemSet(&timeval, 0, sizeof(struct itimerval));
-
/*
* If we think there's a signal pending, but current time is more than
* 10ms past when the signal was due, then assume that the timeout
diff --git a/src/backend/utils/mmgr/portalmem.c b/src/backend/utils/mmgr/portalmem.c
index d549f66d4a..3a161bdb88 100644
--- a/src/backend/utils/mmgr/portalmem.c
+++ b/src/backend/utils/mmgr/portalmem.c
@@ -1146,14 +1146,12 @@ pg_cursor(PG_FUNCTION_ARGS)
{
Portal portal = hentry->portal;
Datum values[6];
- bool nulls[6];
+ bool nulls[6] = {0};
/* report only "visible" entries */
if (!portal->visible)
continue;
- MemSet(nulls, 0, sizeof(nulls));
-
values[0] = CStringGetTextDatum(portal->name);
values[1] = CStringGetTextDatum(portal->sourceText);
values[2] = BoolGetDatum(portal->cursorOptions & CURSOR_OPT_HOLD);
diff --git a/src/bin/pg_basebackup/pg_basebackup.c b/src/bin/pg_basebackup/pg_basebackup.c
index 4445a86aee..79b23fa7d7 100644
--- a/src/bin/pg_basebackup/pg_basebackup.c
+++ b/src/bin/pg_basebackup/pg_basebackup.c
@@ -447,7 +447,7 @@ reached_end_position(XLogRecPtr segendpos, uint32 timeline,
{
#ifndef WIN32
fd_set fds;
- struct timeval tv;
+ struct timeval tv = {0};
int r;
/*
@@ -457,16 +457,13 @@ reached_end_position(XLogRecPtr segendpos, uint32 timeline,
FD_ZERO(&fds);
FD_SET(bgpipe[0], &fds);
- MemSet(&tv, 0, sizeof(tv));
-
r = select(bgpipe[0] + 1, &fds, NULL, NULL, &tv);
if (r == 1)
{
- char xlogend[64];
+ char xlogend[64] = {0};
uint32 hi,
lo;
- MemSet(xlogend, 0, sizeof(xlogend));
r = read(bgpipe[0], xlogend, sizeof(xlogend) - 1);
if (r < 0)
pg_fatal("could not read from ready pipe: %m");
@@ -528,11 +525,10 @@ typedef struct
static int
LogStreamerMain(logstreamer_param *param)
{
- StreamCtl stream;
+ StreamCtl stream = {0};
in_log_streamer = true;
- MemSet(&stream, 0, sizeof(stream));
stream.startpos = param->startptr;
stream.timeline = param->timeline;
stream.sysidentifier = param->sysidentifier;
@@ -1952,7 +1948,6 @@ BaseBackup(char *compression_algorithm, char *compression_detail,
else
starttli = latesttli;
PQclear(res);
- MemSet(xlogend, 0, sizeof(xlogend));
if (verbose && includewal != NO_WAL)
pg_log_info("write-ahead log start point: %s on timeline %u",
diff --git a/src/bin/pg_basebackup/pg_receivewal.c b/src/bin/pg_basebackup/pg_receivewal.c
index ea3902c971..f064cff4ab 100644
--- a/src/bin/pg_basebackup/pg_receivewal.c
+++ b/src/bin/pg_basebackup/pg_receivewal.c
@@ -564,11 +564,9 @@ StreamLog(void)
{
XLogRecPtr serverpos;
TimeLineID servertli;
- StreamCtl stream;
+ StreamCtl stream = {0};
char *sysidentifier;
- MemSet(&stream, 0, sizeof(stream));
-
/*
* Connect in replication mode to the server
*/
diff --git a/src/bin/pg_basebackup/walmethods.c b/src/bin/pg_basebackup/walmethods.c
index ef4c11277a..e90aa0ba37 100644
--- a/src/bin/pg_basebackup/walmethods.c
+++ b/src/bin/pg_basebackup/walmethods.c
@@ -1111,9 +1111,8 @@ tar_close(Walfile f, WalCloseMethod method)
padding = tarPaddingBytesRequired(filesize);
if (padding)
{
- char zerobuf[TAR_BLOCK_SIZE];
+ char zerobuf[TAR_BLOCK_SIZE] = {0};
- MemSet(zerobuf, 0, padding);
if (tar_write(f, zerobuf, padding) != padding)
return -1;
}
@@ -1222,7 +1221,7 @@ tar_existsfile(const char *pathname)
static bool
tar_finish(void)
{
- char zerobuf[1024];
+ char zerobuf[1024] = {0};
tar_clear_error();
@@ -1233,7 +1232,6 @@ tar_finish(void)
}
/* A tarfile always ends with two empty blocks */
- MemSet(zerobuf, 0, sizeof(zerobuf));
if (tar_data->compression_algorithm == PG_COMPRESSION_NONE)
{
errno = 0;
diff --git a/src/common/ip.c b/src/common/ip.c
index cd73d49679..267103efb9 100644
--- a/src/common/ip.c
+++ b/src/common/ip.c
@@ -165,14 +165,12 @@ static int
getaddrinfo_unix(const char *path, const struct addrinfo *hintsp,
struct addrinfo **result)
{
- struct addrinfo hints;
+ struct addrinfo hints = {0};
struct addrinfo *aip;
struct sockaddr_un *unp;
*result = NULL;
- MemSet(&hints, 0, sizeof(hints));
-
if (strlen(path) >= sizeof(unp->sun_path))
return EAI_FAIL;
diff --git a/src/interfaces/libpq/fe-connect.c b/src/interfaces/libpq/fe-connect.c
index dc49387d6c..0362500386 100644
--- a/src/interfaces/libpq/fe-connect.c
+++ b/src/interfaces/libpq/fe-connect.c
@@ -2325,7 +2325,7 @@ keep_going: /* We will come back to here until there is
if (conn->try_next_host)
{
pg_conn_host *ch;
- struct addrinfo hint;
+ struct addrinfo hint = {0};
int thisport;
int ret;
char portstr[MAXPGPATH];
@@ -2364,7 +2364,6 @@ keep_going: /* We will come back to here until there is
ch = &conn->connhost[conn->whichhost];
/* Initialize hint structure */
- MemSet(&hint, 0, sizeof(hint));
hint.ai_socktype = SOCK_STREAM;
conn->addrlist_family = hint.ai_family = AF_UNSPEC;
diff --git a/src/pl/plperl/plperl.c b/src/pl/plperl/plperl.c
index edb93ec1c4..6272e093c5 100644
--- a/src/pl/plperl/plperl.c
+++ b/src/pl/plperl/plperl.c
@@ -1841,10 +1841,9 @@ plperl_call_handler(PG_FUNCTION_ARGS)
Datum retval = (Datum) 0;
plperl_call_data *volatile save_call_data = current_call_data;
plperl_interp_desc *volatile oldinterp = plperl_active_interp;
- plperl_call_data this_call_data;
+ plperl_call_data this_call_data = {0};
/* Initialize current-call status record */
- MemSet(&this_call_data, 0, sizeof(this_call_data));
this_call_data.fcinfo = fcinfo;
PG_TRY();
@@ -1882,16 +1881,13 @@ plperl_inline_handler(PG_FUNCTION_ARGS)
{
LOCAL_FCINFO(fake_fcinfo, 0);
InlineCodeBlock *codeblock = (InlineCodeBlock *) PG_GETARG_POINTER(0);
- FmgrInfo flinfo;
- plperl_proc_desc desc;
+ FmgrInfo flinfo = {0};
+ plperl_proc_desc desc = {0};
plperl_call_data *volatile save_call_data = current_call_data;
plperl_interp_desc *volatile oldinterp = plperl_active_interp;
- plperl_call_data this_call_data;
+ plperl_call_data this_call_data = {0};
ErrorContextCallback pl_error_context;
- /* Initialize current-call status record */
- MemSet(&this_call_data, 0, sizeof(this_call_data));
-
/* Set up a callback for error reporting */
pl_error_context.callback = plperl_inline_callback;
pl_error_context.previous = error_context_stack;
@@ -1904,8 +1900,6 @@ plperl_inline_handler(PG_FUNCTION_ARGS)
* with no arguments passed, and a result type of VOID.
*/
MemSet(fake_fcinfo, 0, SizeForFunctionCallInfo(0));
- MemSet(&flinfo, 0, sizeof(flinfo));
- MemSet(&desc, 0, sizeof(desc));
fake_fcinfo->flinfo = &flinfo;
flinfo.fn_oid = InvalidOid;
flinfo.fn_mcxt = CurrentMemoryContext;
diff --git a/src/pl/plpgsql/src/pl_handler.c b/src/pl/plpgsql/src/pl_handler.c
index 190d286f1c..1f8c9edfa8 100644
--- a/src/pl/plpgsql/src/pl_handler.c
+++ b/src/pl/plpgsql/src/pl_handler.c
@@ -317,7 +317,7 @@ plpgsql_inline_handler(PG_FUNCTION_ARGS)
LOCAL_FCINFO(fake_fcinfo, 0);
InlineCodeBlock *codeblock = castNode(InlineCodeBlock, DatumGetPointer(PG_GETARG_DATUM(0)));
PLpgSQL_function *func;
- FmgrInfo flinfo;
+ FmgrInfo flinfo = {0};
EState *simple_eval_estate;
ResourceOwner simple_eval_resowner;
Datum retval;
@@ -341,7 +341,6 @@ plpgsql_inline_handler(PG_FUNCTION_ARGS)
* with no arguments passed.
*/
MemSet(fake_fcinfo, 0, SizeForFunctionCallInfo(0));
- MemSet(&flinfo, 0, sizeof(flinfo));
fake_fcinfo->flinfo = &flinfo;
flinfo.fn_oid = InvalidOid;
flinfo.fn_mcxt = CurrentMemoryContext;
@@ -502,10 +501,10 @@ plpgsql_validator(PG_FUNCTION_ARGS)
if (check_function_bodies)
{
LOCAL_FCINFO(fake_fcinfo, 0);
- FmgrInfo flinfo;
+ FmgrInfo flinfo = {0};
int rc;
- TriggerData trigdata;
- EventTriggerData etrigdata;
+ TriggerData trigdata = {0};
+ EventTriggerData etrigdata = {0};
/*
* Connect to SPI manager (is this needed for compilation?)
@@ -518,19 +517,16 @@ plpgsql_validator(PG_FUNCTION_ARGS)
* plpgsql_compile().
*/
MemSet(fake_fcinfo, 0, SizeForFunctionCallInfo(0));
- MemSet(&flinfo, 0, sizeof(flinfo));
fake_fcinfo->flinfo = &flinfo;
flinfo.fn_oid = funcoid;
flinfo.fn_mcxt = CurrentMemoryContext;
if (is_dml_trigger)
{
- MemSet(&trigdata, 0, sizeof(trigdata));
trigdata.type = T_TriggerData;
fake_fcinfo->context = (Node *) &trigdata;
}
else if (is_event_trigger)
{
- MemSet(&etrigdata, 0, sizeof(etrigdata));
etrigdata.type = T_EventTriggerData;
fake_fcinfo->context = (Node *) &etrigdata;
}
diff --git a/src/pl/plpython/plpy_main.c b/src/pl/plpython/plpy_main.c
index 0bce106495..1df2dd536c 100644
--- a/src/pl/plpython/plpy_main.c
+++ b/src/pl/plpython/plpy_main.c
@@ -266,8 +266,8 @@ plpython3_inline_handler(PG_FUNCTION_ARGS)
{
LOCAL_FCINFO(fake_fcinfo, 0);
InlineCodeBlock *codeblock = (InlineCodeBlock *) DatumGetPointer(PG_GETARG_DATUM(0));
- FmgrInfo flinfo;
- PLyProcedure proc;
+ FmgrInfo flinfo = {0};
+ PLyProcedure proc = {0};
PLyExecutionContext *exec_ctx;
ErrorContextCallback plerrcontext;
@@ -278,12 +278,10 @@ plpython3_inline_handler(PG_FUNCTION_ARGS)
elog(ERROR, "SPI_connect failed");
MemSet(fcinfo, 0, SizeForFunctionCallInfo(0));
- MemSet(&flinfo, 0, sizeof(flinfo));
fake_fcinfo->flinfo = &flinfo;
flinfo.fn_oid = InvalidOid;
flinfo.fn_mcxt = CurrentMemoryContext;
- MemSet(&proc, 0, sizeof(PLyProcedure));
proc.mcxt = AllocSetContextCreate(TopMemoryContext,
"__plpython_inline_block",
ALLOCSET_DEFAULT_SIZES);
diff --git a/src/port/snprintf.c b/src/port/snprintf.c
index abb1c59770..d4cf368075 100644
--- a/src/port/snprintf.c
+++ b/src/port/snprintf.c
@@ -756,12 +756,10 @@ find_arguments(const char *format, va_list args,
int longflag;
int fmtpos;
int i;
- int last_dollar;
- PrintfArgType argtypes[PG_NL_ARGMAX + 1];
/* Initialize to "no dollar arguments known" */
- last_dollar = 0;
- MemSet(argtypes, 0, sizeof(argtypes));
+ int last_dollar = 0;
+ PrintfArgType argtypes[PG_NL_ARGMAX + 1] = {0};
/*
* This loop must accept the same format strings as the one in dopr().
diff --git a/src/test/modules/test_predtest/test_predtest.c b/src/test/modules/test_predtest/test_predtest.c
index 3b19e0eadc..2ce88cb624 100644
--- a/src/test/modules/test_predtest/test_predtest.c
+++ b/src/test/modules/test_predtest/test_predtest.c
@@ -50,7 +50,7 @@ test_predtest(PG_FUNCTION_ARGS)
strong_refuted_by,
weak_refuted_by;
Datum values[8];
- bool nulls[8];
+ bool nulls[8] = {0};
int i;
/* We use SPI to parse, plan, and execute the test query */
@@ -204,7 +204,6 @@ test_predtest(PG_FUNCTION_ARGS)
"w_r_holds", BOOLOID, -1, 0);
tupdesc = BlessTupleDesc(tupdesc);
- MemSet(nulls, 0, sizeof(nulls));
values[0] = BoolGetDatum(strong_implied_by);
values[1] = BoolGetDatum(weak_implied_by);
values[2] = BoolGetDatum(strong_refuted_by);
diff --git a/src/test/regress/regress.c b/src/test/regress/regress.c
index ba3532a51e..b88d70b6fc 100644
--- a/src/test/regress/regress.c
+++ b/src/test/regress/regress.c
@@ -1110,7 +1110,7 @@ test_enc_conversion(PG_FUNCTION_ARGS)
int convertedbytes;
int dstlen;
Datum values[2];
- bool nulls[2];
+ bool nulls[2] = {0};
HeapTuple tuple;
if (src_encoding < 0)
@@ -1199,7 +1199,6 @@ test_enc_conversion(PG_FUNCTION_ARGS)
pfree(dst);
}
- MemSet(nulls, 0, sizeof(nulls));
values[0] = Int32GetDatum(convertedbytes);
values[1] = PointerGetDatum(retval);
tuple = heap_form_tuple(tupdesc, values, nulls);On 11.07.22 21:06, Ranier Vilela wrote:
Em qui., 7 de jul. de 2022 às 14:01, Ranier Vilela <ranier.vf@gmail.com
<mailto:ranier.vf@gmail.com>> escreveu:Attached the v1 of your patch.
I think that all is safe to switch MemSet by {0}.Here the rebased patch v2, against latest head.
I have committed my patch with Álvaro's comments addressed.
Your patch appears to add in changes that are either arguably out of
scope or would need further review (e.g., changing memset() calls,
changing the scope of some variables, changing places that need to worry
about padding bits). Please submit separate patches for those, and we
can continue the analysis.
Em sáb, 16 de jul de 2022 2:58 AM, Peter Eisentraut <
peter.eisentraut@enterprisedb.com> escreveu:
On 11.07.22 21:06, Ranier Vilela wrote:
Em qui., 7 de jul. de 2022 às 14:01, Ranier Vilela <ranier.vf@gmail.com
<mailto:ranier.vf@gmail.com>> escreveu:Attached the v1 of your patch.
I think that all is safe to switch MemSet by {0}.Here the rebased patch v2, against latest head.
I have committed my patch with Álvaro's comments addressed
I see.
It's annoing that old compiler (gcc 4.7.2) don't handle this style.
Your patch appears to add in changes that are either arguably out of
scope or would need further review (e.g., changing memset() calls,
changing the scope of some variables, changing places that need to worry
about padding bits). Please submit separate patches for those, and we
can continue the analysis.
Sure.
Regards
Ranier Vilela
Show quoted text
Em sáb., 16 de jul. de 2022 às 16:54, Ranier Vilela <ranier.vf@gmail.com>
escreveu:
Em sáb, 16 de jul de 2022 2:58 AM, Peter Eisentraut <
peter.eisentraut@enterprisedb.com> escreveu:On 11.07.22 21:06, Ranier Vilela wrote:
Em qui., 7 de jul. de 2022 às 14:01, Ranier Vilela <ranier.vf@gmail.com
<mailto:ranier.vf@gmail.com>> escreveu:Attached the v1 of your patch.
I think that all is safe to switch MemSet by {0}.Here the rebased patch v2, against latest head.
I have committed my patch with Álvaro's comments addressed
I see.
It's annoing that old compiler (gcc 4.7.2) don't handle this style.Your patch appears to add in changes that are either arguably out of
scope or would need further review (e.g., changing memset() calls,
changing the scope of some variables, changing places that need to worry
about padding bits). Please submit separate patches for those, and we
can continue the analysis.Sure.
Hi, sorry for the delay.
Like how
https://github.com/postgres/postgres/commit/9fd45870c1436b477264c0c82eb195df52bc0919
New attempt to remove more MemSet calls, that are safe.
Attached v3 patch.
regards,
Ranier Vilela
Show quoted text
Attachments:
v3-0001-WIP-Replace-MemSet-calls-with-struct-initialization.patchapplication/octet-stream; name=v3-0001-WIP-Replace-MemSet-calls-with-struct-initialization.patchDownload
diff --git a/contrib/pageinspect/heapfuncs.c b/contrib/pageinspect/heapfuncs.c
index 2ff70405cf..01ce9014ec 100644
--- a/contrib/pageinspect/heapfuncs.c
+++ b/contrib/pageinspect/heapfuncs.c
@@ -180,8 +180,8 @@ heap_page_items(PG_FUNCTION_ARGS)
HeapTuple resultTuple;
Datum result;
ItemId id;
- Datum values[14];
- bool nulls[14];
+ Datum values[14] = {0};
+ bool nulls[14] = {0};
uint16 lp_offset;
uint16 lp_flags;
uint16 lp_len;
diff --git a/contrib/pg_trgm/trgm_regexp.c b/contrib/pg_trgm/trgm_regexp.c
index 58d32ba946..79c925b8dd 100644
--- a/contrib/pg_trgm/trgm_regexp.c
+++ b/contrib/pg_trgm/trgm_regexp.c
@@ -905,7 +905,7 @@ static void
transformGraph(TrgmNFA *trgmNFA)
{
HASHCTL hashCtl;
- TrgmStateKey initkey;
+ TrgmStateKey initkey = {0};
TrgmState *initstate;
ListCell *lc;
@@ -926,7 +926,6 @@ transformGraph(TrgmNFA *trgmNFA)
trgmNFA->nstates = 0;
/* Create initial state: ambiguous prefix, NFA's initial state */
- MemSet(&initkey, 0, sizeof(initkey));
initkey.prefix.colors[0] = COLOR_UNKNOWN;
initkey.prefix.colors[1] = COLOR_UNKNOWN;
initkey.nstate = pg_reg_getinitialstate(trgmNFA->regex);
@@ -1019,17 +1018,11 @@ static void
addKey(TrgmNFA *trgmNFA, TrgmState *state, TrgmStateKey *key)
{
regex_arc_t *arcs;
- TrgmStateKey destKey;
+ TrgmStateKey destKey = {0};
ListCell *cell;
int i,
arcsCount;
- /*
- * Ensure any pad bytes in destKey are zero, since it may get used as a
- * hashtable key by getState.
- */
- MemSet(&destKey, 0, sizeof(destKey));
-
/*
* Compare key to each existing enter key of the state to check for
* redundancy. We can drop either old key(s) or the new key if we find
@@ -1199,18 +1192,12 @@ addKeyToQueue(TrgmNFA *trgmNFA, TrgmStateKey *key)
static void
addArcs(TrgmNFA *trgmNFA, TrgmState *state)
{
- TrgmStateKey destKey;
+ TrgmStateKey destKey = {0};
ListCell *cell;
regex_arc_t *arcs;
int arcsCount,
i;
- /*
- * Ensure any pad bytes in destKey are zero, since it may get used as a
- * hashtable key by getState.
- */
- MemSet(&destKey, 0, sizeof(destKey));
-
/*
* Iterate over enter keys associated with this expanded-graph state. This
* includes both the state's own stateKey, and any enter keys we added to
diff --git a/contrib/postgres_fdw/postgres_fdw.c b/contrib/postgres_fdw/postgres_fdw.c
index 048db542d3..ee5b1b246f 100644
--- a/contrib/postgres_fdw/postgres_fdw.c
+++ b/contrib/postgres_fdw/postgres_fdw.c
@@ -3307,7 +3307,7 @@ estimate_path_cost_size(PlannerInfo *root,
{
RelOptInfo *outerrel = fpinfo->outerrel;
PgFdwRelationInfo *ofpinfo;
- AggClauseCosts aggcosts;
+ AggClauseCosts aggcosts = {0};
double input_rows;
int numGroupCols;
double numGroups = 1;
@@ -3331,7 +3331,6 @@ estimate_path_cost_size(PlannerInfo *root,
input_rows = ofpinfo->rows;
/* Collect statistics about aggregates for estimating costs. */
- MemSet(&aggcosts, 0, sizeof(AggClauseCosts));
if (root->parse->hasAggs)
{
get_agg_clause_costs(root, AGGSPLIT_SIMPLE, &aggcosts);
diff --git a/contrib/tablefunc/tablefunc.c b/contrib/tablefunc/tablefunc.c
index e308228bde..6452111e19 100644
--- a/contrib/tablefunc/tablefunc.c
+++ b/contrib/tablefunc/tablefunc.c
@@ -127,9 +127,8 @@ typedef struct crosstab_cat_desc
#define crosstab_HashTableLookup(HASHTAB, CATNAME, CATDESC) \
do { \
- crosstab_HashEnt *hentry; char key[MAX_CATNAME_LEN]; \
+ crosstab_HashEnt *hentry; char key[MAX_CATNAME_LEN] = {0}; \
\
- MemSet(key, 0, MAX_CATNAME_LEN); \
snprintf(key, MAX_CATNAME_LEN - 1, "%s", CATNAME); \
hentry = (crosstab_HashEnt*) hash_search(HASHTAB, \
key, HASH_FIND, NULL); \
@@ -141,9 +140,8 @@ do { \
#define crosstab_HashTableInsert(HASHTAB, CATDESC) \
do { \
- crosstab_HashEnt *hentry; bool found; char key[MAX_CATNAME_LEN]; \
+ crosstab_HashEnt *hentry; bool found; char key[MAX_CATNAME_LEN] = {0}; \
\
- MemSet(key, 0, MAX_CATNAME_LEN); \
snprintf(key, MAX_CATNAME_LEN - 1, "%s", CATDESC->catname); \
hentry = (crosstab_HashEnt*) hash_search(HASHTAB, \
key, HASH_ENTER, &found); \
diff --git a/src/backend/access/nbtree/nbtpage.c b/src/backend/access/nbtree/nbtpage.c
index 8b96708b3e..f872076d52 100644
--- a/src/backend/access/nbtree/nbtpage.c
+++ b/src/backend/access/nbtree/nbtpage.c
@@ -2096,7 +2096,7 @@ _bt_mark_page_halfdead(Relation rel, Buffer leafbuf, BTStack stack)
OffsetNumber poffset;
OffsetNumber nextoffset;
IndexTuple itup;
- IndexTupleData trunctuple;
+ IndexTupleData trunctuple = {0};
page = BufferGetPage(leafbuf);
opaque = BTPageGetOpaque(page);
@@ -2220,7 +2220,6 @@ _bt_mark_page_halfdead(Relation rel, Buffer leafbuf, BTStack stack)
opaque->btpo_flags |= BTP_HALF_DEAD;
Assert(PageGetMaxOffsetNumber(page) == P_HIKEY);
- MemSet(&trunctuple, 0, sizeof(IndexTupleData));
trunctuple.t_info = sizeof(IndexTupleData);
if (topparent != leafblkno)
BTreeTupleSetTopParent(&trunctuple, topparent);
diff --git a/src/backend/access/nbtree/nbtxlog.c b/src/backend/access/nbtree/nbtxlog.c
index ad489e33b3..14fe2d76c4 100644
--- a/src/backend/access/nbtree/nbtxlog.c
+++ b/src/backend/access/nbtree/nbtxlog.c
@@ -717,7 +717,7 @@ btree_xlog_mark_page_halfdead(uint8 info, XLogReaderState *record)
Buffer buffer;
Page page;
BTPageOpaque pageop;
- IndexTupleData trunctuple;
+ IndexTupleData trunctuple = {0};
/*
* In normal operation, we would lock all the pages this WAL record
@@ -780,7 +780,6 @@ btree_xlog_mark_page_halfdead(uint8 info, XLogReaderState *record)
* Construct a dummy high key item that points to top parent page (value
* is InvalidBlockNumber when the top parent page is the leaf page itself)
*/
- MemSet(&trunctuple, 0, sizeof(IndexTupleData));
trunctuple.t_info = sizeof(IndexTupleData);
BTreeTupleSetTopParent(&trunctuple, xlrec->topparent);
@@ -898,7 +897,7 @@ btree_xlog_unlink_page(uint8 info, XLogReaderState *record)
* we'll delete in the subtree undergoing deletion.
*/
Buffer leafbuf;
- IndexTupleData trunctuple;
+ IndexTupleData trunctuple = {0};
Assert(!isleaf);
@@ -915,7 +914,6 @@ btree_xlog_unlink_page(uint8 info, XLogReaderState *record)
pageop->btpo_cycleid = 0;
/* Add a dummy hikey item */
- MemSet(&trunctuple, 0, sizeof(IndexTupleData));
trunctuple.t_info = sizeof(IndexTupleData);
BTreeTupleSetTopParent(&trunctuple, xlrec->leaftopparent);
diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c
index 15ab8d90d4..920fcca39c 100644
--- a/src/backend/access/transam/xlog.c
+++ b/src/backend/access/transam/xlog.c
@@ -6287,7 +6287,7 @@ void
CreateCheckPoint(int flags)
{
bool shutdown;
- CheckPoint checkPoint;
+ CheckPoint checkPoint = {0};
XLogRecPtr recptr;
XLogSegNo _logSegNo;
XLogCtlInsert *Insert = &XLogCtl->Insert;
@@ -6344,7 +6344,6 @@ CreateCheckPoint(int flags)
}
/* Begin filling in the checkpoint WAL record */
- MemSet(&checkPoint, 0, sizeof(checkPoint));
checkPoint.time = (pg_time_t) time(NULL);
/*
diff --git a/src/backend/commands/copyfromparse.c b/src/backend/commands/copyfromparse.c
index 57813b3458..cef0f2c279 100644
--- a/src/backend/commands/copyfromparse.c
+++ b/src/backend/commands/copyfromparse.c
@@ -869,7 +869,7 @@ NextCopyFrom(CopyFromState cstate, ExprContext *econtext,
/* Initialize all values for row to NULL */
MemSet(values, 0, num_phys_attrs * sizeof(Datum));
- MemSet(nulls, true, num_phys_attrs * sizeof(bool));
+ memset(nulls, true, num_phys_attrs * sizeof(bool));
if (!cstate->opts.binary)
{
diff --git a/src/backend/libpq/auth.c b/src/backend/libpq/auth.c
index 2d9ab7edce..53fb7ca628 100644
--- a/src/backend/libpq/auth.c
+++ b/src/backend/libpq/auth.c
@@ -3022,7 +3022,7 @@ PerformRadiusTransaction(const char *server, const char *secret, const char *por
struct sockaddr_in localaddr;
struct sockaddr_in remoteaddr;
#endif
- struct addrinfo hint;
+ struct addrinfo hint = {0};
struct addrinfo *serveraddrs;
int port;
socklen_t addrsize;
@@ -3038,7 +3038,6 @@ PerformRadiusTransaction(const char *server, const char *secret, const char *por
if (identifier == NULL)
identifier = "postgresql";
- MemSet(&hint, 0, sizeof(hint));
hint.ai_socktype = SOCK_DGRAM;
hint.ai_family = AF_UNSPEC;
port = atoi(portstr);
diff --git a/src/backend/libpq/pqcomm.c b/src/backend/libpq/pqcomm.c
index 75392a8bb7..803d166640 100644
--- a/src/backend/libpq/pqcomm.c
+++ b/src/backend/libpq/pqcomm.c
@@ -331,7 +331,7 @@ StreamServerPort(int family, const char *hostName, unsigned short portNumber,
char *service;
struct addrinfo *addrs = NULL,
*addr;
- struct addrinfo hint;
+ struct addrinfo hint = {0};
int listen_index = 0;
int added = 0;
@@ -343,7 +343,6 @@ StreamServerPort(int family, const char *hostName, unsigned short portNumber,
#endif
/* Initialize hint structure */
- MemSet(&hint, 0, sizeof(hint));
hint.ai_family = family;
hint.ai_flags = AI_PASSIVE;
hint.ai_socktype = SOCK_STREAM;
diff --git a/src/backend/optimizer/path/indxpath.c b/src/backend/optimizer/path/indxpath.c
index 7d176e7b00..e23995eb4f 100644
--- a/src/backend/optimizer/path/indxpath.c
+++ b/src/backend/optimizer/path/indxpath.c
@@ -608,7 +608,7 @@ get_join_index_paths(PlannerInfo *root, RelOptInfo *rel,
Relids relids,
List **considered_relids)
{
- IndexClauseSet clauseset;
+ IndexClauseSet clauseset = {0};
int indexcol;
/* If we already considered this relids set, don't repeat the work */
@@ -616,8 +616,6 @@ get_join_index_paths(PlannerInfo *root, RelOptInfo *rel,
return;
/* Identify indexclauses usable with this relids set */
- MemSet(&clauseset, 0, sizeof(clauseset));
-
for (indexcol = 0; indexcol < index->nkeycolumns; indexcol++)
{
ListCell *lc;
diff --git a/src/backend/optimizer/plan/planner.c b/src/backend/optimizer/plan/planner.c
index 06ad856eac..77cbe681e5 100644
--- a/src/backend/optimizer/plan/planner.c
+++ b/src/backend/optimizer/plan/planner.c
@@ -3350,9 +3350,8 @@ create_grouping_paths(PlannerInfo *root,
Query *parse = root->parse;
RelOptInfo *grouped_rel;
RelOptInfo *partially_grouped_rel;
- AggClauseCosts agg_costs;
+ AggClauseCosts agg_costs = {0};
- MemSet(&agg_costs, 0, sizeof(AggClauseCosts));
get_agg_clause_costs(root, AGGSPLIT_SIMPLE, &agg_costs);
/*
@@ -5908,16 +5907,14 @@ expression_planner_with_deps(Expr *expr,
List **invalItems)
{
Node *result;
- PlannerGlobal glob;
- PlannerInfo root;
+ PlannerGlobal glob = {0};
+ PlannerInfo root = {0};
/* Make up dummy planner state so we can use setrefs machinery */
- MemSet(&glob, 0, sizeof(glob));
glob.type = T_PlannerGlobal;
glob.relationOids = NIL;
glob.invalItems = NIL;
- MemSet(&root, 0, sizeof(root));
root.type = T_PlannerInfo;
root.glob = &glob;
diff --git a/src/backend/optimizer/plan/setrefs.c b/src/backend/optimizer/plan/setrefs.c
index 1cb0abdbc1..311583acde 100644
--- a/src/backend/optimizer/plan/setrefs.c
+++ b/src/backend/optimizer/plan/setrefs.c
@@ -3292,18 +3292,16 @@ extract_query_dependencies(Node *query,
List **invalItems,
bool *hasRowSecurity)
{
- PlannerGlobal glob;
- PlannerInfo root;
+ PlannerGlobal glob = {0};
+ PlannerInfo root = {0};
/* Make up dummy planner state so we can use this module's machinery */
- MemSet(&glob, 0, sizeof(glob));
glob.type = T_PlannerGlobal;
glob.relationOids = NIL;
glob.invalItems = NIL;
/* Hack: we use glob.dependsOnRole to collect hasRowSecurity flags */
glob.dependsOnRole = false;
- MemSet(&root, 0, sizeof(root));
root.type = T_PlannerInfo;
root.glob = &glob;
diff --git a/src/backend/parser/parse_target.c b/src/backend/parser/parse_target.c
index 16a0fe59e2..d69cb58b6a 100644
--- a/src/backend/parser/parse_target.c
+++ b/src/backend/parser/parse_target.c
@@ -1648,10 +1648,9 @@ expandRecordVariable(ParseState *pstate, Var *var, int levelsup)
* in step with varlevelsup in the CTE; furthermore it
* could be an outer CTE.
*/
- ParseState mypstate;
+ ParseState mypstate = {0};
Index levelsup;
- MemSet(&mypstate, 0, sizeof(mypstate));
/* this loop must work, since GetCTEForRTE did */
for (levelsup = 0;
levelsup < rte->ctelevelsup + netlevelsup;
diff --git a/src/backend/replication/walsender.c b/src/backend/replication/walsender.c
index 3a86786cc3..c4b9a14a8a 100644
--- a/src/backend/replication/walsender.c
+++ b/src/backend/replication/walsender.c
@@ -3532,7 +3532,7 @@ pg_stat_get_wal_senders(PG_FUNCTION_ARGS)
* can see details. Other users only get the pid value to know
* it's a walsender, but no details.
*/
- MemSet(&nulls[1], true, PG_STAT_GET_WAL_SENDERS_COLS - 1);
+ memset(&nulls[1], true, PG_STAT_GET_WAL_SENDERS_COLS - 1);
}
else
{
diff --git a/src/backend/storage/lmgr/lock.c b/src/backend/storage/lmgr/lock.c
index 5f5803f681..ae6a1b1116 100644
--- a/src/backend/storage/lmgr/lock.c
+++ b/src/backend/storage/lmgr/lock.c
@@ -597,13 +597,12 @@ DoLockModesConflict(LOCKMODE mode1, LOCKMODE mode2)
bool
LockHeldByMe(const LOCKTAG *locktag, LOCKMODE lockmode)
{
- LOCALLOCKTAG localtag;
+ LOCALLOCKTAG localtag = {0};
LOCALLOCK *locallock;
/*
* See if there is a LOCALLOCK entry for this lock and lockmode
*/
- MemSet(&localtag, 0, sizeof(localtag)); /* must clear padding */
localtag.lock = *locktag;
localtag.mode = lockmode;
@@ -635,7 +634,7 @@ LockHasWaiters(const LOCKTAG *locktag, LOCKMODE lockmode, bool sessionLock)
{
LOCKMETHODID lockmethodid = locktag->locktag_lockmethodid;
LockMethod lockMethodTable;
- LOCALLOCKTAG localtag;
+ LOCALLOCKTAG localtag = {0};
LOCALLOCK *locallock;
LOCK *lock;
PROCLOCK *proclock;
@@ -658,7 +657,6 @@ LockHasWaiters(const LOCKTAG *locktag, LOCKMODE lockmode, bool sessionLock)
/*
* Find the LOCALLOCK entry for this lock and lockmode
*/
- MemSet(&localtag, 0, sizeof(localtag)); /* must clear padding */
localtag.lock = *locktag;
localtag.mode = lockmode;
@@ -777,7 +775,7 @@ LockAcquireExtended(const LOCKTAG *locktag,
{
LOCKMETHODID lockmethodid = locktag->locktag_lockmethodid;
LockMethod lockMethodTable;
- LOCALLOCKTAG localtag;
+ LOCALLOCKTAG localtag = {0};
LOCALLOCK *locallock;
LOCK *lock;
PROCLOCK *proclock;
@@ -820,7 +818,6 @@ LockAcquireExtended(const LOCKTAG *locktag,
/*
* Find or create a LOCALLOCK entry for this lock and lockmode
*/
- MemSet(&localtag, 0, sizeof(localtag)); /* must clear padding */
localtag.lock = *locktag;
localtag.mode = lockmode;
@@ -1976,7 +1973,7 @@ LockRelease(const LOCKTAG *locktag, LOCKMODE lockmode, bool sessionLock)
{
LOCKMETHODID lockmethodid = locktag->locktag_lockmethodid;
LockMethod lockMethodTable;
- LOCALLOCKTAG localtag;
+ LOCALLOCKTAG localtag = {0};
LOCALLOCK *locallock;
LOCK *lock;
PROCLOCK *proclock;
@@ -1999,7 +1996,6 @@ LockRelease(const LOCKTAG *locktag, LOCKMODE lockmode, bool sessionLock)
/*
* Find the LOCALLOCK entry for this lock and lockmode
*/
- MemSet(&localtag, 0, sizeof(localtag)); /* must clear padding */
localtag.lock = *locktag;
localtag.mode = lockmode;
diff --git a/src/backend/storage/lmgr/lwlock.c b/src/backend/storage/lmgr/lwlock.c
index 38317edaf9..ce5e5c073f 100644
--- a/src/backend/storage/lmgr/lwlock.c
+++ b/src/backend/storage/lmgr/lwlock.c
@@ -384,7 +384,7 @@ print_lwlock_stats(int code, Datum arg)
static lwlock_stats *
get_lwlock_stats_entry(LWLock *lock)
{
- lwlock_stats_key key;
+ lwlock_stats_key key = {0};
lwlock_stats *lwstats;
bool found;
@@ -397,7 +397,6 @@ get_lwlock_stats_entry(LWLock *lock)
return &lwlock_stats_dummy;
/* Fetch or create the entry. */
- MemSet(&key, 0, sizeof(key));
key.tranche = lock->tranche;
key.instance = lock;
lwstats = hash_search(lwlock_stats_htab, &key, HASH_ENTER, &found);
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 43fff50d49..8976f4e9f7 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4930,7 +4930,7 @@ pg_timezone_abbrevs(PG_FUNCTION_ARGS)
int gmtoffset;
bool is_dst;
unsigned char *p;
- struct pg_itm_in itm_in;
+ struct pg_itm_in itm_in = {0};
Interval *resInterval;
/* stuff done only on the first call of the function */
@@ -5022,7 +5022,6 @@ pg_timezone_abbrevs(PG_FUNCTION_ARGS)
values[0] = CStringGetTextDatum(buffer);
/* Convert offset (in seconds) to an interval; can't overflow */
- MemSet(&itm_in, 0, sizeof(struct pg_itm_in));
itm_in.tm_usec = (int64) gmtoffset * USECS_PER_SEC;
resInterval = (Interval *) palloc(sizeof(Interval));
(void) itmin2interval(&itm_in, resInterval);
@@ -5055,7 +5054,7 @@ pg_timezone_names(PG_FUNCTION_ARGS)
fsec_t fsec;
const char *tzn;
Interval *resInterval;
- struct pg_itm_in itm_in;
+ struct pg_itm_in itm_in = {0};
SetSingleFuncCall(fcinfo, 0);
@@ -5090,7 +5089,6 @@ pg_timezone_names(PG_FUNCTION_ARGS)
values[1] = CStringGetTextDatum(tzn ? tzn : "");
/* Convert tzoff to an interval; can't overflow */
- MemSet(&itm_in, 0, sizeof(struct pg_itm_in));
itm_in.tm_usec = (int64) -tzoff * USECS_PER_SEC;
resInterval = (Interval *) palloc(sizeof(Interval));
(void) itmin2interval(&itm_in, resInterval);
diff --git a/src/backend/utils/adt/formatting.c b/src/backend/utils/adt/formatting.c
index 6f8734a947..b48fa2a96a 100644
--- a/src/backend/utils/adt/formatting.c
+++ b/src/backend/utils/adt/formatting.c
@@ -5613,13 +5613,11 @@ NUM_processor(FormatNode *node, NUMDesc *Num, char *inout,
int sign, bool is_to_char, Oid collid)
{
FormatNode *n;
- NUMProc _Np,
+ NUMProc _Np = {0},
*Np = &_Np;
const char *pattern;
int pattern_len;
- MemSet(Np, 0, sizeof(NUMProc));
-
Np->Num = Num;
Np->is_to_char = is_to_char;
Np->number = number;
diff --git a/src/backend/utils/adt/tsrank.c b/src/backend/utils/adt/tsrank.c
index 3858fc5928..7d78219b62 100644
--- a/src/backend/utils/adt/tsrank.c
+++ b/src/backend/utils/adt/tsrank.c
@@ -853,7 +853,7 @@ calc_rank_cd(const float4 *arrdata, TSVector txt, TSQuery query, int method)
int len,
i,
doclen = 0;
- CoverExt ext;
+ CoverExt ext = {0};
double Wdoc = 0.0;
double invws[lengthof(weights)];
double SumDist = 0.0,
@@ -883,7 +883,6 @@ calc_rank_cd(const float4 *arrdata, TSVector txt, TSQuery query, int method)
return 0.0;
}
- MemSet(&ext, 0, sizeof(CoverExt));
while (Cover(doc, doclen, &qr, &ext))
{
double Cpos = 0.0;
diff --git a/src/backend/utils/cache/relfilenumbermap.c b/src/backend/utils/cache/relfilenumbermap.c
index c4245d5ccd..71d415e04b 100644
--- a/src/backend/utils/cache/relfilenumbermap.c
+++ b/src/backend/utils/cache/relfilenumbermap.c
@@ -137,7 +137,7 @@ InitializeRelfilenumberMap(void)
Oid
RelidByRelfilenumber(Oid reltablespace, RelFileNumber relfilenumber)
{
- RelfilenumberMapKey key;
+ RelfilenumberMapKey key = {0};
RelfilenumberMapEntry *entry;
bool found;
SysScanDesc scandesc;
@@ -153,7 +153,6 @@ RelidByRelfilenumber(Oid reltablespace, RelFileNumber relfilenumber)
if (reltablespace == MyDatabaseTableSpace)
reltablespace = 0;
- MemSet(&key, 0, sizeof(key));
key.reltablespace = reltablespace;
key.relfilenumber = relfilenumber;
diff --git a/src/backend/utils/cache/ts_cache.c b/src/backend/utils/cache/ts_cache.c
index 24808dfbb1..70e88fd228 100644
--- a/src/backend/utils/cache/ts_cache.c
+++ b/src/backend/utils/cache/ts_cache.c
@@ -414,7 +414,7 @@ lookup_ts_config_cache(Oid cfgId)
ScanKeyData mapskey;
SysScanDesc mapscan;
HeapTuple maptup;
- ListDictionary maplists[MAXTOKENTYPE + 1];
+ ListDictionary maplists[MAXTOKENTYPE + 1] = {0};
Oid mapdicts[MAXDICTSPERTT];
int maxtokentype;
int ndicts;
@@ -468,7 +468,6 @@ lookup_ts_config_cache(Oid cfgId)
* see the entries in maptokentype order, and in mapseqno order for
* each token type, even though we didn't explicitly ask for that.
*/
- MemSet(maplists, 0, sizeof(maplists));
maxtokentype = 0;
ndicts = 0;
diff --git a/src/backend/utils/misc/ps_status.c b/src/backend/utils/misc/ps_status.c
index 8520ce76bb..264d0ab1df 100644
--- a/src/backend/utils/misc/ps_status.c
+++ b/src/backend/utils/misc/ps_status.c
@@ -376,7 +376,7 @@ set_ps_display(const char *activity)
#ifdef PS_USE_CLOBBER_ARGV
/* pad unused memory; need only clobber remainder of old status string */
if (last_status_len > ps_buffer_cur_len)
- MemSet(ps_buffer + ps_buffer_cur_len, PS_PADDING,
+ memset(ps_buffer + ps_buffer_cur_len, PS_PADDING,
last_status_len - ps_buffer_cur_len);
last_status_len = ps_buffer_cur_len;
#endif /* PS_USE_CLOBBER_ARGV */
diff --git a/src/backend/utils/misc/timeout.c b/src/backend/utils/misc/timeout.c
index 6f5e08bc30..284b9153ea 100644
--- a/src/backend/utils/misc/timeout.c
+++ b/src/backend/utils/misc/timeout.c
@@ -211,13 +211,11 @@ schedule_alarm(TimestampTz now)
{
if (num_active_timeouts > 0)
{
- struct itimerval timeval;
+ struct itimerval timeval = {0};
TimestampTz nearest_timeout;
long secs;
int usecs;
- MemSet(&timeval, 0, sizeof(struct itimerval));
-
/*
* If we think there's a signal pending, but current time is more than
* 10ms past when the signal was due, then assume that the timeout
diff --git a/src/interfaces/libpq/fe-connect.c b/src/interfaces/libpq/fe-connect.c
index dc49387d6c..0362500386 100644
--- a/src/interfaces/libpq/fe-connect.c
+++ b/src/interfaces/libpq/fe-connect.c
@@ -2325,7 +2325,7 @@ keep_going: /* We will come back to here until there is
if (conn->try_next_host)
{
pg_conn_host *ch;
- struct addrinfo hint;
+ struct addrinfo hint = {0};
int thisport;
int ret;
char portstr[MAXPGPATH];
@@ -2364,7 +2364,6 @@ keep_going: /* We will come back to here until there is
ch = &conn->connhost[conn->whichhost];
/* Initialize hint structure */
- MemSet(&hint, 0, sizeof(hint));
hint.ai_socktype = SOCK_STREAM;
conn->addrlist_family = hint.ai_family = AF_UNSPEC;
diff --git a/src/pl/plperl/plperl.c b/src/pl/plperl/plperl.c
index af354a68cc..1e6cb45ad4 100644
--- a/src/pl/plperl/plperl.c
+++ b/src/pl/plperl/plperl.c
@@ -1840,10 +1840,9 @@ plperl_call_handler(PG_FUNCTION_ARGS)
Datum retval = (Datum) 0;
plperl_call_data *volatile save_call_data = current_call_data;
plperl_interp_desc *volatile oldinterp = plperl_active_interp;
- plperl_call_data this_call_data;
+ plperl_call_data this_call_data = {0};
/* Initialize current-call status record */
- MemSet(&this_call_data, 0, sizeof(this_call_data));
this_call_data.fcinfo = fcinfo;
PG_TRY();
@@ -1881,16 +1880,13 @@ plperl_inline_handler(PG_FUNCTION_ARGS)
{
LOCAL_FCINFO(fake_fcinfo, 0);
InlineCodeBlock *codeblock = (InlineCodeBlock *) PG_GETARG_POINTER(0);
- FmgrInfo flinfo;
- plperl_proc_desc desc;
+ FmgrInfo flinfo = {0};
+ plperl_proc_desc desc = {0};
plperl_call_data *volatile save_call_data = current_call_data;
plperl_interp_desc *volatile oldinterp = plperl_active_interp;
- plperl_call_data this_call_data;
+ plperl_call_data this_call_data = {0};
ErrorContextCallback pl_error_context;
- /* Initialize current-call status record */
- MemSet(&this_call_data, 0, sizeof(this_call_data));
-
/* Set up a callback for error reporting */
pl_error_context.callback = plperl_inline_callback;
pl_error_context.previous = error_context_stack;
@@ -1903,8 +1899,6 @@ plperl_inline_handler(PG_FUNCTION_ARGS)
* with no arguments passed, and a result type of VOID.
*/
MemSet(fake_fcinfo, 0, SizeForFunctionCallInfo(0));
- MemSet(&flinfo, 0, sizeof(flinfo));
- MemSet(&desc, 0, sizeof(desc));
fake_fcinfo->flinfo = &flinfo;
flinfo.fn_oid = InvalidOid;
flinfo.fn_mcxt = CurrentMemoryContext;
diff --git a/src/pl/plpgsql/src/pl_handler.c b/src/pl/plpgsql/src/pl_handler.c
index 190d286f1c..1f8c9edfa8 100644
--- a/src/pl/plpgsql/src/pl_handler.c
+++ b/src/pl/plpgsql/src/pl_handler.c
@@ -317,7 +317,7 @@ plpgsql_inline_handler(PG_FUNCTION_ARGS)
LOCAL_FCINFO(fake_fcinfo, 0);
InlineCodeBlock *codeblock = castNode(InlineCodeBlock, DatumGetPointer(PG_GETARG_DATUM(0)));
PLpgSQL_function *func;
- FmgrInfo flinfo;
+ FmgrInfo flinfo = {0};
EState *simple_eval_estate;
ResourceOwner simple_eval_resowner;
Datum retval;
@@ -341,7 +341,6 @@ plpgsql_inline_handler(PG_FUNCTION_ARGS)
* with no arguments passed.
*/
MemSet(fake_fcinfo, 0, SizeForFunctionCallInfo(0));
- MemSet(&flinfo, 0, sizeof(flinfo));
fake_fcinfo->flinfo = &flinfo;
flinfo.fn_oid = InvalidOid;
flinfo.fn_mcxt = CurrentMemoryContext;
@@ -502,10 +501,10 @@ plpgsql_validator(PG_FUNCTION_ARGS)
if (check_function_bodies)
{
LOCAL_FCINFO(fake_fcinfo, 0);
- FmgrInfo flinfo;
+ FmgrInfo flinfo = {0};
int rc;
- TriggerData trigdata;
- EventTriggerData etrigdata;
+ TriggerData trigdata = {0};
+ EventTriggerData etrigdata = {0};
/*
* Connect to SPI manager (is this needed for compilation?)
@@ -518,19 +517,16 @@ plpgsql_validator(PG_FUNCTION_ARGS)
* plpgsql_compile().
*/
MemSet(fake_fcinfo, 0, SizeForFunctionCallInfo(0));
- MemSet(&flinfo, 0, sizeof(flinfo));
fake_fcinfo->flinfo = &flinfo;
flinfo.fn_oid = funcoid;
flinfo.fn_mcxt = CurrentMemoryContext;
if (is_dml_trigger)
{
- MemSet(&trigdata, 0, sizeof(trigdata));
trigdata.type = T_TriggerData;
fake_fcinfo->context = (Node *) &trigdata;
}
else if (is_event_trigger)
{
- MemSet(&etrigdata, 0, sizeof(etrigdata));
etrigdata.type = T_EventTriggerData;
fake_fcinfo->context = (Node *) &etrigdata;
}
diff --git a/src/pl/plpython/plpy_main.c b/src/pl/plpython/plpy_main.c
index a4d66f3057..40d66da28a 100644
--- a/src/pl/plpython/plpy_main.c
+++ b/src/pl/plpython/plpy_main.c
@@ -264,8 +264,8 @@ plpython3_inline_handler(PG_FUNCTION_ARGS)
{
LOCAL_FCINFO(fake_fcinfo, 0);
InlineCodeBlock *codeblock = (InlineCodeBlock *) DatumGetPointer(PG_GETARG_DATUM(0));
- FmgrInfo flinfo;
- PLyProcedure proc;
+ FmgrInfo flinfo = {0};
+ PLyProcedure proc = {0};
PLyExecutionContext *exec_ctx;
ErrorContextCallback plerrcontext;
@@ -276,12 +276,10 @@ plpython3_inline_handler(PG_FUNCTION_ARGS)
elog(ERROR, "SPI_connect failed");
MemSet(fcinfo, 0, SizeForFunctionCallInfo(0));
- MemSet(&flinfo, 0, sizeof(flinfo));
fake_fcinfo->flinfo = &flinfo;
flinfo.fn_oid = InvalidOid;
flinfo.fn_mcxt = CurrentMemoryContext;
- MemSet(&proc, 0, sizeof(PLyProcedure));
proc.mcxt = AllocSetContextCreate(TopMemoryContext,
"__plpython_inline_block",
ALLOCSET_DEFAULT_SIZES);
On Tue, Aug 2, 2022 at 3:09 AM Ranier Vilela <ranier.vf@gmail.com> wrote:
Em sáb., 16 de jul. de 2022 às 16:54, Ranier Vilela <ranier.vf@gmail.com> escreveu:
Em sáb, 16 de jul de 2022 2:58 AM, Peter Eisentraut <peter.eisentraut@enterprisedb.com> escreveu:
On 11.07.22 21:06, Ranier Vilela wrote:
Em qui., 7 de jul. de 2022 às 14:01, Ranier Vilela <ranier.vf@gmail.com
<mailto:ranier.vf@gmail.com>> escreveu:Attached the v1 of your patch.
I think that all is safe to switch MemSet by {0}.Here the rebased patch v2, against latest head.
I have committed my patch with Álvaro's comments addressed
I see.
It's annoing that old compiler (gcc 4.7.2) don't handle this style.Your patch appears to add in changes that are either arguably out of
scope or would need further review (e.g., changing memset() calls,
changing the scope of some variables, changing places that need to worry
about padding bits). Please submit separate patches for those, and we
can continue the analysis.Sure.
Hi, sorry for the delay.
Like how https://github.com/postgres/postgres/commit/9fd45870c1436b477264c0c82eb195df52bc0919
New attempt to remove more MemSet calls, that are safe.Attached v3 patch.
regards,
Ranier Vilela
Hi, I have not been closely following this thread, but it's starting
to sound very deja-vu with something I proposed 3 years ago. See [1]/messages/by-id/2793d0d2-c65f-5db0-4f89-251188438391@gmail.com
"Make use of C99 designated initialisers for nulls/values arrays".
That started off with lots of support, but then there was a suggestion
that the {0} should be implemented as a macro, and the subsequent
discussions about that macro eventually bikeshedded the patch to
death.
It might be a good idea if you check that old thread so you can avoid
the same pitfalls. I hope you have more luck than I did ;-)
------
[1]: /messages/by-id/2793d0d2-c65f-5db0-4f89-251188438391@gmail.com
Kind Regards,
Peter Smith.
Fujitsu Australia
Em seg., 1 de ago. de 2022 às 22:19, Peter Smith <smithpb2250@gmail.com>
escreveu:
On Tue, Aug 2, 2022 at 3:09 AM Ranier Vilela <ranier.vf@gmail.com> wrote:
Em sáb., 16 de jul. de 2022 às 16:54, Ranier Vilela <ranier.vf@gmail.com>
escreveu:
Em sáb, 16 de jul de 2022 2:58 AM, Peter Eisentraut <
peter.eisentraut@enterprisedb.com> escreveu:
On 11.07.22 21:06, Ranier Vilela wrote:
Em qui., 7 de jul. de 2022 às 14:01, Ranier Vilela <
ranier.vf@gmail.com
<mailto:ranier.vf@gmail.com>> escreveu:
Attached the v1 of your patch.
I think that all is safe to switch MemSet by {0}.Here the rebased patch v2, against latest head.
I have committed my patch with Álvaro's comments addressed
I see.
It's annoing that old compiler (gcc 4.7.2) don't handle this style.Your patch appears to add in changes that are either arguably out of
scope or would need further review (e.g., changing memset() calls,
changing the scope of some variables, changing places that need toworry
about padding bits). Please submit separate patches for those, and we
can continue the analysis.Sure.
Hi, sorry for the delay.
Like howhttps://github.com/postgres/postgres/commit/9fd45870c1436b477264c0c82eb195df52bc0919
New attempt to remove more MemSet calls, that are safe.
Attached v3 patch.
regards,
Ranier VilelaHi, I have not been closely following this thread, but it's starting
to sound very deja-vu with something I proposed 3 years ago. See [1]
"Make use of C99 designated initialisers for nulls/values arrays".
That started off with lots of support, but then there was a suggestion
that the {0} should be implemented as a macro, and the subsequent
discussions about that macro eventually bikeshedded the patch to
death.It might be a good idea if you check that old thread so you can avoid
the same pitfalls. I hope you have more luck than I did ;-)
I see, thanks.
We are using only {0}, just to avoid these pitfalls.
All changes here are safe, because, the tradeoff is
MemSet with 0 to {0}
Any else is ignored.
The rest of the calls with MemSet are alignment and padding dependent, and
for now, will not be played.
regards,
Ranier Vilela
Hi Ranier,
I'm pretty late to thread but would like to know about your claim in the
thread:
`All compilers currently have memset optimized.` I know one case of
optimization where variable is not used after the memset.
Are the cases for which the optimization is done consistent across all the
compilers?
Thanks,
Mahendrakar.
On Tue, 2 Aug 2022 at 17:26, Ranier Vilela <ranier.vf@gmail.com> wrote:
Show quoted text
Em seg., 1 de ago. de 2022 às 22:19, Peter Smith <smithpb2250@gmail.com>
escreveu:On Tue, Aug 2, 2022 at 3:09 AM Ranier Vilela <ranier.vf@gmail.com> wrote:
Em sáb., 16 de jul. de 2022 às 16:54, Ranier Vilela <
ranier.vf@gmail.com> escreveu:
Em sáb, 16 de jul de 2022 2:58 AM, Peter Eisentraut <
peter.eisentraut@enterprisedb.com> escreveu:
On 11.07.22 21:06, Ranier Vilela wrote:
Em qui., 7 de jul. de 2022 às 14:01, Ranier Vilela <
ranier.vf@gmail.com
<mailto:ranier.vf@gmail.com>> escreveu:
Attached the v1 of your patch.
I think that all is safe to switch MemSet by {0}.Here the rebased patch v2, against latest head.
I have committed my patch with Álvaro's comments addressed
I see.
It's annoing that old compiler (gcc 4.7.2) don't handle this style.Your patch appears to add in changes that are either arguably out of
scope or would need further review (e.g., changing memset() calls,
changing the scope of some variables, changing places that need toworry
about padding bits). Please submit separate patches for those, and we
can continue the analysis.Sure.
Hi, sorry for the delay.
Like howhttps://github.com/postgres/postgres/commit/9fd45870c1436b477264c0c82eb195df52bc0919
New attempt to remove more MemSet calls, that are safe.
Attached v3 patch.
regards,
Ranier VilelaHi, I have not been closely following this thread, but it's starting
to sound very deja-vu with something I proposed 3 years ago. See [1]
"Make use of C99 designated initialisers for nulls/values arrays".
That started off with lots of support, but then there was a suggestion
that the {0} should be implemented as a macro, and the subsequent
discussions about that macro eventually bikeshedded the patch to
death.It might be a good idea if you check that old thread so you can avoid
the same pitfalls. I hope you have more luck than I did ;-)I see, thanks.
We are using only {0}, just to avoid these pitfalls.
All changes here are safe, because, the tradeoff isMemSet with 0 to {0}
Any else is ignored.
The rest of the calls with MemSet are alignment and padding dependent, and
for now, will not be played.regards,
Ranier Vilela
Em ter., 2 de ago. de 2022 às 10:17, mahendrakar s <
mahendrakarforpg@gmail.com> escreveu:
Hi Ranier,
I'm pretty late to thread but would like to know about your claim in the
thread:
`All compilers currently have memset optimized.`
What did I mean, modern compilers.
I know one case of optimization where variable is not used after the memset.
Probably, the compiler decided to remove the variable altogether.
The most common is to remove the padding, when he understands that this is
possible and safe.
This does not mean that this will happen in all cases.
The point here is, this is only possible when using memset.
Are the cases for which the optimization is done consistent across all the
compilers?
Of course not. But it does not matter.
regards,
Ranier Vilela
On 01.08.22 19:08, Ranier Vilela wrote:
Like how
https://github.com/postgres/postgres/commit/9fd45870c1436b477264c0c82eb195df52bc0919
<https://github.com/postgres/postgres/commit/9fd45870c1436b477264c0c82eb195df52bc0919>
New attempt to remove more MemSet calls, that are safe.Attached v3 patch.
Note that struct initialization does not set padding bits. So any
struct that is used as a hash key or that goes to disk or something
similar needs to be set with memset/MemSet instead. Various places in
the code make explicit comments about that, which your patch deletes,
which is a mistake. This patch needs to be adjusted carefully with this
in mind before it can be considered.
Em qui., 11 de ago. de 2022 às 07:38, Peter Eisentraut <
peter.eisentraut@enterprisedb.com> escreveu:
On 01.08.22 19:08, Ranier Vilela wrote:
Like how
https://github.com/postgres/postgres/commit/9fd45870c1436b477264c0c82eb195df52bc0919
<
https://github.com/postgres/postgres/commit/9fd45870c1436b477264c0c82eb195df52bc0919
New attempt to remove more MemSet calls, that are safe.
Attached v3 patch.
Note that struct initialization does not set padding bits.
According to:
https://interrupt.memfault.com/blog/c-struct-padding-initialization
2. individually set all members to 0:
struct foo a = {
.i = 0,
.b = 0,};
Suffer from this problem.
3. use { 0 } zero-initializer, not.
So any
struct that is used as a hash key or that goes to disk or something
similar needs to be set with memset/MemSet instead. Various places in
the code make explicit comments about that, which your patch deletes,
which is a mistake. This patch needs to be adjusted carefully with this
in mind before it can be considered.
I think this needs better comprovation?
regards,
Ranier Vilela
On 2022-Aug-11, Ranier Vilela wrote:
According to:
https://interrupt.memfault.com/blog/c-struct-padding-initialization
Did you actually read it?
https://interrupt.memfault.com/blog/c-struct-padding-initialization#structure-zero-initialization
: This looks great! However, it’s not obvious (from looking at those snippets)
: what the value loaded into the padding region will be.
:
: The unfortunate answer is: it depends
:
: The C11 standard, chapter §6.2.6.1/6 says this:
:
: : When a value is stored in an object of structure or union type, including in a
: : member object, the bytes of the object representation that correspond to any
: : padding bytes take unspecified values.
--
Álvaro Herrera 48°01'N 7°57'E — https://www.EnterpriseDB.com/
"La rebeldía es la virtud original del hombre" (Arthur Schopenhauer)
Em qui., 11 de ago. de 2022 às 08:48, Alvaro Herrera <
alvherre@alvh.no-ip.org> escreveu:
On 2022-Aug-11, Ranier Vilela wrote:
According to:
https://interrupt.memfault.com/blog/c-struct-padding-initializationDid you actually read it?
Yes, today.
https://interrupt.memfault.com/blog/c-struct-padding-initialization#structure-zero-initialization
: This looks great! However, it’s not obvious (from looking at those
snippets)
: what the value loaded into the padding region will be.
:
: The unfortunate answer is: it depends
:
: The C11 standard, chapter §6.2.6.1/6 says this:
:
: : When a value is stored in an object of structure or union type,
including in a
: : member object, the bytes of the object representation that correspond
to any
: : padding bytes take unspecified values.
Did you see the Strategy 3 table, { 0 } ?
regards,
Ranier Vilela
On Thu, Aug 11, 2022 at 08:51:53AM -0300, Ranier Vilela wrote:
Em qui., 11 de ago. de 2022 �s 08:48, Alvaro Herrera <
alvherre@alvh.no-ip.org> escreveu:On 2022-Aug-11, Ranier Vilela wrote:
According to:
https://interrupt.memfault.com/blog/c-struct-padding-initializationDid you see the Strategy 3 table, { 0 } ?
It explicitly shows that at least Ubuntu clang version 13.0.0-2 with -01
doesn't do anything about the padding bytes (and that's after testing only 2
different compilers). Even if those compilers didn't show any problem, we
still couldn't rely on an undefined behavior and assume that no other compilers
behave differently.
Em qui., 11 de ago. de 2022 às 09:23, Julien Rouhaud <rjuju123@gmail.com>
escreveu:
On Thu, Aug 11, 2022 at 08:51:53AM -0300, Ranier Vilela wrote:
Em qui., 11 de ago. de 2022 às 08:48, Alvaro Herrera <
alvherre@alvh.no-ip.org> escreveu:On 2022-Aug-11, Ranier Vilela wrote:
According to:
https://interrupt.memfault.com/blog/c-struct-padding-initializationDid you see the Strategy 3 table, { 0 } ?
It explicitly shows that at least Ubuntu clang version 13.0.0-2 with -01
doesn't do anything about the padding bytes (and that's after testing only
2
different compilers). Even if those compilers didn't show any problem, we
still couldn't rely on an undefined behavior and assume that no other
compilers
behave differently.
Yeah, although not a problem in the main current compilers clang, gcc and
msvc,
it seems that this cannot be changed.
Being an undefined behavior, filling structures with holes, it seems to me
that you should always use MemSet or memset.
Since even a current structure without holes could be changed in the future
and become a bug.
regards,
Ranier Vilela
Hi Ranier,
Following the comment in commit 9fd45870c1436b477264c0c82eb195df52bc0919,
(The same could be done with appropriate memset() calls, but this
patch is part of an effort to phase out MemSet(), so it doesn't touch
memset() calls.)
Should these obviously possible replacement of the standard library
function "memset" be considered as well? For example, something like the
attached one which is focusing on the pageinspect extension only.
Best regards,
David
Show quoted text
On 2022-08-01 10:08 a.m., Ranier Vilela wrote:
Em sáb., 16 de jul. de 2022 às 16:54, Ranier Vilela
<ranier.vf@gmail.com> escreveu:Em sáb, 16 de jul de 2022 2:58 AM, Peter Eisentraut
<peter.eisentraut@enterprisedb.com> escreveu:On 11.07.22 21:06, Ranier Vilela wrote:
Em qui., 7 de jul. de 2022 às 14:01, Ranier Vilela
<ranier.vf@gmail.com
<mailto:ranier.vf@gmail.com>> escreveu:
Attached the v1 of your patch.
I think that all is safe to switch MemSet by {0}.Here the rebased patch v2, against latest head.
I have committed my patch with Álvaro's comments addressed
I see.
It's annoing that old compiler (gcc 4.7.2) don't handle this style.Your patch appears to add in changes that are either arguably
out of
scope or would need further review (e.g., changing memset()
calls,
changing the scope of some variables, changing places that
need to worry
about padding bits). Please submit separate patches for
those, and we
can continue the analysis.Sure.
Hi, sorry for the delay.
Like how
https://github.com/postgres/postgres/commit/9fd45870c1436b477264c0c82eb195df52bc0919
New attempt to remove more MemSet calls, that are safe.Attached v3 patch.
regards,
Ranier Vilela
Attachments:
0001-Replace-many-memset-calls-with-struct-initialization.patchtext/plain; charset=UTF-8; name=0001-Replace-many-memset-calls-with-struct-initialization.patchDownload
From 25bd8af7acfd6bf2e23cdfac93828d810cfbb5b4 Mon Sep 17 00:00:00 2001
From: David Zhang <david.zhang@highgo.ca>
Date: Fri, 19 Aug 2022 14:43:01 -0700
Subject: [PATCH] Replace many memset calls with struct initialization
This replaces all memset() calls with struct initialization where that
is easily and obviously possible.
---
contrib/pageinspect/btreefuncs.c | 3 +--
contrib/pageinspect/ginfuncs.c | 12 +++---------
contrib/pageinspect/gistfuncs.c | 12 +++---------
contrib/pageinspect/heapfuncs.c | 4 +---
contrib/pageinspect/rawpage.c | 4 +---
5 files changed, 9 insertions(+), 26 deletions(-)
diff --git a/contrib/pageinspect/btreefuncs.c b/contrib/pageinspect/btreefuncs.c
index 9375d55e14..a14d83f8cb 100644
--- a/contrib/pageinspect/btreefuncs.c
+++ b/contrib/pageinspect/btreefuncs.c
@@ -311,7 +311,7 @@ bt_page_print_tuples(struct user_args *uargs)
bool rightmost = uargs->rightmost;
bool ispivottuple;
Datum values[9];
- bool nulls[9];
+ bool nulls[9] = {0};
HeapTuple tuple;
ItemId id;
IndexTuple itup;
@@ -331,7 +331,6 @@ bt_page_print_tuples(struct user_args *uargs)
itup = (IndexTuple) PageGetItem(page, id);
j = 0;
- memset(nulls, 0, sizeof(nulls));
values[j++] = DatumGetInt16(offset);
values[j++] = ItemPointerGetDatum(&itup->t_tid);
values[j++] = Int32GetDatum((int) IndexTupleSize(itup));
diff --git a/contrib/pageinspect/ginfuncs.c b/contrib/pageinspect/ginfuncs.c
index 952e9d51a8..6c0183cc63 100644
--- a/contrib/pageinspect/ginfuncs.c
+++ b/contrib/pageinspect/ginfuncs.c
@@ -40,7 +40,7 @@ gin_metapage_info(PG_FUNCTION_ARGS)
GinMetaPageData *metadata;
HeapTuple resultTuple;
Datum values[10];
- bool nulls[10];
+ bool nulls[10] = {0};
if (!superuser())
ereport(ERROR,
@@ -75,8 +75,6 @@ gin_metapage_info(PG_FUNCTION_ARGS)
metadata = GinPageGetMeta(page);
- memset(nulls, 0, sizeof(nulls));
-
values[0] = Int64GetDatum(metadata->head);
values[1] = Int64GetDatum(metadata->tail);
values[2] = Int32GetDatum(metadata->tailFreeSize);
@@ -107,7 +105,7 @@ gin_page_opaque_info(PG_FUNCTION_ARGS)
GinPageOpaque opaq;
HeapTuple resultTuple;
Datum values[3];
- bool nulls[3];
+ bool nulls[3] = {0};
Datum flags[16];
int nflags = 0;
uint16 flagbits;
@@ -162,8 +160,6 @@ gin_page_opaque_info(PG_FUNCTION_ARGS)
flags[nflags++] = DirectFunctionCall1(to_hex32, Int32GetDatum(flagbits));
}
- memset(nulls, 0, sizeof(nulls));
-
values[0] = Int64GetDatum(opaq->rightlink);
values[1] = Int32GetDatum(opaq->maxoff);
values[2] = PointerGetDatum(construct_array_builtin(flags, nflags, TEXTOID));
@@ -255,14 +251,12 @@ gin_leafpage_items(PG_FUNCTION_ARGS)
HeapTuple resultTuple;
Datum result;
Datum values[3];
- bool nulls[3];
+ bool nulls[3] = {0};
int ndecoded,
i;
ItemPointer tids;
Datum *tids_datum;
- memset(nulls, 0, sizeof(nulls));
-
values[0] = ItemPointerGetDatum(&cur->first);
values[1] = UInt16GetDatum(cur->nbytes);
diff --git a/contrib/pageinspect/gistfuncs.c b/contrib/pageinspect/gistfuncs.c
index d0a34a3375..1e8cc88b65 100644
--- a/contrib/pageinspect/gistfuncs.c
+++ b/contrib/pageinspect/gistfuncs.c
@@ -43,7 +43,7 @@ gist_page_opaque_info(PG_FUNCTION_ARGS)
GISTPageOpaque opaq;
HeapTuple resultTuple;
Datum values[4];
- bool nulls[4];
+ bool nulls[4] = {0};
Datum flags[16];
int nflags = 0;
uint16 flagbits;
@@ -99,8 +99,6 @@ gist_page_opaque_info(PG_FUNCTION_ARGS)
flags[nflags++] = DirectFunctionCall1(to_hex32, Int32GetDatum(flagbits));
}
- memset(nulls, 0, sizeof(nulls));
-
values[0] = LSNGetDatum(PageGetLSN(page));
values[1] = LSNGetDatum(GistPageGetNSN(page));
values[2] = Int64GetDatum(opaq->rightlink);
@@ -163,7 +161,7 @@ gist_page_items_bytea(PG_FUNCTION_ARGS)
offset++)
{
Datum values[5];
- bool nulls[5];
+ bool nulls[5] = {0};
ItemId id;
IndexTuple itup;
bytea *tuple_bytea;
@@ -177,8 +175,6 @@ gist_page_items_bytea(PG_FUNCTION_ARGS)
itup = (IndexTuple) PageGetItem(page, id);
tuple_len = IndexTupleSize(itup);
- memset(nulls, 0, sizeof(nulls));
-
values[0] = DatumGetInt16(offset);
values[1] = ItemPointerGetDatum(&itup->t_tid);
values[2] = Int32GetDatum((int) IndexTupleSize(itup));
@@ -241,7 +237,7 @@ gist_page_items(PG_FUNCTION_ARGS)
offset++)
{
Datum values[5];
- bool nulls[5];
+ bool nulls[5] = {0};
ItemId id;
IndexTuple itup;
Datum itup_values[INDEX_MAX_KEYS];
@@ -258,8 +254,6 @@ gist_page_items(PG_FUNCTION_ARGS)
index_deform_tuple(itup, RelationGetDescr(indexRel),
itup_values, itup_isnull);
- memset(nulls, 0, sizeof(nulls));
-
values[0] = DatumGetInt16(offset);
values[1] = ItemPointerGetDatum(&itup->t_tid);
values[2] = Int32GetDatum((int) IndexTupleSize(itup));
diff --git a/contrib/pageinspect/heapfuncs.c b/contrib/pageinspect/heapfuncs.c
index 2ff70405cf..952f5ed57e 100644
--- a/contrib/pageinspect/heapfuncs.c
+++ b/contrib/pageinspect/heapfuncs.c
@@ -181,13 +181,11 @@ heap_page_items(PG_FUNCTION_ARGS)
Datum result;
ItemId id;
Datum values[14];
- bool nulls[14];
+ bool nulls[14] = {0};
uint16 lp_offset;
uint16 lp_flags;
uint16 lp_len;
- memset(nulls, 0, sizeof(nulls));
-
/* Extract information from the line pointer */
id = PageGetItemId(page, inter_call_data->offset);
diff --git a/contrib/pageinspect/rawpage.c b/contrib/pageinspect/rawpage.c
index 90942be71e..0d1292d8f1 100644
--- a/contrib/pageinspect/rawpage.c
+++ b/contrib/pageinspect/rawpage.c
@@ -252,7 +252,7 @@ page_header(PG_FUNCTION_ARGS)
Datum result;
HeapTuple tuple;
Datum values[9];
- bool nulls[9];
+ bool nulls[9] = {0};
Page page;
PageHeader pageheader;
@@ -318,8 +318,6 @@ page_header(PG_FUNCTION_ARGS)
/* Build and return the tuple. */
- memset(nulls, 0, sizeof(nulls));
-
tuple = heap_form_tuple(tupdesc, values, nulls);
result = HeapTupleGetDatum(tuple);
--
2.17.1
Em sex., 19 de ago. de 2022 às 19:27, David Zhang <david.zhang@highgo.ca>
escreveu:
Hi Ranier,
Hi David,
Following the comment in commit 9fd45870c1436b477264c0c82eb195df52bc0919,
(The same could be done with appropriate memset() calls, but this
patch is part of an effort to phase out MemSet(), so it doesn't touch
memset() calls.)Should these obviously possible replacement of the standard library
function "memset" be considered as well?
Yes, sure.
In modern C compilers like clang above 13, gcc and msvc the initialization
with {0},
has no problem, because all bits are correctly initialized to zero.
However with some old compilers, such behavior is not strictly followed, so
with structs it is not safe to use.
But especially for arrays, whose use doesn't depend on filling the holes,
it's certainly safe and cheap to use,
which is the case here.
For example, something like the attached one which is focusing on the
pageinspect extension only.
Surely you did, but it has to be said, it was compiled and tested with at
least a make check.
Looks like it's ok, LTGM.
regards,
Ranier Vilela
Show quoted text
On 2022-Aug-19, David Zhang wrote:
Should these obviously possible replacement of the standard library function
"memset" be considered as well? For example, something like the attached one
which is focusing on the pageinspect extension only.
If you do this, you're creating a potential backpatching hazard. This
is OK if we get something in return, so a question to ask is whether
there is any benefit in doing it.
--
Álvaro Herrera PostgreSQL Developer — https://www.EnterpriseDB.com/
"Most hackers will be perfectly comfortable conceptualizing users as entropy
sources, so let's move on." (Nathaniel Smith)
On 24.08.22 16:30, Alvaro Herrera wrote:
On 2022-Aug-19, David Zhang wrote:
Should these obviously possible replacement of the standard library function
"memset" be considered as well? For example, something like the attached one
which is focusing on the pageinspect extension only.If you do this, you're creating a potential backpatching hazard. This
is OK if we get something in return, so a question to ask is whether
there is any benefit in doing it.
I don't follow how this is a backpatching hazard.
Peter Eisentraut <peter.eisentraut@enterprisedb.com> writes:
On 24.08.22 16:30, Alvaro Herrera wrote:
If you do this, you're creating a potential backpatching hazard. This
is OK if we get something in return, so a question to ask is whether
there is any benefit in doing it.
I don't follow how this is a backpatching hazard.
Call me a trogdolyte, but I don't follow how it's an improvement.
It looks to me like an entirely random change that doesn't get rid
of assumptions about what the bits are, it just replaces one set of
assumptions with a different set. Moreover, the new set of assumptions
may include "there are no padding bits in here", which is mighty fragile
and hard to verify. So I frankly do not find this a stylistic improvement.
regards, tom lane
On Wed, Aug 24, 2022 at 3:00 PM Tom Lane <tgl@sss.pgh.pa.us> wrote:
Call me a trogdolyte, but I don't follow how it's an improvement.
It looks to me like an entirely random change that doesn't get rid
of assumptions about what the bits are, it just replaces one set of
assumptions with a different set. Moreover, the new set of assumptions
may include "there are no padding bits in here", which is mighty fragile
and hard to verify. So I frankly do not find this a stylistic improvement.
Ditto.
--
Robert Haas
EDB: http://www.enterprisedb.com
Em qua., 24 de ago. de 2022 às 16:00, Tom Lane <tgl@sss.pgh.pa.us> escreveu:
Peter Eisentraut <peter.eisentraut@enterprisedb.com> writes:
On 24.08.22 16:30, Alvaro Herrera wrote:
If you do this, you're creating a potential backpatching hazard. This
is OK if we get something in return, so a question to ask is whether
there is any benefit in doing it.I don't follow how this is a backpatching hazard.
Call me a trogdolyte, but I don't follow how it's an improvement.
It looks to me like an entirely random change that doesn't get rid
of assumptions about what the bits are, it just replaces one set of
assumptions with a different set. Moreover, the new set of assumptions
may include "there are no padding bits in here", which is mighty fragile
and hard to verify. So I frankly do not find this a stylistic improvement.
But, these same arguments apply to Designated Initializers [1]https://interrupt.memfault.com/blog/c-struct-padding-initialization.
like:
struct foo a = {
.i = 0,
.b = 0,
};
That is slowly being introduced and IMHO brings the same problems with
padding bits.
regards,
Ranier Vilela
[1]: https://interrupt.memfault.com/blog/c-struct-padding-initialization
On Wed, Aug 24, 2022 at 3:20 PM Ranier Vilela <ranier.vf@gmail.com> wrote:
But, these same arguments apply to Designated Initializers [1].
like:
struct foo a = {
.i = 0,
.b = 0,
};That is slowly being introduced and IMHO brings the same problems with padding bits.
Yep. I don't find that an improvement over a MemSet on the struct
either, if we're just using it to fill in zeroes.
If we're using it to fill in non-zero values, though, then there's a
reasonable argument that it offers some notational convenience.
--
Robert Haas
EDB: http://www.enterprisedb.com
Em qua., 24 de ago. de 2022 às 16:41, Robert Haas <robertmhaas@gmail.com>
escreveu:
On Wed, Aug 24, 2022 at 3:20 PM Ranier Vilela <ranier.vf@gmail.com> wrote:
But, these same arguments apply to Designated Initializers [1].
like:
struct foo a = {
.i = 0,
.b = 0,
};That is slowly being introduced and IMHO brings the same problems with
padding bits.
Yep. I don't find that an improvement over a MemSet on the struct
either, if we're just using it to fill in zeroes.If we're using it to fill in non-zero values, though, then there's a
reasonable argument that it offers some notational convenience.
Even in that case, it still hides bugs.
All arguments against {0} apply entirely to this initialization type.
Because the padding bits remain uninitialized.
Note that where all major compilers are correctly initializing padding bits
with {0}, then this misbehavior will become of no practical effect in the
future.
regards,
Ranier Vilela
On 2022-Aug-24, Peter Eisentraut wrote:
I don't follow how this is a backpatching hazard.
It changes code. Any bugfix in the surrounding code would have to fix a
conflict. That is nonzero effort. Is it a huge risk? No, it is very
small risk and a very small cost to fix such a conflict; but my claim is
that this change has zero benefit, therefore we should not incur a
nonzero future effort.
--
Álvaro Herrera PostgreSQL Developer — https://www.EnterpriseDB.com/
"How amazing is that? I call it a night and come back to find that a bug has
been identified and patched while I sleep." (Robert Davidson)
http://archives.postgresql.org/pgsql-sql/2006-03/msg00378.php
On Thu, Aug 25, 2022 at 10:38:41AM +0200, Alvaro Herrera wrote:
It changes code. Any bugfix in the surrounding code would have to fix a
conflict. That is nonzero effort. Is it a huge risk? No, it is very
small risk and a very small cost to fix such a conflict; but my claim is
that this change has zero benefit, therefore we should not incur a
nonzero future effort.
Agreed to leave things as they are. This really comes down to if we
want to make this code more C99-ish or not, and the post-patch result
is logically the same as the pre-patch result.
--
Michael