pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Fix some cases of indirectly casting away const.
Date: Fri, 05 Dec 2025 16:17:38 +0000
Message-ID: <E1vRYV0-002xeT-1T@gemulon.postgresql.org> (raw)

Fix some cases of indirectly casting away const.

Newest versions of gcc are able to detect cases where code implicitly
casts away const by assigning the result of strchr() or a similar
function applied to a "const char *" value to a target variable
that's just "char *".  This of course creates a hazard of not getting
a compiler warning about scribbling on a string one was not supposed
to, so fixing up such cases is good.

This patch fixes a dozen or so places where we were doing that.
Most are trivial additions of "const" to the target variable,
since no actually-hazardous change was occurring.  There is one
place in ecpg.trailer where we were indeed violating the intention
of not modifying a string passed in as "const char *".  I believe
that's harmless not a live bug, but let's fix it by copying the
string before modifying it.

There is a remaining trouble spot in ecpg/preproc/variable.c,
which requires more complex surgery.  I've left that out of this
commit because I want to study that code a bit more first.

We probably will want to back-patch this once compilers that detect
this pattern get into wider circulation, but for now I'm just
going to apply it to master to see what the buildfarm says.

Thanks to Bertrand Drouvot for finding a couple more spots than
I had.

Author: Tom Lane <tgl@sss.pgh.pa.us>
Reviewed-by: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
Discussion: https://postgr.es/m/1324889.1764886170@sss.pgh.pa.us

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/8f1791c61836d213acbf85d368c8762705ad9d51

Modified Files
--------------
src/backend/catalog/pg_type.c             |  2 +-
src/backend/tsearch/spell.c               |  2 +-
src/backend/utils/adt/formatting.c        | 11 ++++++-----
src/backend/utils/adt/pg_locale.c         |  2 +-
src/backend/utils/adt/xid8funcs.c         |  2 +-
src/bin/pg_waldump/pg_waldump.c           |  2 +-
src/bin/pgbench/pgbench.c                 |  2 +-
src/common/compression.c                  |  2 +-
src/interfaces/ecpg/pgtypeslib/datetime.c |  4 ++--
src/interfaces/ecpg/preproc/ecpg.trailer  |  6 ++++--
src/port/chklocale.c                      |  2 +-
src/port/getopt_long.c                    |  2 +-
src/port/win32setlocale.c                 |  8 ++++----
src/test/regress/pg_regress.c             |  2 +-
src/timezone/zic.c                        |  2 +-
15 files changed, 27 insertions(+), 24 deletions(-)



view thread (6+ messages)  latest in thread

Message-ID: <E1vRYV0-002xeT-1T@gemulon.postgresql.org>
Permalink:  ../E1vRYV0-002xeT-1T@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1vRYV0-002xeT-1T@gemulon.postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-committers@postgresql.org
  Cc: tgl@sss.pgh.pa.us, pgsql-committers@lists.postgresql.org
  Subject: Re: pgsql: Fix some cases of indirectly casting away const.
  In-Reply-To: <E1vRYV0-002xeT-1T@gemulon.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox