pgsql: Suppress compiler warnings in new pgstats code.

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Suppress compiler warnings in new pgstats code.
Date: 2023-02-27 22:21:37
Message-ID: E1pWlsH-00128s-0z@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Suppress compiler warnings in new pgstats code.

Some clang versions whine about comparing an enum variable to
a value outside the range of the enum, on the grounds that the
result must be constant. In the cases we fix here, the loops
will terminate only if the enum variable can in fact hold a
value one beyond its declared range. While that's very likely
to always be true for these enum types, it still seems like a
poor coding practice to assume it; so use "int" loop variables
instead to silence the warnings. (This matches what we've done
in other places, for example loops over the range of ForkNumber.)

While at it, let's drop the XXX_FIRST macros for these enums and just
write zeroes for the loop start values. The apparent flexibility
seems rather illusory given that iterating up to one-less-than-
the-number-of-values is only correct for a zero-based range.

Melanie Plageman

Discussion: https://postgr.es/m/20520.1677435600@sss.pgh.pa.us

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/728560db7d868b3ded9a8675742083ab89bcff7c

Modified Files
--------------
src/backend/utils/activity/pgstat_io.c | 17 ++++++-----------
src/backend/utils/adt/pgstatfuncs.c | 10 ++++------
src/include/pgstat.h | 3 ---
3 files changed, 10 insertions(+), 20 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Michael Paquier 2023-02-27 23:08:48 pgsql: Rework pg_input_error_message(), now renamed pg_input_error_info
Previous Message Tom Lane 2023-02-27 21:30:04 pgsql: Harden postgres_fdw tests against unexpected cache flushes.