From 383640c9a3a728c2f9752f1acd958ab90adf37b5 Mon Sep 17 00:00:00 2001
From: Peter Geoghegan <pg@bowt.ie>
Date: Sun, 1 Mar 2020 16:03:25 -0800
Subject: [PATCH] Add assertions to _bt_update_posting().

---
 src/backend/access/nbtree/nbtdedup.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/src/backend/access/nbtree/nbtdedup.c b/src/backend/access/nbtree/nbtdedup.c
index 3175d6fdd1..2434ce134b 100644
--- a/src/backend/access/nbtree/nbtdedup.c
+++ b/src/backend/access/nbtree/nbtdedup.c
@@ -688,6 +688,9 @@ _bt_update_posting(BTVacuumPosting vacposting)
 	else
 		newsize = keysize;
 
+	Assert(newsize <= INDEX_SIZE_MASK);
+	Assert(newsize == MAXALIGN(newsize));
+
 	/* Allocate memory using palloc0() (matches index_form_tuple()) */
 	itup = palloc0(newsize);
 	memcpy(itup, origtuple, keysize);
@@ -721,6 +724,7 @@ _bt_update_posting(BTVacuumPosting vacposting)
 	Assert(ui == nhtids);
 	Assert(d == vacposting->ndeletedtids);
 	Assert(nhtids == 1 || _bt_posting_valid(itup));
+	Assert(nhtids > 1 || ItemPointerIsValid(&itup->t_tid));
 
 	/* vacposting arg's itup will now point to updated version */
 	vacposting->itup = itup;
-- 
2.17.1

