From be8fb5d0892466114c995a28686db487b2026ebf Mon Sep 17 00:00:00 2001
From: Daniel Gustafsson <daniel@yesql.se>
Date: Fri, 11 Sep 2020 13:34:56 +0200
Subject: [PATCH] Exit early when no objects are to be indexed

Check for objects passed to the function before allocating space for
the index, as the returned allocation will otherwise not contain an
index and thus be potentially misleading.
---
 src/bin/pg_dump/common.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/src/bin/pg_dump/common.c b/src/bin/pg_dump/common.c
index 08239dde4f..fe477ccc99 100644
--- a/src/bin/pg_dump/common.c
+++ b/src/bin/pg_dump/common.c
@@ -719,6 +719,9 @@ buildIndexArray(void *objArray, int numObjs, Size objSize)
 	DumpableObject **ptrs;
 	int			i;
 
+	if (numObjs == 0)
+		return NULL;
+
 	ptrs = (DumpableObject **) pg_malloc(numObjs * sizeof(DumpableObject *));
 	for (i = 0; i < numObjs; i++)
 		ptrs[i] = (DumpableObject *) ((char *) objArray + i * objSize);
-- 
2.21.1 (Apple Git-122.3)

