mirror of
https://github.com/postgres/postgres.git
synced 2025-05-18 17:41:14 +03:00
Adjust PageGetMaxOffsetNumber to ensure sane behavior on uninitialized
pages, even when the macro's result is stored into an unsigned variable.
This commit is contained in:
parent
a757fd70e5
commit
1532e3a8aa
@ -7,7 +7,7 @@
|
|||||||
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
|
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
|
||||||
* Portions Copyright (c) 1994, Regents of the University of California
|
* Portions Copyright (c) 1994, Regents of the University of California
|
||||||
*
|
*
|
||||||
* $Id: bufpage.h,v 1.55 2003/08/04 02:40:14 momjian Exp $
|
* $Id: bufpage.h,v 1.55.4.1 2004/06/05 17:42:50 tgl Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -283,13 +283,14 @@ typedef PageHeaderData *PageHeader;
|
|||||||
* Since offset numbers are 1-based, this is also the number
|
* Since offset numbers are 1-based, this is also the number
|
||||||
* of items on the page.
|
* of items on the page.
|
||||||
*
|
*
|
||||||
* NOTE: to ensure sane behavior if the page is not initialized
|
* NOTE: if the page is not initialized (pd_lower == 0), we must
|
||||||
* (pd_lower == 0), cast the unsigned values to int before dividing.
|
* return zero to ensure sane behavior. Accept double evaluation
|
||||||
* That way we get -1 or so, not a huge positive number...
|
* of the argument so that we can ensure this.
|
||||||
*/
|
*/
|
||||||
#define PageGetMaxOffsetNumber(page) \
|
#define PageGetMaxOffsetNumber(page) \
|
||||||
(((int) (((PageHeader) (page))->pd_lower - SizeOfPageHeaderData)) \
|
(((PageHeader) (page))->pd_lower <= SizeOfPageHeaderData ? 0 : \
|
||||||
/ ((int) sizeof(ItemIdData)))
|
((((PageHeader) (page))->pd_lower - SizeOfPageHeaderData) \
|
||||||
|
/ sizeof(ItemIdData)))
|
||||||
|
|
||||||
#define PageGetLSN(page) \
|
#define PageGetLSN(page) \
|
||||||
(((PageHeader) (page))->pd_lsn)
|
(((PageHeader) (page))->pd_lsn)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user