diff options
author | Peter Eisentraut <peter@eisentraut.org> | 2022-07-16 08:42:15 +0200 |
---|---|---|
committer | Peter Eisentraut <peter@eisentraut.org> | 2022-07-16 08:50:49 +0200 |
commit | 9fd45870c1436b477264c0c82eb195df52bc0919 (patch) | |
tree | 10a09724c0bcffa8f58f262e50c3260cde484446 /src/backend/commands/tablecmds.c | |
parent | c94ae9d827a360d74da6a304692d34a4dc8b6445 (diff) | |
download | postgresql-9fd45870c1436b477264c0c82eb195df52bc0919.tar.gz postgresql-9fd45870c1436b477264c0c82eb195df52bc0919.zip |
Replace many MemSet calls with struct initialization
This replaces all MemSet() calls with struct initialization where that
is easily and obviously possible. (For example, some cases have to
worry about padding bits, so I left those.)
(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.)
Reviewed-by: Ranier Vilela <ranier.vf@gmail.com>
Reviewed-by: Alvaro Herrera <alvherre@alvh.no-ip.org>
Discussion: https://www.postgresql.org/message-id/9847b13c-b785-f4e2-75c3-12ec77a3b05c@enterprisedb.com
Diffstat (limited to 'src/backend/commands/tablecmds.c')
-rw-r--r-- | src/backend/commands/tablecmds.c | 44 |
1 files changed, 14 insertions, 30 deletions
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index f2947ea9b49..a2f577024a1 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -8988,15 +8988,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, @@ -9088,16 +9088,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); @@ -11473,7 +11463,7 @@ validateForeignKeyConstraint(char *conname, { TupleTableSlot *slot; TableScanDesc scan; - Trigger trig; + Trigger trig = {0}; Snapshot snapshot; MemoryContext oldcxt; MemoryContext perTupCxt; @@ -11484,7 +11474,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; @@ -12758,15 +12747,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, @@ -19192,7 +19177,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)) @@ -19205,7 +19190,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; |