RE: Use correct macro for accessing offset numbers. - Mailing list pgsql-hackers

From li carol
Subject RE: Use correct macro for accessing offset numbers.
Date
Msg-id TYSPR01MB6650128F7CCEBE1C809AE51E8181A@TYSPR01MB6650.apcprd01.prod.exchangelabs.com
Whole thread Raw
In response to Re: Use correct macro for accessing offset numbers.  (Michael Paquier <michael@paquier.xyz>)
Responses Re: Use correct macro for accessing offset numbers.
List pgsql-hackers
>
> On Sun, Jan 11, 2026 at 04:58:39PM +0500, Kirill Reshke wrote:
> > Maybe, I have stopped some more cases, in v2-0001
>
> Right.  It's true that we could be more consistent for all these based on their
> base type, some of them, particularly in the GIN code now, caring about using
> the correct macro.  It may be a good occasion to double-check the whole tree
> for similar holes based on unsigned types.
> --
> Michael

Hi Kirill, Roman, and Michael,
While double-checking the tree for similar holes as Michael suggested, I noticed a couple more inconsistencies in
contrib/pageinspect/ginfuncs.cwhere we are using signed macros for unsigned types. 
Specifically, in gin_page_opaque_info, we use Int32GetDatum for maxoff:

values[1] = Int32GetDatum(opaq->maxoff);

Since maxoff is of type OffsetNumber (uint16), this seems to be the exact same pattern Kirill is addressing in other
partsof the GIN code. Although it is widened to int32 here, for the sake of consistency, it should probably be using a
16-bitor unsigned macro. 

Similarly, in gin_metapage_info, tailFreeSize (which is defined as uint32 in GinMetaPageData) is also converted using
Int32GetDatum:

values[2] = Int32GetDatum(metadata->tailFreeSize);

It might be better to include these cleanups in the next version of the patch to ensure all pageinspect GIN functions
followthe same standard. 

Best regards,
Yuan Li(carol)




pgsql-hackers by date:

Previous
From: Peter Smith
Date:
Subject: Re: Proposal: Conflict log history table for Logical Replication
Next
From: Tatsuro Yamada
Date:
Subject: Re: [PATCH] psql: add \dcs to list all constraints