Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit24a1e20

Browse files
committed
Adjust PageGetMaxOffsetNumber to ensure sane behavior on uninitialized
pages, even when the macro's result is stored into an unsigned variable.
1 parent641c5b5 commit24a1e20

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

‎src/include/storage/bufpage.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $PostgreSQL: pgsql/src/include/storage/bufpage.h,v 1.57 2003/12/11 21:21:55 tgl Exp $
10+
* $PostgreSQL: pgsql/src/include/storage/bufpage.h,v 1.58 2004/06/05 17:42:46 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -283,13 +283,14 @@ typedef PageHeaderData *PageHeader;
283283
*Since offset numbers are 1-based, this is also the number
284284
*of items on the page.
285285
*
286-
*NOTE:to ensure sane behaviorif the page is not initialized
287-
*(pd_lower == 0), cast the unsigned values to int before dividing.
288-
*That way we get -1 or so, not a huge positive number...
286+
*NOTE: if the page is not initialized (pd_lower == 0), we must
287+
*return zero to ensure sane behavior. Accept double evaluation
288+
*of the argument so that we can ensure this.
289289
*/
290290
#definePageGetMaxOffsetNumber(page) \
291-
(((int) (((PageHeader) (page))->pd_lower - SizeOfPageHeaderData)) \
292-
/ ((int) sizeof(ItemIdData)))
291+
(((PageHeader) (page))->pd_lower <= SizeOfPageHeaderData ? 0 : \
292+
((((PageHeader) (page))->pd_lower - SizeOfPageHeaderData) \
293+
/ sizeof(ItemIdData)))
293294

294295
#definePageGetLSN(page) \
295296
(((PageHeader) (page))->pd_lsn)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp