From d399278c68b4d91d2666984067894ab6cf08d22a Mon Sep 17 00:00:00 2001
From: Justin Pryzby <pryzbyj@telsasoft.com>
Date: Fri, 27 Dec 2019 17:23:12 -0600
Subject: [PATCH v1 2/2] Some less useful changes to avoid memset..

.. when memset is being called anyway on something other than a bool.
---
 contrib/dblink/dblink.c                         | 3 +--
 contrib/pg_stat_statements/pg_stat_statements.c | 3 +--
 src/backend/catalog/heap.c                      | 6 ++----
 src/backend/catalog/pg_largeobject.c            | 3 +--
 src/backend/catalog/pg_publication.c            | 3 +--
 src/backend/catalog/pg_shdepend.c               | 6 ++----
 src/backend/catalog/pg_subscription.c           | 9 +++------
 src/backend/commands/amcmds.c                   | 3 +--
 src/backend/commands/collationcmds.c            | 6 ++----
 src/backend/commands/foreigncmds.c              | 3 +--
 src/backend/commands/proclang.c                 | 3 +--
 src/backend/commands/publicationcmds.c          | 9 +++------
 src/backend/utils/misc/guc.c                    | 3 +--
 13 files changed, 20 insertions(+), 40 deletions(-)

diff --git a/contrib/dblink/dblink.c b/contrib/dblink/dblink.c
index 1dddf02..07bfee2 100644
--- a/contrib/dblink/dblink.c
+++ b/contrib/dblink/dblink.c
@@ -1902,10 +1902,9 @@ dblink_get_notify(PG_FUNCTION_ARGS)
 	while ((notify = PQnotifies(conn)) != NULL)
 	{
 		Datum		values[DBLINK_NOTIFY_COLS];
-		bool		nulls[DBLINK_NOTIFY_COLS];
+		bool		nulls[DBLINK_NOTIFY_COLS] = {0,};
 
 		memset(values, 0, sizeof(values));
-		memset(nulls, 0, sizeof(nulls));
 
 		if (notify->relname != NULL)
 			values[0] = CStringGetTextDatum(notify->relname);
diff --git a/contrib/pg_stat_statements/pg_stat_statements.c b/contrib/pg_stat_statements/pg_stat_statements.c
index 6f82a67..1caf4c2 100644
--- a/contrib/pg_stat_statements/pg_stat_statements.c
+++ b/contrib/pg_stat_statements/pg_stat_statements.c
@@ -1530,14 +1530,13 @@ pg_stat_statements_internal(FunctionCallInfo fcinfo,
 	while ((entry = hash_seq_search(&hash_seq)) != NULL)
 	{
 		Datum		values[PG_STAT_STATEMENTS_COLS];
-		bool		nulls[PG_STAT_STATEMENTS_COLS];
+		bool		nulls[PG_STAT_STATEMENTS_COLS] = {0,};
 		int			i = 0;
 		Counters	tmp;
 		double		stddev;
 		int64		queryid = entry->key.queryid;
 
 		memset(values, 0, sizeof(values));
-		memset(nulls, 0, sizeof(nulls));
 
 		values[i++] = ObjectIdGetDatum(entry->key.userid);
 		values[i++] = ObjectIdGetDatum(entry->key.dbid);
diff --git a/src/backend/catalog/heap.c b/src/backend/catalog/heap.c
index 01ecd9f..1c94eb4 100644
--- a/src/backend/catalog/heap.c
+++ b/src/backend/catalog/heap.c
@@ -727,12 +727,11 @@ InsertPgAttributeTuple(Relation pg_attribute_rel,
 					   CatalogIndexState indstate)
 {
 	Datum		values[Natts_pg_attribute];
-	bool		nulls[Natts_pg_attribute];
+	bool		nulls[Natts_pg_attribute] = {0,};
 	HeapTuple	tup;
 
 	/* This is a tad tedious, but way cleaner than what we used to do... */
 	memset(values, 0, sizeof(values));
-	memset(nulls, false, sizeof(nulls));
 
 	values[Anum_pg_attribute_attrelid - 1] = ObjectIdGetDatum(new_attribute->attrelid);
 	values[Anum_pg_attribute_attname - 1] = NameGetDatum(&new_attribute->attname);
@@ -884,12 +883,11 @@ InsertPgClassTuple(Relation pg_class_desc,
 {
 	Form_pg_class rd_rel = new_rel_desc->rd_rel;
 	Datum		values[Natts_pg_class];
-	bool		nulls[Natts_pg_class];
+	bool		nulls[Natts_pg_class] = {0,};
 	HeapTuple	tup;
 
 	/* This is a tad tedious, but way cleaner than what we used to do... */
 	memset(values, 0, sizeof(values));
-	memset(nulls, false, sizeof(nulls));
 
 	values[Anum_pg_class_oid - 1] = ObjectIdGetDatum(new_rel_oid);
 	values[Anum_pg_class_relname - 1] = NameGetDatum(&rd_rel->relname);
diff --git a/src/backend/catalog/pg_largeobject.c b/src/backend/catalog/pg_largeobject.c
index ae9365e..10e59ba 100644
--- a/src/backend/catalog/pg_largeobject.c
+++ b/src/backend/catalog/pg_largeobject.c
@@ -43,7 +43,7 @@ LargeObjectCreate(Oid loid)
 	HeapTuple	ntup;
 	Oid			loid_new;
 	Datum		values[Natts_pg_largeobject_metadata];
-	bool		nulls[Natts_pg_largeobject_metadata];
+	bool		nulls[Natts_pg_largeobject_metadata] = {0,};
 
 	pg_lo_meta = table_open(LargeObjectMetadataRelationId,
 							RowExclusiveLock);
@@ -52,7 +52,6 @@ LargeObjectCreate(Oid loid)
 	 * Insert metadata of the largeobject
 	 */
 	memset(values, 0, sizeof(values));
-	memset(nulls, false, sizeof(nulls));
 
 	if (OidIsValid(loid))
 		loid_new = loid;
diff --git a/src/backend/catalog/pg_publication.c b/src/backend/catalog/pg_publication.c
index c5eea7a..086b20b 100644
--- a/src/backend/catalog/pg_publication.c
+++ b/src/backend/catalog/pg_publication.c
@@ -152,7 +152,7 @@ publication_add_relation(Oid pubid, Relation targetrel,
 	Relation	rel;
 	HeapTuple	tup;
 	Datum		values[Natts_pg_publication_rel];
-	bool		nulls[Natts_pg_publication_rel];
+	bool		nulls[Natts_pg_publication_rel] = {0,};
 	Oid			relid = RelationGetRelid(targetrel);
 	Oid			prrelid;
 	Publication *pub = GetPublication(pubid);
@@ -184,7 +184,6 @@ publication_add_relation(Oid pubid, Relation targetrel,
 
 	/* Form a tuple. */
 	memset(values, 0, sizeof(values));
-	memset(nulls, false, sizeof(nulls));
 
 	prrelid = GetNewOidWithIndex(rel, PublicationRelObjectIndexId,
 								 Anum_pg_publication_rel_oid);
diff --git a/src/backend/catalog/pg_shdepend.c b/src/backend/catalog/pg_shdepend.c
index ff05868..f19750e 100644
--- a/src/backend/catalog/pg_shdepend.c
+++ b/src/backend/catalog/pg_shdepend.c
@@ -799,8 +799,8 @@ copyTemplateDependencies(Oid templateDbId, Oid newDbId)
 	HeapTuple	tup;
 	CatalogIndexState indstate;
 	Datum		values[Natts_pg_shdepend];
-	bool		nulls[Natts_pg_shdepend];
-	bool		replace[Natts_pg_shdepend];
+	bool		nulls[Natts_pg_shdepend] = {0,};
+	bool		replace[Natts_pg_shdepend] = {0,};
 
 	sdepRel = table_open(SharedDependRelationId, RowExclusiveLock);
 	sdepDesc = RelationGetDescr(sdepRel);
@@ -818,8 +818,6 @@ copyTemplateDependencies(Oid templateDbId, Oid newDbId)
 
 	/* Set up to copy the tuples except for inserting newDbId */
 	memset(values, 0, sizeof(values));
-	memset(nulls, false, sizeof(nulls));
-	memset(replace, false, sizeof(replace));
 
 	replace[Anum_pg_shdepend_dbid - 1] = true;
 	values[Anum_pg_shdepend_dbid - 1] = ObjectIdGetDatum(newDbId);
diff --git a/src/backend/catalog/pg_subscription.c b/src/backend/catalog/pg_subscription.c
index f77a83b..eb03be7 100644
--- a/src/backend/catalog/pg_subscription.c
+++ b/src/backend/catalog/pg_subscription.c
@@ -237,7 +237,7 @@ AddSubscriptionRelState(Oid subid, Oid relid, char state,
 {
 	Relation	rel;
 	HeapTuple	tup;
-	bool		nulls[Natts_pg_subscription_rel];
+	bool		nulls[Natts_pg_subscription_rel] = {0,};
 	Datum		values[Natts_pg_subscription_rel];
 
 	LockSharedObject(SubscriptionRelationId, subid, 0, AccessShareLock);
@@ -254,7 +254,6 @@ AddSubscriptionRelState(Oid subid, Oid relid, char state,
 
 	/* Form the tuple. */
 	memset(values, 0, sizeof(values));
-	memset(nulls, false, sizeof(nulls));
 	values[Anum_pg_subscription_rel_srsubid - 1] = ObjectIdGetDatum(subid);
 	values[Anum_pg_subscription_rel_srrelid - 1] = ObjectIdGetDatum(relid);
 	values[Anum_pg_subscription_rel_srsubstate - 1] = CharGetDatum(state);
@@ -283,9 +282,9 @@ UpdateSubscriptionRelState(Oid subid, Oid relid, char state,
 {
 	Relation	rel;
 	HeapTuple	tup;
-	bool		nulls[Natts_pg_subscription_rel];
+	bool		nulls[Natts_pg_subscription_rel] = {0,};
+	bool		replaces[Natts_pg_subscription_rel] = {0,};
 	Datum		values[Natts_pg_subscription_rel];
-	bool		replaces[Natts_pg_subscription_rel];
 
 	LockSharedObject(SubscriptionRelationId, subid, 0, AccessShareLock);
 
@@ -301,8 +300,6 @@ UpdateSubscriptionRelState(Oid subid, Oid relid, char state,
 
 	/* Update the tuple. */
 	memset(values, 0, sizeof(values));
-	memset(nulls, false, sizeof(nulls));
-	memset(replaces, false, sizeof(replaces));
 
 	replaces[Anum_pg_subscription_rel_srsubstate - 1] = true;
 	values[Anum_pg_subscription_rel_srsubstate - 1] = CharGetDatum(state);
diff --git a/src/backend/commands/amcmds.c b/src/backend/commands/amcmds.c
index 7546378..edf1f40 100644
--- a/src/backend/commands/amcmds.c
+++ b/src/backend/commands/amcmds.c
@@ -46,7 +46,7 @@ CreateAccessMethod(CreateAmStmt *stmt)
 	ObjectAddress referenced;
 	Oid			amoid;
 	Oid			amhandler;
-	bool		nulls[Natts_pg_am];
+	bool		nulls[Natts_pg_am] = {0,};
 	Datum		values[Natts_pg_am];
 	HeapTuple	tup;
 
@@ -80,7 +80,6 @@ CreateAccessMethod(CreateAmStmt *stmt)
 	 * Insert tuple into pg_am.
 	 */
 	memset(values, 0, sizeof(values));
-	memset(nulls, false, sizeof(nulls));
 
 	amoid = GetNewOidWithIndex(rel, AmOidIndexId, Anum_pg_am_oid);
 	values[Anum_pg_am_oid - 1] = ObjectIdGetDatum(amoid);
diff --git a/src/backend/commands/collationcmds.c b/src/backend/commands/collationcmds.c
index 34c75e8..4849a33 100644
--- a/src/backend/commands/collationcmds.c
+++ b/src/backend/commands/collationcmds.c
@@ -315,8 +315,8 @@ AlterCollation(AlterCollationStmt *stmt)
 		elog(ERROR, "invalid collation version change");
 	else if (oldversion && newversion && strcmp(newversion, oldversion) != 0)
 	{
-		bool		nulls[Natts_pg_collation];
-		bool		replaces[Natts_pg_collation];
+		bool		nulls[Natts_pg_collation] = {0,};
+		bool		replaces[Natts_pg_collation] = {0,};
 		Datum		values[Natts_pg_collation];
 
 		ereport(NOTICE,
@@ -324,8 +324,6 @@ AlterCollation(AlterCollationStmt *stmt)
 						oldversion, newversion)));
 
 		memset(values, 0, sizeof(values));
-		memset(nulls, false, sizeof(nulls));
-		memset(replaces, false, sizeof(replaces));
 
 		values[Anum_pg_collation_collversion - 1] = CStringGetTextDatum(newversion);
 		replaces[Anum_pg_collation_collversion - 1] = true;
diff --git a/src/backend/commands/foreigncmds.c b/src/backend/commands/foreigncmds.c
index f197869..0834b7d 100644
--- a/src/backend/commands/foreigncmds.c
+++ b/src/backend/commands/foreigncmds.c
@@ -563,7 +563,7 @@ CreateForeignDataWrapper(CreateFdwStmt *stmt)
 {
 	Relation	rel;
 	Datum		values[Natts_pg_foreign_data_wrapper];
-	bool		nulls[Natts_pg_foreign_data_wrapper];
+	bool		nulls[Natts_pg_foreign_data_wrapper] = {0,};
 	HeapTuple	tuple;
 	Oid			fdwId;
 	bool		handler_given;
@@ -601,7 +601,6 @@ CreateForeignDataWrapper(CreateFdwStmt *stmt)
 	 * Insert tuple into pg_foreign_data_wrapper.
 	 */
 	memset(values, 0, sizeof(values));
-	memset(nulls, false, sizeof(nulls));
 
 	fdwId = GetNewOidWithIndex(rel, ForeignDataWrapperOidIndexId,
 							   Anum_pg_foreign_data_wrapper_oid);
diff --git a/src/backend/commands/proclang.c b/src/backend/commands/proclang.c
index cdff43d..226ad18 100644
--- a/src/backend/commands/proclang.c
+++ b/src/backend/commands/proclang.c
@@ -326,7 +326,7 @@ create_proc_lang(const char *languageName, bool replace,
 	Relation	rel;
 	TupleDesc	tupDesc;
 	Datum		values[Natts_pg_language];
-	bool		nulls[Natts_pg_language];
+	bool		nulls[Natts_pg_language] = {0,};
 	bool		replaces[Natts_pg_language];
 	NameData	langname;
 	HeapTuple	oldtup;
@@ -341,7 +341,6 @@ create_proc_lang(const char *languageName, bool replace,
 
 	/* Prepare data to be inserted */
 	memset(values, 0, sizeof(values));
-	memset(nulls, false, sizeof(nulls));
 	memset(replaces, true, sizeof(replaces));
 
 	namestrcpy(&langname, languageName);
diff --git a/src/backend/commands/publicationcmds.c b/src/backend/commands/publicationcmds.c
index f96cb42..eab793d 100644
--- a/src/backend/commands/publicationcmds.c
+++ b/src/backend/commands/publicationcmds.c
@@ -138,7 +138,7 @@ CreatePublication(CreatePublicationStmt *stmt)
 	Relation	rel;
 	ObjectAddress myself;
 	Oid			puboid;
-	bool		nulls[Natts_pg_publication];
+	bool		nulls[Natts_pg_publication] = {0,};
 	Datum		values[Natts_pg_publication];
 	HeapTuple	tup;
 	bool		publish_given;
@@ -175,7 +175,6 @@ CreatePublication(CreatePublicationStmt *stmt)
 
 	/* Form a tuple. */
 	memset(values, 0, sizeof(values));
-	memset(nulls, false, sizeof(nulls));
 
 	values[Anum_pg_publication_pubname - 1] =
 		DirectFunctionCall1(namein, CStringGetDatum(stmt->pubname));
@@ -246,8 +245,8 @@ static void
 AlterPublicationOptions(AlterPublicationStmt *stmt, Relation rel,
 						HeapTuple tup)
 {
-	bool		nulls[Natts_pg_publication];
-	bool		replaces[Natts_pg_publication];
+	bool		nulls[Natts_pg_publication] = {0,};
+	bool		replaces[Natts_pg_publication] = {0,};
 	Datum		values[Natts_pg_publication];
 	bool		publish_given;
 	bool		publish_insert;
@@ -264,8 +263,6 @@ AlterPublicationOptions(AlterPublicationStmt *stmt, Relation rel,
 
 	/* Everything ok, form a new tuple. */
 	memset(values, 0, sizeof(values));
-	memset(nulls, false, sizeof(nulls));
-	memset(replaces, false, sizeof(replaces));
 
 	if (publish_given)
 	{
diff --git a/src/backend/utils/misc/guc.c b/src/backend/utils/misc/guc.c
index 77ac510..e4572ad 100644
--- a/src/backend/utils/misc/guc.c
+++ b/src/backend/utils/misc/guc.c
@@ -9546,10 +9546,9 @@ show_all_file_settings(PG_FUNCTION_ARGS)
 	for (seqno = 1; conf != NULL; conf = conf->next, seqno++)
 	{
 		Datum		values[NUM_PG_FILE_SETTINGS_ATTS];
-		bool		nulls[NUM_PG_FILE_SETTINGS_ATTS];
+		bool		nulls[NUM_PG_FILE_SETTINGS_ATTS] = {0,};
 
 		memset(values, 0, sizeof(values));
-		memset(nulls, 0, sizeof(nulls));
 
 		/* sourcefile */
 		if (conf->filename)
-- 
2.7.4

