From 8b0438045bbff5b665e65c4d1cf73b5da7d0d955 Mon Sep 17 00:00:00 2001
From: Tomas Vondra <tomas@vondra.me>
Date: Mon, 7 Apr 2025 21:33:20 +0200
Subject: [PATCH v29 4/4] fixup

---
 contrib/pg_buffercache/pg_buffercache_pages.c | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/contrib/pg_buffercache/pg_buffercache_pages.c b/contrib/pg_buffercache/pg_buffercache_pages.c
index b9fdf87bcc4..a702a47efe9 100644
--- a/contrib/pg_buffercache/pg_buffercache_pages.c
+++ b/contrib/pg_buffercache/pg_buffercache_pages.c
@@ -307,8 +307,8 @@ pg_buffercache_numa_pages(PG_FUNCTION_ARGS)
 	{
 		int			i,
 					idx;
-		Size		os_page_size = 0;
-		void	  **os_page_ptrs = NULL;
+		Size		os_page_size;
+		void	  **os_page_ptrs;
 		int		   *os_page_status;
 		uint64		os_page_count;
 		int			pages_per_buffer;
@@ -352,8 +352,8 @@ pg_buffercache_numa_pages(PG_FUNCTION_ARGS)
 		 */
 		startptr = (char *) TYPEALIGN_DOWN(os_page_size,
 										   BufferGetBlock(1));
-		endptr = (char *) TYPEALIGN_DOWN(os_page_size,
-										 (char *) BufferGetBlock(NBuffers) + BLCKSZ);
+		endptr = (char *) TYPEALIGN(os_page_size,
+									(char *) BufferGetBlock(NBuffers) + BLCKSZ);
 		os_page_count = (endptr - startptr) / os_page_size;
 
 		/* Used to determine the NUMA node for all OS pages at once */
@@ -470,8 +470,10 @@ pg_buffercache_numa_pages(PG_FUNCTION_ARGS)
 			/* start of the first page of this buffer */
 			startptr_buff = (char *) TYPEALIGN_DOWN(os_page_size, buffptr);
 
-			/* start of the page right after this buffer */
-			endptr_buff = (char *) TYPEALIGN_DOWN(os_page_size, buffptr + BLCKSZ);
+			/* end of the buffer (no need to align to memory page) */
+			endptr_buff = buffptr + BLCKSZ;
+
+			Assert(startptr_buff < endptr_buff);
 
 			/* calculate ID of the first page for this buffer */
 			page_num = (startptr_buff - startptr) / os_page_size;
-- 
2.49.0

