Re: printf format selection vs. reality - Mailing list pgsql-hackers

From Alvaro Herrera
Subject Re: printf format selection vs. reality
Date
Msg-id 20180523201046.4znqfw52bmr6o3gr@alvherre.pgsql
Whole thread Raw
In response to Re: printf format selection vs. reality  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: printf format selection vs. reality
List pgsql-hackers
On 2018-May-23, Tom Lane wrote:

> The practical alternatives seem to be to avoid %z in frontend code,
> or to invent a macro SIZE_T_MODIFIER and use it like INT64_MODIFIER.
> Either one will be extremely error-prone, I'm afraid, unless we can
> find a way to get compiler warnings for violations.

Usage of %z outside safe-known seems really limited.  It would be sad to
force SIZE_T_MODIFIER for elog calls (where it is prevalent) just for
the benefit of usage outside of elog on fringe platforms -- you're right
that we do have a few cases of %z under fprintf() already.  The good
news is that AFAICS those strings are not translatable today, so
changing only those to SIZE_T_MODIFIER (and leaving alone those using
elog) is maybe not such a big deal.  I think those are dshash.c, dsa.c,
slab.c and aset.c only.

(I assume without checking that with the stringinfo API it's OK to use %z).

Can't we raise warnings on such usages with an archetype change?  (Hm,
is it possible to change archetype for fprintf?)

-- 
Álvaro Herrera                https://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services


pgsql-hackers by date:

Previous
From: Stephen Frost
Date:
Subject: Re: [PATCH v14] GSSAPI encryption support
Next
From: Tom Lane
Date:
Subject: Re: printf format selection vs. reality