From 5117e66043b6c8c66c2f98fcd99fdaefec66f90e Mon Sep 17 00:00:00 2001
From: Justin Pryzby <pryzbyj@telsasoft.com>
Date: Fri, 27 Dec 2019 17:30:36 -0600
Subject: [PATCH v1 1/2] Avoid some calls to memset..

..in cases where that saves a couple lines of code.
Note that gcc has builtin for memset, but inlined function is still not same as
initializing to zero.

That should probably be faster, since the local storage can be zerod by the
compiler during stack manipulation, and could possibly allow for
additional optimization, too.
---
 contrib/pageinspect/ginfuncs.c                 | 12 +++---------
 contrib/pageinspect/heapfuncs.c                |  4 +---
 contrib/pageinspect/rawpage.c                  |  4 +---
 contrib/pgstattuple/pgstatapprox.c             |  4 +---
 src/backend/catalog/pg_collation.c             |  4 +---
 src/backend/catalog/pg_db_role_setting.c       |  4 +---
 src/backend/catalog/pg_depend.c                |  4 +---
 src/backend/catalog/pg_enum.c                  |  6 ++----
 src/backend/catalog/pg_inherits.c              |  4 +---
 src/backend/catalog/pg_range.c                 |  4 +---
 src/backend/catalog/pg_shdepend.c              |  8 ++------
 src/backend/commands/event_trigger.c           |  3 +--
 src/backend/commands/indexcmds.c               |  3 +--
 src/backend/commands/seclabel.c                | 12 ++++--------
 src/backend/commands/sequence.c                | 12 +++---------
 src/backend/commands/trigger.c                 |  4 +---
 src/backend/commands/tsearchcmds.c             |  3 +--
 src/backend/replication/logical/logicalfuncs.c |  3 +--
 src/backend/replication/slotfuncs.c            |  8 ++------
 src/backend/replication/walsender.c            |  3 +--
 src/backend/statistics/mcv.c                   |  5 +----
 src/backend/utils/adt/genfile.c                |  4 +---
 22 files changed, 32 insertions(+), 86 deletions(-)

diff --git a/contrib/pageinspect/ginfuncs.c b/contrib/pageinspect/ginfuncs.c
index 4b623fb..d9590bd 100644
--- a/contrib/pageinspect/ginfuncs.c
+++ b/contrib/pageinspect/ginfuncs.c
@@ -40,7 +40,7 @@ gin_metapage_info(PG_FUNCTION_ARGS)
 	GinMetaPageData *metadata;
 	HeapTuple	resultTuple;
 	Datum		values[10];
-	bool		nulls[10];
+	bool		nulls[10] = {0,};
 
 	if (!superuser())
 		ereport(ERROR,
@@ -63,8 +63,6 @@ gin_metapage_info(PG_FUNCTION_ARGS)
 
 	metadata = GinPageGetMeta(page);
 
-	memset(nulls, 0, sizeof(nulls));
-
 	values[0] = Int64GetDatum(metadata->head);
 	values[1] = Int64GetDatum(metadata->tail);
 	values[2] = Int32GetDatum(metadata->tailFreeSize);
@@ -95,7 +93,7 @@ gin_page_opaque_info(PG_FUNCTION_ARGS)
 	GinPageOpaque opaq;
 	HeapTuple	resultTuple;
 	Datum		values[3];
-	bool		nulls[3];
+	bool		nulls[3] = {0,};
 	Datum		flags[16];
 	int			nflags = 0;
 	uint16		flagbits;
@@ -139,8 +137,6 @@ gin_page_opaque_info(PG_FUNCTION_ARGS)
 		flags[nflags++] = DirectFunctionCall1(to_hex32, Int32GetDatum(flagbits));
 	}
 
