Fix relptr's encoding of the base address.
authorThomas Munro <tmunro@postgresql.org>
Sun, 26 Jun 2022 22:30:15 +0000 (10:30 +1200)
committerThomas Munro <tmunro@postgresql.org>
Sun, 26 Jun 2022 23:45:03 +0000 (11:45 +1200)
commit99504ff8265eac35da5af06f4ce99196bbdc0239
treec97562d6d6cf885e4f3697cf97a9868bba96f0fe
parente086b55381a98975348051d218cff0752c19d0f9
Fix relptr's encoding of the base address.

Previously, we encoded both NULL and the first byte at the base address
as 0.  That confusion led to the assertion in commit e07d4ddc, which
failed when min_dynamic_shared_memory was used.  Give them distinct
encodings, by switching to 1-based offsets for non-NULL pointers.  Also
improve macro hygiene in passing (missing/misplaced parentheses), and
remove open-coded access to the raw offset value from freepage.c/h.

Although e07d4ddc was back-patched to 10, the only code that actually
makes use of relptr at the base address arrived in 84b1c63a, so no need
to back-patch further than 14 for now.

Reported-by: Justin Pryzby <pryzby@telsasoft.com>
Reviewed-by: Robert Haas <robertmhaas@gmail.com>
Discussion: http://postgr.es/m/20220519193839.GT19626%40telsasoft.com
src/backend/utils/mmgr/freepage.c
src/include/utils/freepage.h
src/include/utils/relptr.h