aboutsummaryrefslogtreecommitdiff
path: root/src/backend/commands/dbcommands.c
diff options
context:
space:
mode:
authorPeter Eisentraut <peter@eisentraut.org>2022-07-16 08:42:15 +0200
committerPeter Eisentraut <peter@eisentraut.org>2022-07-16 08:50:49 +0200
commit9fd45870c1436b477264c0c82eb195df52bc0919 (patch)
tree10a09724c0bcffa8f58f262e50c3260cde484446 /src/backend/commands/dbcommands.c
parentc94ae9d827a360d74da6a304692d34a4dc8b6445 (diff)
downloadpostgresql-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/dbcommands.c')
-rw-r--r--src/backend/commands/dbcommands.c35
1 files changed, 11 insertions, 24 deletions
diff --git a/src/backend/commands/dbcommands.c b/src/backend/commands/dbcommands.c
index 1901b434c58..099d369b2f4 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);