pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
pgsql: Fix some cases of indirectly casting away const.
6+ messages / 1 participants
[nested] [flat]

* pgsql: Fix some cases of indirectly casting away const.
@ 2025-12-05 16:17 Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 6+ messages in thread

From: Tom Lane @ 2025-12-05 16:17 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

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(-)



^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* pgsql: Fix some cases of indirectly casting away const.
@ 2026-02-25 16:20 Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 6+ messages in thread

From: Tom Lane @ 2026-02-25 16:20 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

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

Branch
------
REL_18_STABLE

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

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/common/compression.c                  | 2 +-
src/interfaces/ecpg/pgtypeslib/datetime.c | 4 ++--
src/interfaces/ecpg/preproc/ecpg.trailer  | 2 +-
src/interfaces/ecpg/preproc/variable.c    | 2 +-
src/port/chklocale.c                      | 2 +-
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 +-
17 files changed, 23 insertions(+), 22 deletions(-)



^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* pgsql: Fix some cases of indirectly casting away const.
@ 2026-02-25 16:20 Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 6+ messages in thread

From: Tom Lane @ 2026-02-25 16:20 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

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

Branch
------
REL_17_STABLE

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

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/common/compression.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 +-
14 files changed, 20 insertions(+), 19 deletions(-)



^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* pgsql: Fix some cases of indirectly casting away const.
@ 2026-02-25 16:20 Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 6+ messages in thread

From: Tom Lane @ 2026-02-25 16:20 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

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

Branch
------
REL_16_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/0969bfd0db869a31e341ad17bbef32532f6315fc

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/common/compression.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 +-
14 files changed, 20 insertions(+), 19 deletions(-)



^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* pgsql: Fix some cases of indirectly casting away const.
@ 2026-02-25 16:20 Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 6+ messages in thread

From: Tom Lane @ 2026-02-25 16:20 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

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

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(-)



^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* pgsql: Fix some cases of indirectly casting away const.
@ 2026-02-25 16:20 Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 6+ messages in thread

From: Tom Lane @ 2026-02-25 16:20 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

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

Branch
------
REL_14_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/244c047205bb770f877ea525ea8bd7cd3cdad076

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(-)



^ permalink  raw  reply  [nested|flat] 6+ messages in thread


end of thread, other threads:[~2026-02-25 16:20 UTC | newest]

Thread overview: 6+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2025-12-05 16:17 pgsql: Fix some cases of indirectly casting away const. Tom Lane <tgl@sss.pgh.pa.us>
2026-02-25 16:20 pgsql: Fix some cases of indirectly casting away const. Tom Lane <tgl@sss.pgh.pa.us>
2026-02-25 16:20 pgsql: Fix some cases of indirectly casting away const. Tom Lane <tgl@sss.pgh.pa.us>
2026-02-25 16:20 pgsql: Fix some cases of indirectly casting away const. Tom Lane <tgl@sss.pgh.pa.us>
2026-02-25 16:20 pgsql: Fix some cases of indirectly casting away const. Tom Lane <tgl@sss.pgh.pa.us>
2026-02-25 16:20 pgsql: Fix some cases of indirectly casting away const. Tom Lane <tgl@sss.pgh.pa.us>

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