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);