-	memset(nulls, 0, sizeof(nulls));
-
 	values[0] = Int64GetDatum(opaq->rightlink);
 	values[1] = Int32GetDatum(opaq->maxoff);
 	values[2] = PointerGetDatum(construct_array(flags, nflags,
@@ -227,14 +223,12 @@ gin_leafpage_items(PG_FUNCTION_ARGS)
 		HeapTuple	resultTuple;
 		Datum		result;
 		Datum		values[3];
-		bool		nulls[3];
+		bool		nulls[3] = {0,};
 		int			ndecoded,
 					i;
 		ItemPointer tids;
 		Datum	   *tids_datum;
 
-		memset(nulls, 0, sizeof(nulls));
-
 		values[0] = ItemPointerGetDatum(&cur->first);
 		values[1] = UInt16GetDatum(cur->nbytes);
 
diff --git a/contrib/pageinspect/heapfuncs.c b/contrib/pageinspect/heapfuncs.c
index aa7e4b9..5b8ddf3 100644
--- a/contrib/pageinspect/heapfuncs.c
+++ b/contrib/pageinspect/heapfuncs.c
@@ -179,13 +179,11 @@ heap_page_items(PG_FUNCTION_ARGS)
 		Datum		result;
 		ItemId		id;
 		Datum		values[14];
-		bool		nulls[14];
+		bool		nulls[14] = {0,};
 		uint16		lp_offset;
 		uint16		lp_flags;
 		uint16		lp_len;
 
-		memset(nulls, 0, sizeof(nulls));
-
 		/* Extract information from the line pointer */
 
 		id = PageGetItemId(page, inter_call_data->offset);
diff --git a/contrib/pageinspect/rawpage.c b/contrib/pageinspect/rawpage.c
index a7b0d17..0901429 100644
--- a/contrib/pageinspect/rawpage.c
+++ b/contrib/pageinspect/rawpage.c
@@ -225,7 +225,7 @@ page_header(PG_FUNCTION_ARGS)
 	Datum		result;
 	HeapTuple	tuple;
 	Datum		values[9];
-	bool		nulls[9];
+	bool		nulls[9] = {0,};
 
 	PageHeader	page;
 	XLogRecPtr	lsn;
@@ -278,8 +278,6 @@ page_header(PG_FUNCTION_ARGS)
 
 	/* Build and return the tuple. */
 
-	memset(nulls, 0, sizeof(nulls));
-
 	tuple = heap_form_tuple(tupdesc, values, nulls);
 	result = HeapTupleGetDatum(tuple);
 
diff --git a/contrib/pgstattuple/pgstatapprox.c b/contrib/pgstattuple/pgstatapprox.c
index 672dbf2..826db15 100644
--- a/contrib/pgstattuple/pgstatapprox.c
+++ b/contrib/pgstattuple/pgstatapprox.c
@@ -254,7 +254,7 @@ pgstattuple_approx_internal(Oid relid, FunctionCallInfo fcinfo)
 	Relation	rel;
 	output_type stat = {0};
 	TupleDesc	tupdesc;
-	bool		nulls[NUM_OUTPUT_COLUMNS];
+	bool		nulls[NUM_OUTPUT_COLUMNS] = {0,};
 	Datum		values[NUM_OUTPUT_COLUMNS];
 	HeapTuple	ret;
 	int			i = 0;
@@ -297,8 +297,6 @@ pgstattuple_approx_internal(Oid relid, FunctionCallInfo fcinfo)
 
 	relation_close(rel, AccessShareLock);
 
-	memset(nulls, 0, sizeof(nulls));
-
 	values[i++] = Int64GetDatum(stat.table_len);
 	values[i++] = Float8GetDatum(stat.scanned_percent);
 	values[i++] = Int64GetDatum(stat.tuple_count);
diff --git a/src/backend/catalog/pg_collation.c b/src/backend/catalog/pg_collation.c
index 8559779..f818857 100644
--- a/src/backend/catalog/pg_collation.c
+++ b/src/backend/catalog/pg_collation.c
@@ -57,7 +57,7 @@ CollationCreate(const char *collname, Oid collnamespace,
 	TupleDesc	tupDesc;
 	HeapTuple	tup;
 	Datum		values[Natts_pg_collation];
-	bool		nulls[Natts_pg_collation];
+	bool		nulls[Natts_pg_collation] = {0,};
 	NameData	name_name,
 				name_collate,
 				name_ctype;
@@ -151,8 +151,6 @@ CollationCreate(const char *collname, Oid collnamespace,
 	tupDesc = RelationGetDescr(rel);
 
 	/* form a tuple */
-	memset(nulls, 0, sizeof(nulls));
-
 	namestrcpy(&name_name, collname);
 	oid = GetNewOidWithIndex(rel, CollationOidIndexId,
 							 Anum_pg_collation_oid);
diff --git a/src/backend/catalog/pg_db_role_setting.c b/src/backend/catalog/pg_db_role_setting.c
index 33fc53a..58a32a4 100644
--- a/src/backend/catalog/pg_db_role_setting.c
+++ b/src/backend/catalog/pg_db_role_setting.c
@@ -136,11 +136,9 @@ AlterSetting(Oid databaseid, Oid roleid, VariableSetStmt *setstmt)
 		/* non-null valuestr means it's not RESET, so insert a new tuple */
 		HeapTuple	newtuple;
 		Datum		values[Natts_pg_db_role_setting];
-		bool		nulls[Natts_pg_db_role_setting];
+		bool		nulls[Natts_pg_db_role_setting] = {0,};
 		ArrayType  *a;
 
-		memset(nulls, false, sizeof(nulls));
-
 		a = GUCArrayAdd(NULL, setstmt->name, valuestr);
 
 		values[Anum_pg_db_role_setting_setdatabase - 1] =
diff --git a/src/backend/catalog/pg_depend.c b/src/backend/catalog/pg_depend.c
index f9af245..832ff76 100644
--- a/src/backend/catalog/pg_depend.c
+++ b/src/backend/catalog/pg_depend.c
@@ -61,7 +61,7 @@ recordMultipleDependencies(const ObjectAddress *depender,
 	CatalogIndexState indstate;
 	HeapTuple	tup;
 	int			i;
-	bool		nulls[Natts_pg_depend];
+	bool		nulls[Natts_pg_depend] = {0,};
 	Datum		values[Natts_pg_depend];
 
 	if (nreferenced <= 0)
@@ -79,8 +79,6 @@ recordMultipleDependencies(const ObjectAddress *depender,
 	/* Don't open indexes unless we need to make an update */
 	indstate = NULL;
 
-	memset(nulls, false, sizeof(nulls));
-
 	for (i = 0; i < nreferenced; i++, referenced++)
 	{
 		/*
diff --git a/src/backend/catalog/pg_enum.c b/src/backend/catalog/pg_enum.c
index 27e4100..0146955 100644
--- a/src/backend/catalog/pg_enum.c
+++ b/src/backend/catalog/pg_enum.c
@@ -65,7 +65,7 @@ EnumValuesCreate(Oid enumTypeOid, List *vals)
 	int			elemno,
 				num_elems;
 	Datum		values[Natts_pg_enum];
-	bool		nulls[Natts_pg_enum];
+	bool		nulls[Natts_pg_enum] = {0,};
 	ListCell   *lc;
 	HeapTuple	tup;
 
@@ -110,7 +110,6 @@ EnumValuesCreate(Oid enumTypeOid, List *vals)
 	qsort(oids, num_elems, sizeof(Oid), oid_cmp);
 
 	/* and make the entries */
-	memset(nulls, false, sizeof(nulls));
 
 	elemno = 0;
 	foreach(lc, vals)
@@ -214,7 +213,7 @@ AddEnumLabel(Oid enumTypeOid,
 	Relation	pg_enum;
 	Oid			newOid;
 	Datum		values[Natts_pg_enum];
-	bool		nulls[Natts_pg_enum];
+	bool		nulls[Natts_pg_enum] = {0,};
 	NameData	enumlabel;
 	HeapTuple	enum_tup;
 	float4		newelemorder;
@@ -479,7 +478,6 @@ restart:
 	ReleaseCatCacheList(list);
 
 	/* Create the new pg_enum entry */
-	memset(nulls, false, sizeof(nulls));
 	values[Anum_pg_enum_oid - 1] = ObjectIdGetDatum(newOid);
 	values[Anum_pg_enum_enumtypid - 1] = ObjectIdGetDatum(enumTypeOid);
 	values[Anum_pg_enum_enumsortorder - 1] = Float4GetDatum(newelemorder);
diff --git a/src/backend/catalog/pg_inherits.c b/src/backend/catalog/pg_inherits.c
index 17f37eb..3a98fa1 100644
--- a/src/backend/catalog/pg_inherits.c
+++ b/src/backend/catalog/pg_inherits.c
@@ -417,7 +417,7 @@ void
 StoreSingleInheritance(Oid relationId, Oid parentOid, int32 seqNumber)
 {
 	Datum		values[Natts_pg_inherits];
-	bool		nulls[Natts_pg_inherits];
+	bool		nulls[Natts_pg_inherits] = {0,};
 	HeapTuple	tuple;
 	Relation	inhRelation;
 
@@ -430,8 +430,6 @@ StoreSingleInheritance(Oid relationId, Oid parentOid, int32 seqNumber)
 	values[Anum_pg_inherits_inhparent - 1] = ObjectIdGetDatum(parentOid);
 	values[Anum_pg_inherits_inhseqno - 1] = Int32GetDatum(seqNumber);
 
-	memset(nulls, 0, sizeof(nulls));
-
 	tuple = heap_form_tuple(RelationGetDescr(inhRelation), values, nulls);
 
 	CatalogTupleInsert(inhRelation, tuple);
diff --git a/src/backend/catalog/pg_range.c b/src/backend/catalog/pg_range.c
index b5bc36c..36a2103 100644
--- a/src/backend/catalog/pg_range.c
+++ b/src/backend/catalog/pg_range.c
@@ -39,15 +39,13 @@ RangeCreate(Oid rangeTypeOid, Oid rangeSubType, Oid rangeCollation,
 {
 	Relation	pg_range;
 	Datum		values[Natts_pg_range];
-	bool		nulls[Natts_pg_range];
+	bool		nulls[Natts_pg_range] = {0,};
 	HeapTuple	tup;
 	ObjectAddress myself;
 	ObjectAddress referenced;
 
 	pg_range = table_open(RangeRelationId, RowExclusiveLock);
 
-	memset(nulls, 0, sizeof(nulls));
-
 	values[Anum_pg_range_rngtypid - 1] = ObjectIdGetDatum(rangeTypeOid);
 	values[Anum_pg_range_rngsubtype - 1] = ObjectIdGetDatum(rangeSubType);
 	values[Anum_pg_range_rngcollation - 1] = ObjectIdGetDatum(rangeCollation);
diff --git a/src/backend/catalog/pg_shdepend.c b/src/backend/catalog/pg_shdepend.c
index 2ef792d..ff05868 100644
--- a/src/backend/catalog/pg_shdepend.c
+++ b/src/backend/catalog/pg_shdepend.c
@@ -272,9 +272,7 @@ shdepChangeDep(Relation sdepRel,
 	{
 		/* Need to insert new entry */
 		Datum		values[Natts_pg_shdepend];
-		bool		nulls[Natts_pg_shdepend];
-
-		memset(nulls, false, sizeof(nulls));
+		bool		nulls[Natts_pg_shdepend] = {0,};
 
 		values[Anum_pg_shdepend_dbid - 1] = ObjectIdGetDatum(dbid);
 		values[Anum_pg_shdepend_classid - 1] = ObjectIdGetDatum(classid);
@@ -933,7 +931,7 @@ shdepAddDependency(Relation sdepRel,
 {
 	HeapTuple	tup;
 	Datum		values[Natts_pg_shdepend];
-	bool		nulls[Natts_pg_shdepend];
+	bool		nulls[Natts_pg_shdepend] = {0,};
 
 	/*
 	 * Make sure the object doesn't go away while we record the dependency on
@@ -942,8 +940,6 @@ shdepAddDependency(Relation sdepRel,
 	 */
 	shdepLockAndCheckObject(refclassId, refobjId);
 
-	memset(nulls, false, sizeof(nulls));
-
 	/*
 	 * Form the new tuple and record the dependency.
 	 */
diff --git a/src/backend/commands/event_trigger.c b/src/backend/commands/event_trigger.c
index 6d4154a..864cee2 100644
--- a/src/backend/commands/event_trigger.c
+++ b/src/backend/commands/event_trigger.c
@@ -380,7 +380,7 @@ insert_event_trigger_tuple(const char *trigname, const char *eventname, Oid evtO
 	Oid			trigoid;
 	HeapTuple	tuple;
 	Datum		values[Natts_pg_trigger];
-	bool		nulls[Natts_pg_trigger];
+	bool		nulls[Natts_pg_trigger] = {0,};
 	NameData	evtnamedata,
 				evteventdata;
 	ObjectAddress myself,
@@ -393,7 +393,6 @@ insert_event_trigger_tuple(const char *trigname, const char *eventname, Oid evtO
 	trigoid = GetNewOidWithIndex(tgrel, EventTriggerOidIndexId,
 								 Anum_pg_event_trigger_oid);
 	values[Anum_pg_event_trigger_oid - 1] = ObjectIdGetDatum(trigoid);
-	memset(nulls, false, sizeof(nulls));
 	namestrcpy(&evtnamedata, trigname);
 	values[Anum_pg_event_trigger_evtname - 1] = NameGetDatum(&evtnamedata);
 	namestrcpy(&evteventdata, eventname);
diff --git a/src/backend/commands/indexcmds.c b/src/backend/commands/indexcmds.c
index 7b33b98..f93dc7b 100644
--- a/src/backend/commands/indexcmds.c
+++ b/src/backend/commands/indexcmds.c
@@ -3400,7 +3400,7 @@ IndexSetParentIndex(Relation partitionIdx, Oid parentOid)
 		else
 		{
 			Datum		values[Natts_pg_inherits];
-			bool		isnull[Natts_pg_inherits];
+			bool		isnull[Natts_pg_inherits] = {0,};
 
 			/*
 			 * No pg_inherits row exists, and we want a parent for this index,
@@ -3410,7 +3410,6 @@ IndexSetParentIndex(Relation partitionIdx, Oid parentOid)
 			values[Anum_pg_inherits_inhparent - 1] =
 				ObjectIdGetDatum(parentOid);
 			values[Anum_pg_inherits_inhseqno - 1] = Int32GetDatum(1);
-			memset(isnull, false, sizeof(isnull));
 
 			tuple = heap_form_tuple(RelationGetDescr(pg_inherits),
 									values, isnull);
diff --git a/src/backend/commands/seclabel.c b/src/backend/commands/seclabel.c
index b497c06..e64fe96 100644
--- a/src/backend/commands/seclabel.c
+++ b/src/backend/commands/seclabel.c
@@ -258,12 +258,10 @@ SetSharedSecurityLabel(const ObjectAddress *object,
 	HeapTuple	oldtup;
 	HeapTuple	newtup = NULL;
 	Datum		values[Natts_pg_shseclabel];
-	bool		nulls[Natts_pg_shseclabel];
-	bool		replaces[Natts_pg_shseclabel];
+	bool		nulls[Natts_pg_shseclabel] = {0,};
+	bool		replaces[Natts_pg_shseclabel] = {0,};
 
 	/* Prepare to form or update a tuple, if necessary. */
-	memset(nulls, false, sizeof(nulls));
-	memset(replaces, false, sizeof(replaces));
 	values[Anum_pg_shseclabel_objoid - 1] = ObjectIdGetDatum(object->objectId);
 	values[Anum_pg_shseclabel_classoid - 1] = ObjectIdGetDatum(object->classId);
 	values[Anum_pg_shseclabel_provider - 1] = CStringGetTextDatum(provider);
@@ -333,8 +331,8 @@ SetSecurityLabel(const ObjectAddress *object,
 	HeapTuple	oldtup;
 	HeapTuple	newtup = NULL;
 	Datum		values[Natts_pg_seclabel];
-	bool		nulls[Natts_pg_seclabel];
-	bool		replaces[Natts_pg_seclabel];
+	bool		nulls[Natts_pg_seclabel] = {0,};
+	bool		replaces[Natts_pg_seclabel] = {0,};
 
 	/* Shared objects have their own security label catalog. */
 	if (IsSharedRelation(object->classId))
@@ -344,8 +342,6 @@ SetSecurityLabel(const ObjectAddress *object,
 	}
 
 	/* Prepare to form or update a tuple, if necessary. */
-	memset(nulls, false, sizeof(nulls));
-	memset(replaces, false, sizeof(replaces));
 	values[Anum_pg_seclabel_objoid - 1] = ObjectIdGetDatum(object->objectId);
 	values[Anum_pg_seclabel_classoid - 1] = ObjectIdGetDatum(object->classId);
 	values[Anum_pg_seclabel_objsubid - 1] = Int32GetDatum(object->objectSubId);
diff --git a/src/backend/commands/sequence.c b/src/backend/commands/sequence.c
index 6aab73b..f7ea908 100644
--- a/src/backend/commands/sequence.c
+++ b/src/backend/commands/sequence.c
@@ -128,9 +128,9 @@ DefineSequence(ParseState *pstate, CreateSeqStmt *seq)
 	HeapTuple	tuple;
 	TupleDesc	tupDesc;
 	Datum		value[SEQ_COL_LASTCOL];
-	bool		null[SEQ_COL_LASTCOL];
+	bool		null[SEQ_COL_LASTCOL] = {0,};
 	Datum		pgs_values[Natts_pg_sequence];
-	bool		pgs_nulls[Natts_pg_sequence];
+	bool		pgs_nulls[Natts_pg_sequence] = {0,};
 	int			i;
 
 	/* Unlogged sequences are not implemented -- not clear if useful. */
@@ -182,8 +182,6 @@ DefineSequence(ParseState *pstate, CreateSeqStmt *seq)
 		coldef->constraints = NIL;
 		coldef->location = -1;
 
-		null[i - 1] = false;
-
 		switch (i)
 		{
 			case SEQ_COL_LASTVAL:
@@ -234,8 +232,6 @@ DefineSequence(ParseState *pstate, CreateSeqStmt *seq)
 	rel = table_open(SequenceRelationId, RowExclusiveLock);
 	tupDesc = RelationGetDescr(rel);
 
-	memset(pgs_nulls, 0, sizeof(pgs_nulls));
-
 	pgs_values[Anum_pg_sequence_seqrelid - 1] = ObjectIdGetDatum(seqoid);
 	pgs_values[Anum_pg_sequence_seqtypid - 1] = ObjectIdGetDatum(seqform.seqtypid);
 	pgs_values[Anum_pg_sequence_seqstart - 1] = Int64GetDatumFast(seqform.seqstart);
@@ -1790,7 +1786,7 @@ pg_sequence_parameters(PG_FUNCTION_ARGS)
 	Oid			relid = PG_GETARG_OID(0);
 	TupleDesc	tupdesc;
 	Datum		values[7];
-	bool		isnull[7];
+	bool		isnull[7] = {0,};
 	HeapTuple	pgstuple;
 	Form_pg_sequence pgsform;
 
@@ -1818,8 +1814,6 @@ pg_sequence_parameters(PG_FUNCTION_ARGS)
 
 	BlessTupleDesc(tupdesc);
 
-	memset(isnull, 0, sizeof(isnull));
-
 	pgstuple = SearchSysCache1(SEQRELID, relid);
 	if (!HeapTupleIsValid(pgstuple))
 		elog(ERROR, "cache lookup failed for sequence %u", relid);
diff --git a/src/backend/commands/trigger.c b/src/backend/commands/trigger.c
index c5c7b21..e7da3f3 100644
--- a/src/backend/commands/trigger.c
+++ b/src/backend/commands/trigger.c
@@ -171,7 +171,7 @@ CreateTrigger(CreateTrigStmt *stmt, const char *queryString,
 	List	   *whenRtable;
 	char	   *qual;
 	Datum		values[Natts_pg_trigger];
-	bool		nulls[Natts_pg_trigger];
+	bool		nulls[Natts_pg_trigger] = {0,};
 	Relation	rel;
 	AclResult	aclresult;
 	Relation	tgrel;
@@ -843,8 +843,6 @@ CreateTrigger(CreateTrigStmt *stmt, const char *queryString,
 	 * makes the triggers in partitions identical to the ones in the
 	 * partitioned tables, except that they are marked internal.
 	 */
-	memset(nulls, false, sizeof(nulls));
-
 	values[Anum_pg_trigger_oid - 1] = ObjectIdGetDatum(trigoid);
 	values[Anum_pg_trigger_tgrelid - 1] = ObjectIdGetDatum(RelationGetRelid(rel));
 	values[Anum_pg_trigger_tgname - 1] = DirectFunctionCall1(namein,
diff --git a/src/backend/commands/tsearchcmds.c b/src/backend/commands/tsearchcmds.c
index 9dca682..65e4cf8 100644
--- a/src/backend/commands/tsearchcmds.c
+++ b/src/backend/commands/tsearchcmds.c
@@ -1420,9 +1420,8 @@ MakeConfigurationMapping(AlterTSConfigurationStmt *stmt,
 			for (j = 0; j < ndict; j++)
 			{
 				Datum		values[Natts_pg_ts_config_map];
-				bool		nulls[Natts_pg_ts_config_map];
+				bool		nulls[Natts_pg_ts_config_map] = {0,};
 
-				memset(nulls, false, sizeof(nulls));
 				values[Anum_pg_ts_config_map_mapcfg - 1] = ObjectIdGetDatum(cfgId);
 				values[Anum_pg_ts_config_map_maptokentype - 1] = Int32GetDatum(tokens[i]);
 				values[Anum_pg_ts_config_map_mapseqno - 1] = Int32GetDatum(j + 1);
diff --git a/src/backend/replication/logical/logicalfuncs.c b/src/backend/replication/logical/logicalfuncs.c
index 7693c98..cb23dd6 100644
--- a/src/backend/replication/logical/logicalfuncs.c
+++ b/src/backend/replication/logical/logicalfuncs.c
@@ -67,7 +67,7 @@ LogicalOutputWrite(LogicalDecodingContext *ctx, XLogRecPtr lsn, TransactionId xi
 				   bool last_write)
 {
 	Datum		values[3];
-	bool		nulls[3];
+	bool		nulls[3] = {0,};
 	DecodingOutputState *p;
 
 	/* SQL Datums can only be of a limited length... */
@@ -76,7 +76,6 @@ LogicalOutputWrite(LogicalDecodingContext *ctx, XLogRecPtr lsn, TransactionId xi
 
 	p = (DecodingOutputState *) ctx->output_writer_private;
 
-	memset(nulls, 0, sizeof(nulls));
 	values[0] = LSNGetDatum(lsn);
 	values[1] = TransactionIdGetDatum(xid);
 
diff --git a/src/backend/replication/slotfuncs.c b/src/backend/replication/slotfuncs.c
index bb69683..6cb4c6d 100644
--- a/src/backend/replication/slotfuncs.c
+++ b/src/backend/replication/slotfuncs.c
@@ -167,7 +167,7 @@ pg_create_logical_replication_slot(PG_FUNCTION_ARGS)
 	TupleDesc	tupdesc;
 	HeapTuple	tuple;
 	Datum		values[2];
-	bool		nulls[2];
+	bool		nulls[2] = {0,};
 
 	if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE)
 		elog(ERROR, "return type must be a row type");
@@ -184,8 +184,6 @@ pg_create_logical_replication_slot(PG_FUNCTION_ARGS)
 	values[0] = NameGetDatum(&MyReplicationSlot->data.name);
 	values[1] = LSNGetDatum(MyReplicationSlot->data.confirmed_flush);
 
-	memset(nulls, 0, sizeof(nulls));
-
 	tuple = heap_form_tuple(tupdesc, values, nulls);
 	result = HeapTupleGetDatum(tuple);
 
@@ -264,7 +262,7 @@ pg_get_replication_slots(PG_FUNCTION_ARGS)
 	{
 		ReplicationSlot *slot = &ReplicationSlotCtl->replication_slots[slotno];
 		Datum		values[PG_GET_REPLICATION_SLOTS_COLS];
-		bool		nulls[PG_GET_REPLICATION_SLOTS_COLS];
+		bool		nulls[PG_GET_REPLICATION_SLOTS_COLS] = {0,};
 
 		ReplicationSlotPersistency persistency;
 		TransactionId xmin;
@@ -294,8 +292,6 @@ pg_get_replication_slots(PG_FUNCTION_ARGS)
 
 		SpinLockRelease(&slot->mutex);
 
-		memset(nulls, 0, sizeof(nulls));
-
 		i = 0;
 		values[i++] = NameGetDatum(&slot_name);
 
diff --git a/src/backend/replication/walsender.c b/src/backend/replication/walsender.c
index 6e80e67..03c1e28 100644
--- a/src/backend/replication/walsender.c
+++ b/src/backend/replication/walsender.c
@@ -3237,7 +3237,7 @@ pg_stat_get_wal_senders(PG_FUNCTION_ARGS)
 		int64		spillCount;
 		int64		spillBytes;
 		Datum		values[PG_STAT_GET_WAL_SENDERS_COLS];
-		bool		nulls[PG_STAT_GET_WAL_SENDERS_COLS];
+		bool		nulls[PG_STAT_GET_WAL_SENDERS_COLS] = {0,};
 
 		SpinLockAcquire(&walsnd->mutex);
 		if (walsnd->pid == 0)
@@ -3261,7 +3261,6 @@ pg_stat_get_wal_senders(PG_FUNCTION_ARGS)
 		spillBytes = walsnd->spillBytes;
 		SpinLockRelease(&walsnd->mutex);
 
-		memset(nulls, 0, sizeof(nulls));
 		values[0] = Int32GetDatum(pid);
 
 		if (!is_member_of_role(GetUserId(), DEFAULT_ROLE_READ_ALL_STATS))
diff --git a/src/backend/statistics/mcv.c b/src/backend/statistics/mcv.c
index 87e232f..199453a 100644
--- a/src/backend/statistics/mcv.c
+++ b/src/backend/statistics/mcv.c
@@ -1380,7 +1380,7 @@ pg_stats_ext_mcvlist_items(PG_FUNCTION_ARGS)
 	if (funcctx->call_cntr < funcctx->max_calls)	/* do when there is more left to send */
 	{
 		Datum		values[5];
-		bool		nulls[5];
+		bool		nulls[5] = {0,};
 		HeapTuple	tuple;
 		Datum		result;
 		ArrayBuildState *astate_values = NULL;
@@ -1440,9 +1440,6 @@ pg_stats_ext_mcvlist_items(PG_FUNCTION_ARGS)
 		values[3] = Float8GetDatum(item->frequency);
 		values[4] = Float8GetDatum(item->base_frequency);
 
-		/* no NULLs in the tuple */
-		memset(nulls, 0, sizeof(nulls));
-
 		/* build a tuple */
 		tuple = heap_form_tuple(funcctx->attinmeta->tupdesc, values, nulls);
 
diff --git a/src/backend/utils/adt/genfile.c b/src/backend/utils/adt/genfile.c
index 81b3d82..f7882c7 100644
--- a/src/backend/utils/adt/genfile.c
+++ b/src/backend/utils/adt/genfile.c
@@ -365,7 +365,7 @@ pg_stat_file(PG_FUNCTION_ARGS)
 	char	   *filename;
 	struct stat fst;
 	Datum		values[6];
-	bool		isnull[6];
+	bool		isnull[6] = {0,};
 	HeapTuple	tuple;
 	TupleDesc	tupdesc;
 	bool		missing_ok = false;
@@ -405,8 +405,6 @@ pg_stat_file(PG_FUNCTION_ARGS)
 					   "isdir", BOOLOID, -1, 0);
 	BlessTupleDesc(tupdesc);
 
-	memset(isnull, false, sizeof(isnull));
-
 	values[0] = Int64GetDatum((int64) fst.st_size);
 	values[1] = TimestampTzGetDatum(time_t_to_timestamptz(fst.st_atime));
 	values[2] = TimestampTzGetDatum(time_t_to_timestamptz(fst.st_mtime));
-- 
2.7.4

