From 2dab9fee061dd0cedbfc44caab8d31fb485c4f7a Mon Sep 17 00:00:00 2001
From: Sehrope Sarkuni <sehrope@jackdb.com>
Date: Sat, 26 Sep 2026 19:15:05 +0000
Subject: [PATCH v1 7/7] gin: scope decode locals to the segment loop

val, ptr and endptr live only within one iteration of the segment loop, like
prev.  Declare them there rather than at the top of the function.
---
 src/backend/access/gin/ginpostinglist.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/backend/access/gin/ginpostinglist.c b/src/backend/access/gin/ginpostinglist.c
index 57c16eb05cb..4aeeb8c4eef 100644
--- a/src/backend/access/gin/ginpostinglist.c
+++ b/src/backend/access/gin/ginpostinglist.c
@@ -272,11 +272,8 @@ ginPostingListDecodeAllSegments(GinPostingList *segment, int len, int *ndecoded_
 {
 	ItemPointer result;
 	int			nallocated;
-	uint64		val;
 	char	   *endseg = ((char *) segment) + len;
 	int			ndecoded;
-	unsigned char *ptr;
-	unsigned char *endptr;
 
 	/*
 	 * Size from len, not segment->nbytes.  len can be smaller than a segment
@@ -291,7 +288,10 @@ ginPostingListDecodeAllSegments(GinPostingList *segment, int len, int *ndecoded_
 	while ((char *) segment < endseg)
 	{
 		OffsetNumber firstoff;
+		uint64		val;
 		uint64		prev;
+		unsigned char *ptr;
+		unsigned char *endptr;
 
 		/*
 		 * Reject a segment that runs past the end of the posting list.
-- 
2.17.1

