Subject: [PATCH v1 2/5] Replace literal 0 with InvalidOffsetNumber for OffsetNumber assignments

From: Bertrand Drouvot <[email-masked]>
Date: Thu, 12 Feb 2026 09:12:17 +0000

Use the proper constant InvalidOffsetNumber instead of literal 0 when
assigning OffsetNumber variables and struct fields.

This improves code clarity by making it explicit that these are
invalid OffsetNumber values rather than ambiguous zero literals.

Author: Bertrand Drouvot <[email-masked]>
Discussion:
---
 src/backend/access/gin/ginfast.c      | 4 ++--
 src/backend/access/gin/ginget.c       | 2 +-
 src/backend/access/gin/gininsert.c    | 2 +-
 src/backend/access/gin/ginxlog.c      | 2 +-
 src/backend/access/nbtree/nbtsearch.c | 2 +-
 src/backend/storage/page/itemptr.c    | 2 +-
 6 files changed, 7 insertions(+), 7 deletions(-)
  71.7% src/backend/access/gin/
  19.8% src/backend/access/nbtree/
   8.4% src/backend/storage/page/

diff --git a/src/backend/access/gin/ginfast.c b/src/backend/access/gin/ginfast.c
index 7a6b177977b..dde0f534613 100644
--- a/src/backend/access/gin/ginfast.c
+++ b/src/backend/access/gin/ginfast.c
@@ -108,7 +108,7 @@ writeListPage(Relation index, Buffer buffer,
 	}
 	else
 	{
-		GinPageGetOpaque(page)->maxoff = 0;
+		GinPageGetOpaque(page)->maxoff = InvalidOffsetNumber;
 	}
 
 	MarkBufferDirty(buffer);
@@ -720,7 +720,7 @@ processPendingPage(BuildAccumulator *accum, KeyArray *ka,
 	maxoff = PageGetMaxOffsetNumber(page);
 	Assert(maxoff >= FirstOffsetNumber);
 	ItemPointerSetInvalid(&heapptr);
-	attrnum = 0;
+	attrnum = InvalidOffsetNumber;
 
 	for (i = startoff; i <= maxoff; i = OffsetNumberNext(i))
 	{
diff --git a/src/backend/access/gin/ginget.c b/src/backend/access/gin/ginget.c
index 6b148e69a8e..9f4be6d2be3 100644
--- a/src/backend/access/gin/ginget.c
+++ b/src/backend/access/gin/ginget.c
@@ -859,7 +859,7 @@ entryGetItem(GinState *ginstate, GinScanEntry entry,
 				 * matchResult is lossy.  So, on next call we will get next
 				 * result from TIDBitmap.
 				 */
-				entry->offset = 0;
+				entry->offset = InvalidOffsetNumber;
 			}
 			if (entry->isFinished)
 				break;
diff --git a/src/backend/access/gin/gininsert.c b/src/backend/access/gin/gininsert.c
index 0d63fb4ba27..ae9a8736a8f 100644
--- a/src/backend/access/gin/gininsert.c
+++ b/src/backend/access/gin/gininsert.c
@@ -1562,7 +1562,7 @@ GinBufferReset(GinBuffer *buffer)
 	 */
 	buffer->key = (Datum) 0;
 
-	buffer->attnum = 0;
+	buffer->attnum = InvalidOffsetNumber;
 	buffer->category = 0;
 	buffer->keylen = 0;
 	buffer->nitems = 0;
diff --git a/src/backend/access/gin/ginxlog.c b/src/backend/access/gin/ginxlog.c
index b1fee3c281f..5d24862405c 100644
--- a/src/backend/access/gin/ginxlog.c
+++ b/src/backend/access/gin/ginxlog.c
@@ -643,7 +643,7 @@ ginRedoInsertListPage(XLogReaderState *record)
 	}
 	else
 	{
-		GinPageGetOpaque(page)->maxoff = 0;
+		GinPageGetOpaque(page)->maxoff = InvalidOffsetNumber;
 	}
 
 	payload = XLogRecGetBlockData(record, 0, &totaltupsize);
diff --git a/src/backend/access/nbtree/nbtsearch.c b/src/backend/access/nbtree/nbtsearch.c
index 32ae0bda892..3711efb97e0 100644
--- a/src/backend/access/nbtree/nbtsearch.c
+++ b/src/backend/access/nbtree/nbtsearch.c
@@ -2223,7 +2223,7 @@ _bt_endpoint(IndexScanDesc scan, ScanDirection dir)
 	else
 	{
 		elog(ERROR, "invalid scan direction: %d", (int) dir);
-		start = 0;				/* keep compiler quiet */
+		start = InvalidOffsetNumber;	/* keep compiler quiet */
 	}
 
 	/*
diff --git a/src/backend/storage/page/itemptr.c b/src/backend/storage/page/itemptr.c
index 546874ebc5f..4843ac84f01 100644
--- a/src/backend/storage/page/itemptr.c
+++ b/src/backend/storage/page/itemptr.c
@@ -90,7 +90,7 @@ ItemPointerInc(ItemPointer pointer)
 	{
 		if (blk != InvalidBlockNumber)
 		{
-			off = 0;
+			off = InvalidOffsetNumber;
 			blk++;
 		}
 	}
-- 
2.34.1

--A7qqtM/5Ou92K2X7
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
	filename="v1-0003-Replace-literal-0-with-InvalidAttrNumber-for-Attr.patch"