Re: [PATCH] add relation and block-level filtering to pg_waldump - Mailing list pgsql-hackers

From Thomas Munro
Subject Re: [PATCH] add relation and block-level filtering to pg_waldump
Date
Msg-id CA+hUKGLGS8mJuTxNPVMqEg2Whr6Gg3OSMuWaZYhws1HmQHLQ-A@mail.gmail.com
Whole thread Raw
In response to Re: [PATCH] add relation and block-level filtering to pg_waldump  (Peter Eisentraut <peter.eisentraut@enterprisedb.com>)
Responses Re: [PATCH] add relation and block-level filtering to pg_waldump  (Andres Freund <andres@anarazel.de>)
Re: [PATCH] add relation and block-level filtering to pg_waldump  (Peter Eisentraut <peter.eisentraut@enterprisedb.com>)
List pgsql-hackers
On Thu, Mar 24, 2022 at 9:53 AM Peter Eisentraut
<peter.eisentraut@enterprisedb.com> wrote:
> On 21.03.22 05:55, Thomas Munro wrote:
> > [04:30:50.630] pg_waldump.c:963:26: error: format ‘%u’ expects
> > argument of type ‘unsigned int *’, but argument 3 has type ‘ForkNumber
> > *’ [-Werror=format=]
> > [04:30:50.630] 963 | if (sscanf(optarg, "%u",
> > &config.filter_by_relation_forknum) != 1 ||
> > [04:30:50.630] | ~^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> > [04:30:50.630] | | |
> > [04:30:50.630] | | ForkNumber *
> > [04:30:50.630] | unsigned int *
> >
> > And now that this gets to the CompilerWarnings CI task, it looks like
> > GCC doesn't like an enum as a scanf %u destination (I didn't see that
> > warning locally when I compiled the above fixup because clearly Clang
> > is cool with it...).  Probably needs a temporary unsigned int to
> > sscanf into first.
>
> That's because ForkNum is a signed type.  You will probably succeed if
> you use "%d" instead.

Erm, is that really OK?  C says "Each enumerated type shall be
compatible with char, a signed integer type, or an
unsigned integer type. The choice of type is implementation-defined,
but shall be capable of representing the values of all the members of
the enumeration."  It could even legally vary from enum to enum,
though in practice most compilers probably just use ints all the time
unless you use weird pragma pack incantation.  Therefore I think you
need an intermediate variable with the size and signedness matching the
format string, if you're going to scanf directly into it, which
David's V6 did.



pgsql-hackers by date:

Previous
From: Jacob Champion
Date:
Subject: Re: [PATCH] Expose port->authn_id to extensions and triggers
Next
From: Andres Freund
Date:
Subject: Re: ubsan