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/user.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/user.c')
-rw-r--r-- | src/backend/commands/user.c | 37 |
1 files changed, 11 insertions, 26 deletions
diff --git a/src/backend/commands/user.c b/src/backend/commands/user.c index 984305ba31c..5b24b6dcad8 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; |