]> git.ipfire.org Git - thirdparty/postgresql.git/commit
Fix some cases of indirectly casting away const.
authorTom Lane <tgl@sss.pgh.pa.us>
Wed, 25 Feb 2026 16:19:50 +0000 (11:19 -0500)
committerTom Lane <tgl@sss.pgh.pa.us>
Wed, 25 Feb 2026 16:19:50 +0000 (11:19 -0500)
commit244c047205bb770f877ea525ea8bd7cd3cdad076
tree73d9daa57c9e5b7f9fa244799f71ec9a0663c75f
parent5d311d6a845ae4423a716ae422f1462128c33125
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 <tgl@sss.pgh.pa.us>
Reviewed-by: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
Discussion: https://postgr.es/m/1324889.1764886170@sss.pgh.pa.us
Discussion: https://postgr.es/m/3988414.1771950285@sss.pgh.pa.us
Backpatch-through: 14-18
13 files changed:
src/backend/catalog/pg_type.c
src/backend/tsearch/spell.c
src/backend/utils/adt/formatting.c
src/backend/utils/adt/pg_locale.c
src/backend/utils/adt/xid8funcs.c
src/bin/pg_waldump/pg_waldump.c
src/bin/pgbench/pgbench.c
src/interfaces/ecpg/pgtypeslib/datetime.c
src/port/getopt.c
src/port/getopt_long.c
src/port/win32setlocale.c
src/test/regress/pg_regress.c
src/timezone/zic.c