aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/include/storage/bufpage.h13
1 files changed, 7 insertions, 6 deletions
diff --git a/src/include/storage/bufpage.h b/src/include/storage/bufpage.h
index 5dbabb31684..5f8012e0ed6 100644
--- a/src/include/storage/bufpage.h
+++ b/src/include/storage/bufpage.h
@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/include/storage/bufpage.h,v 1.57 2003/12/11 21:21:55 tgl Exp $
+ * $PostgreSQL: pgsql/src/include/storage/bufpage.h,v 1.58 2004/06/05 17:42:46 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -283,13 +283,14 @@ typedef PageHeaderData *PageHeader;
* Since offset numbers are 1-based, this is also the number
* of items on the page.
*
- * NOTE: to ensure sane behavior if the page is not initialized
- * (pd_lower == 0), cast the unsigned values to int before dividing.
- * That way we get -1 or so, not a huge positive number...
+ * NOTE: if the page is not initialized (pd_lower == 0), we must
+ * return zero to ensure sane behavior. Accept double evaluation
+ * of the argument so that we can ensure this.
*/
#define PageGetMaxOffsetNumber(page) \
- (((int) (((PageHeader) (page))->pd_lower - SizeOfPageHeaderData)) \
- / ((int) sizeof(ItemIdData)))
+ (((PageHeader) (page))->pd_lower <= SizeOfPageHeaderData ? 0 : \
+ ((((PageHeader) (page))->pd_lower - SizeOfPageHeaderData) \
+ / sizeof(ItemIdData)))
#define PageGetLSN(page) \
(((PageHeader) (page))->pd_lsn)