From 5d92eada65fdca559ca7b6d50f84f9eed226b048 Mon Sep 17 00:00:00 2001
From: Sehrope Sarkuni <sehrope@jackdb.com>
Date: Sun, 27 Sep 2026 12:39:29 -0400
Subject: [PATCH v1 6/7] gin: replace unreachable repalloc_array() with
 Assert()

Now that we size our result array based on the len of all segments,
we should never need to expand the result array to accomodate more
elements.  So we replace that with an Assert() that the array has
enough capacity for another element.
---
 src/backend/access/gin/ginpostinglist.c | 16 ++--------------
 1 file changed, 2 insertions(+), 14 deletions(-)

diff --git a/src/backend/access/gin/ginpostinglist.c b/src/backend/access/gin/ginpostinglist.c
index 56bb8c1e6eb..57c16eb05cb 100644
--- a/src/backend/access/gin/ginpostinglist.c
+++ b/src/backend/access/gin/ginpostinglist.c
@@ -323,14 +323,8 @@ ginPostingListDecodeAllSegments(GinPostingList *segment, int len, int *ndecoded_
 					(errcode(ERRCODE_DATA_CORRUPTED),
 					 errmsg("corrupted GIN posting list")));
 
-		/* enlarge output array if needed */
-		if (ndecoded >= nallocated)
-		{
-			nallocated *= 2;
-			result = repalloc_array(result, ItemPointerData, nallocated);
-		}
-
 		/* copy the first item */
+		Assert(ndecoded < nallocated);
 		result[ndecoded] = segment->first;
 		ndecoded++;
 
@@ -340,13 +334,6 @@ ginPostingListDecodeAllSegments(GinPostingList *segment, int len, int *ndecoded_
 		endptr = segment->bytes + segment->nbytes;
 		while (ptr < endptr)
 		{
-			/* enlarge output array if needed */
-			if (ndecoded >= nallocated)
-			{
-				nallocated *= 2;
-				result = repalloc_array(result, ItemPointerData, nallocated);
-			}
-
 			val += decode_varbyte(&ptr, endptr);
 
 			/*
@@ -361,6 +348,7 @@ ginPostingListDecodeAllSegments(GinPostingList *segment, int len, int *ndecoded_
 						 errmsg("corrupted GIN posting list")));
 			prev = val;
 
+			Assert(ndecoded < nallocated);
 			uint64_to_itemptr(val, &result[ndecoded]);
 			ndecoded++;
 		}
-- 
2.17.1

