From 78c228dda68cada702d67f433eb92583f3298933 Mon Sep 17 00:00:00 2001 From: "Chao Li (Evan)" Date: Wed, 29 Oct 2025 10:27:44 +0800 Subject: [PATCH v1] Fix incorrect const qualification for tbm_add_tuples() and itemptr_to_uint64() The parameters in tbm_add_tuples() and itemptr_to_uint64() were declared as "const ItemPointer tids", which incorrectly applies const to the pointer itself rather than to the data it points to. As a result, the contents referenced by "tids" were not protected from modification, defeating the intended use of const. Change these parameters to "const ItemPointerData *" so that the pointed- to data are correctly treated as read-only. Author: Chao Li --- src/backend/access/gin/ginpostinglist.c | 2 +- src/backend/nodes/tidbitmap.c | 5 ++--- src/include/nodes/tidbitmap.h | 2 +- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/backend/access/gin/ginpostinglist.c b/src/backend/access/gin/ginpostinglist.c index 48eadec87b0..6d8c8edc490 100644 --- a/src/backend/access/gin/ginpostinglist.c +++ b/src/backend/access/gin/ginpostinglist.c @@ -84,7 +84,7 @@ #define MaxBytesPerInteger 7 static inline uint64 -itemptr_to_uint64(const ItemPointer iptr) +itemptr_to_uint64(const ItemPointerData *iptr) { uint64 val; diff --git a/src/backend/nodes/tidbitmap.c b/src/backend/nodes/tidbitmap.c index fac2ba5d0ca..57286863df0 100644 --- a/src/backend/nodes/tidbitmap.c +++ b/src/backend/nodes/tidbitmap.c @@ -364,15 +364,14 @@ tbm_free_shared_area(dsa_area *dsa, dsa_pointer dp) * TBMIterateResult when any of these tuples are reported out. */ void -tbm_add_tuples(TIDBitmap *tbm, const ItemPointer tids, int ntids, +tbm_add_tuples(TIDBitmap *tbm, const ItemPointerData *tids, int ntids, bool recheck) { BlockNumber currblk = InvalidBlockNumber; PagetableEntry *page = NULL; /* only valid when currblk is valid */ - int i; Assert(tbm->iterating == TBM_NOT_ITERATING); - for (i = 0; i < ntids; i++) + for (int i = 0; i < ntids; i++) { BlockNumber blk = ItemPointerGetBlockNumber(tids + i); OffsetNumber off = ItemPointerGetOffsetNumber(tids + i); diff --git a/src/include/nodes/tidbitmap.h b/src/include/nodes/tidbitmap.h index f54e61c7190..c24997d1c40 100644 --- a/src/include/nodes/tidbitmap.h +++ b/src/include/nodes/tidbitmap.h @@ -85,7 +85,7 @@ extern void tbm_free(TIDBitmap *tbm); extern void tbm_free_shared_area(dsa_area *dsa, dsa_pointer dp); extern void tbm_add_tuples(TIDBitmap *tbm, - const ItemPointer tids, int ntids, + const ItemPointerData *tids, int ntids, bool recheck); extern void tbm_add_page(TIDBitmap *tbm, BlockNumber pageno); -- 2.39.5 (Apple Git-154)