public inbox for [email protected]  
help / color / mirror / Atom feed
From: Tom Lane <[email protected]>
To: [email protected]
Subject: pgsql: Fix some cases of indirectly casting away const.
Date: Wed, 25 Feb 2026 16:20:05 +0000
Message-ID: <[email protected]> (raw)

Fix some cases of indirectly casting away const.

Newest versions of gcc+glibc 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.

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

This commit back-patches relevant portions of 8f1791c61 and
9f7565c6c into supported branches.  However, there are two
places in ecpg (in v18 only) where a proper fix is more
complicated than seems appropriate for a back-patch.  I opted
to silence those two warnings by adding casts.

Author: Tom Lane <[email protected]>
Reviewed-by: Bertrand Drouvot <[email protected]>
Discussion: https://postgr.es/m/[email protected]
Discussion: https://postgr.es/m/[email protected]
Backpatch-through: 14-18

Branch
------
REL_15_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/cc9c22a5160a260551a0316078bef55954ba7e9a

Modified Files
--------------
src/backend/catalog/pg_type.c             | 2 +-
src/backend/tsearch/spell.c               | 2 +-
src/backend/utils/adt/formatting.c        | 5 +++--
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/interfaces/ecpg/pgtypeslib/datetime.c | 4 ++--
src/port/getopt.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 +-
13 files changed, 19 insertions(+), 18 deletions(-)



view thread (5+ messages)  latest in thread

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: [email protected]
  Cc: [email protected], [email protected]
  Subject: Re: pgsql: Fix some cases of indirectly casting away const.
  In-Reply-To: <[email protected]>

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

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