fix more casting away of qualifiers

Started by Peter Eisentrautabout 6 hours ago2 messageshackers
Beta feature

Hackorum builds and tests every patch posted to the lists, not only commitfest submissions. This is Hackorum's own CI rather than the PostgreSQL project's, and it is still under testing - please report anything that looks wrong.

appliessuccessCI history

You can run a PostgreSQL built from this patch straight from Docker, with no checkout and no build:

docker run --rm -p 5432:5432 ghcr.io/hackorum-dev/postgres-patch:t253463
psql -h localhost -U postgres

Built from patchset v1 (message #1), August 18, 2026 at 09:16 AM.

Every patchset is also pushed to a branch of our PostgreSQL fork, so you can check out the same tree CI built. Without a PostgreSQL checkout:

git clone --branch t253463_1 https://github.com/hackorum-dev/postgres.git

In a checkout you already have, add the fork once:

git remote add hackorum https://github.com/hackorum-dev/postgres.git

then, for this patchset and every later one:

git fetch hackorum t253463_1 && git checkout t253463_1

Patchset v1 (message #1) is on t253463_1

Jump to latest
#1Peter Eisentraut
peter_e@gmx.net

The attached patches fix more cases where qualifiers (const, volatile)
are cast away either accidentally, or unnecessarily, or where it can be
worked around easily.

I split these into tiny bits to simplify review and to show that they
are all independent. But they could perhaps be committed all together.
(See also similar commit 3f988629805.)

I have a local WIP branch that fixes all remaining -Wcast-qual warnings.
The attached patches are the "easy" half of that. I plan to propose
addressing the other half separately later.

Attachments:

t253463_1
0001-Fix-some-Wcast-qual-warnings-fe_utils-print.c.patchtext/plain; charset=UTF-8; name=0001-Fix-some-Wcast-qual-warnings-fe_utils-print.c.patchDownload+2-3
0002-Fix-some-Wcast-qual-warnings-rangetypes.patchtext/plain; charset=UTF-8; name=0002-Fix-some-Wcast-qual-warnings-rangetypes.patchDownload+4-5
0003-Fix-some-Wcast-qual-warnings-varlena.patchtext/plain; charset=UTF-8; name=0003-Fix-some-Wcast-qual-warnings-varlena.patchDownload+12-13
0004-Fix-some-Wcast-qual-warnings-contrib-xml2.patchtext/plain; charset=UTF-8; name=0004-Fix-some-Wcast-qual-warnings-contrib-xml2.patchDownload+8-8
0005-Fix-some-Wcast-qual-warnings-postgres_fdw.patchtext/plain; charset=UTF-8; name=0005-Fix-some-Wcast-qual-warnings-postgres_fdw.patchDownload+7-5
0006-Fix-some-Wcast-qual-warnings-btree_gist.patchtext/plain; charset=UTF-8; name=0006-Fix-some-Wcast-qual-warnings-btree_gist.patchDownload+5-6
0007-Fix-some-Wcast-qual-warnings-guc_funcs.patchtext/plain; charset=UTF-8; name=0007-Fix-some-Wcast-qual-warnings-guc_funcs.patchDownload+9-2
0008-Fix-some-Wcast-qual-warnings-bufpage.patchtext/plain; charset=UTF-8; name=0008-Fix-some-Wcast-qual-warnings-bufpage.patchDownload+1-2
0009-Fix-some-Wcast-qual-warnings-test_custom_stats.patchtext/plain; charset=UTF-8; name=0009-Fix-some-Wcast-qual-warnings-test_custom_stats.patchDownload+1-2
0010-Fix-some-Wcast-qual-warnings-readline.patchtext/plain; charset=UTF-8; name=0010-Fix-some-Wcast-qual-warnings-readline.patchDownload+1-2
0011-Change-InputFunctionCall-to-take-a-const-char-str.patchtext/plain; charset=UTF-8; name=0011-Change-InputFunctionCall-to-take-a-const-char-str.patchDownload+19-20
#2Heikki Linnakangas
heikki.linnakangas@enterprisedb.com
In reply to: Peter Eisentraut (#1)
Re: fix more casting away of qualifiers

On 18/08/2026 12:04, Peter Eisentraut wrote:

The attached patches fix more cases where qualifiers (const, volatile)
are cast away either accidentally, or unnecessarily, or where it can be
worked around easily.

I split these into tiny bits to simplify review and to show that they
are all independent.  But they could perhaps be committed all together.
(See also similar commit 3f988629805.)

Thanks for the cleanups!

diff --git a/src/backend/utils/misc/guc_funcs.c b/src/backend/utils/misc/guc_funcs.c
index e2c2919484e..defaa796a0c 100644
--- a/src/backend/utils/misc/guc_funcs.c
+++ b/src/backend/utils/misc/guc_funcs.c
@@ -971,6 +971,7 @@ show_all_settings(PG_FUNCTION_ARGS)
while (call_cntr < max_calls)	/* do when there is more left to send */
{
struct config_generic *conf = guc_vars[call_cntr];
+		const char *cvalues[NUM_PG_SETTINGS_ATTS];
char	   *values[NUM_PG_SETTINGS_ATTS];
HeapTuple	tuple;
Datum		result;
@@ -984,7 +985,14 @@ show_all_settings(PG_FUNCTION_ARGS)
}
/* extract values for the current variable */
-		GetConfigOptionValues(conf, (const char **) values);
+		GetConfigOptionValues(conf, cvalues);
+
+		/*
+		 * This is so that both GetConfigOptionValues() and
+		 * BuildTupleFromCStrings() are satisfied about the const-ness without
+		 * triggering warnings.
+		 */
+		memcpy(values, cvalues, sizeof(cvalues));

/* build a tuple */
tuple = BuildTupleFromCStrings(attinmeta, values);

This seems hacky. Can we change BuildTupleFromCStrings() to take a const
instead? Maybe that was part of your "difficult half" already?

I guess that requires changing all the callers: You get a warning if
pass a "char **" to a "const char **". Is there a way with some macro
magic or something that you could accept both?

All else look good to me at a quick glance.

- Heikki