Skip to content

Commit dc0a208

Browse files
committed
Fix off-by-one Asserts in FreePageBtreeInsertInternal/Leaf.
These two functions expect there to be room to insert another item in the FreePageBtree's array, but their assertions were too weak to guarantee that. This has little practical effect granting that the callers are not buggy, but it seems to be misleading late-model Coverity into complaining about possible array overrun. Author: Tom Lane <tgl@sss.pgh.pa.us> Discussion: https://postgr.es/m/799984.1761150474@sss.pgh.pa.us Backpatch-through: 13
1 parent d90c92d commit dc0a208

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/backend/utils/mmgr/freepage.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -894,14 +894,14 @@ FreePageBtreeGetRecycled(FreePageManager *fpm)
894894
}
895895

896896
/*
897-
* Insert an item into an internal page.
897+
* Insert an item into an internal page (there must be room).
898898
*/
899899
static void
900900
FreePageBtreeInsertInternal(char *base, FreePageBtree *btp, Size index,
901901
Size first_page, FreePageBtree *child)
902902
{
903903
Assert(btp->hdr.magic == FREE_PAGE_INTERNAL_MAGIC);
904-
Assert(btp->hdr.nused <= FPM_ITEMS_PER_INTERNAL_PAGE);
904+
Assert(btp->hdr.nused < FPM_ITEMS_PER_INTERNAL_PAGE);
905905
Assert(index <= btp->hdr.nused);
906906
memmove(&btp->u.internal_key[index + 1], &btp->u.internal_key[index],
907907
sizeof(FreePageBtreeInternalKey) * (btp->hdr.nused - index));
@@ -911,14 +911,14 @@ FreePageBtreeInsertInternal(char *base, FreePageBtree *btp, Size index,
911911
}
912912

913913
/*
914-
* Insert an item into a leaf page.
914+
* Insert an item into a leaf page (there must be room).
915915
*/
916916
static void
917917
FreePageBtreeInsertLeaf(FreePageBtree *btp, Size index, Size first_page,
918918
Size npages)
919919
{
920920
Assert(btp->hdr.magic == FREE_PAGE_LEAF_MAGIC);
921-
Assert(btp->hdr.nused <= FPM_ITEMS_PER_LEAF_PAGE);
921+
Assert(btp->hdr.nused < FPM_ITEMS_PER_LEAF_PAGE);
922922
Assert(index <= btp->hdr.nused);
923923
memmove(&btp->u.leaf_key[index + 1], &btp->u.leaf_key[index],
924924
sizeof(FreePageBtreeLeafKey) * (btp->hdr.nused - index));

0 commit comments

Comments
 (0)