Skip to content

Commit 93624bc

Browse files
committed
Fix CHECK_RELATION_BLOCK_RANGE macro, which was not merely producing
a warning but was outright wrong.
1 parent 4608f35 commit 93624bc

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

contrib/pageinspect/btreefuncs.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,13 @@ extern Datum bt_page_stats(PG_FUNCTION_ARGS);
5757
#define IS_BTREE(r) ((r)->rd_rel->relam == BTREE_AM_OID)
5858

5959
#define CHECK_PAGE_OFFSET_RANGE(pg, offnum) { \
60-
if ( !(FirstOffsetNumber<=(offnum) && \
61-
(offnum)<=PageGetMaxOffsetNumber(pg)) ) \
60+
if ( !(FirstOffsetNumber <= (offnum) && \
61+
(offnum) <= PageGetMaxOffsetNumber(pg)) ) \
6262
elog(ERROR, "page offset number out of range"); }
6363

64+
/* note: BlockNumber is unsigned, hence can't be negative */
6465
#define CHECK_RELATION_BLOCK_RANGE(rel, blkno) { \
65-
if ( (blkno)<0 && RelationGetNumberOfBlocks((rel))<=(blkno) ) \
66+
if ( RelationGetNumberOfBlocks(rel) <= (BlockNumber) (blkno) ) \
6667
elog(ERROR, "block number out of range"); }
6768

6869
/* ------------------------------------------------

contrib/pgstattuple/pgstatindex.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,13 @@ extern Datum pg_relpages(PG_FUNCTION_ARGS);
4848
#define IS_BTREE(r) ((r)->rd_rel->relam == BTREE_AM_OID)
4949

5050
#define CHECK_PAGE_OFFSET_RANGE(pg, offnum) { \
51-
if ( !(FirstOffsetNumber<=(offnum) && \
52-
(offnum)<=PageGetMaxOffsetNumber(pg)) ) \
51+
if ( !(FirstOffsetNumber <= (offnum) && \
52+
(offnum) <= PageGetMaxOffsetNumber(pg)) ) \
5353
elog(ERROR, "page offset number out of range"); }
5454

55+
/* note: BlockNumber is unsigned, hence can't be negative */
5556
#define CHECK_RELATION_BLOCK_RANGE(rel, blkno) { \
56-
if ( (blkno)<0 && RelationGetNumberOfBlocks((rel))<=(blkno) ) \
57+
if ( RelationGetNumberOfBlocks(rel) <= (BlockNumber) (blkno) ) \
5758
elog(ERROR, "block number out of range"); }
5859

5960
/* ------------------------------------------------

0 commit comments

Comments
 (0)