More const-marking cleanup

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: More const-marking cleanup
Date: 2025-12-04 22:09:30
Message-ID: 1324889.1764886170@sss.pgh.pa.us
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

I noticed that our two buildfarm animals that are running Fedora
rawhide (caiman, midge) are emitting warnings like

compression.c: In function "parse_compress_options":
compression.c:458:13: warning: assignment discards "const" qualifier from pointer target type [-Wdiscarded-qualifiers]
458 | sep = strchr(option, ':');
| ^

Apparently, latest gcc is able to notice that constructions like

const char *str = ...;
char *ptr = strchr(str, ':');

are effectively casting away const. This is a good thing and long
overdue, but we have some work to do to clean up the places where
we are doing that.

Attached is a patch that cleans up all the cases I saw on a local
rawhide installation. Most of it is unremarkable, but the changes
in ecpg are less so. In particular, variable.c is a mess, because
somebody const-ified some of the char* arguments to find_struct()
and find_struct_member() without regard for the fact that all their
char* arguments point at the same string. (Not that you could
discover that from their nonexistent documentation.) I considered
just reverting that change, but was able to fix things up reasonably
well at the price of a few extra strdup's. It turned out that
find_struct_member()'s modification of its input string is actually
entirely useless, because it undoes that before consulting the
string again. find_struct() and find_variable() need to make
copies, though.

regards, tom lane

Attachment Content-Type Size
v1-fix-missing-const-markers.patch text/x-diff 10.6 KB

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Paul A Jungwirth 2025-12-04 22:34:17 Fix out-of-date comment on makeRangeConstructors
Previous Message Nathan Bossart 2025-12-04 21:52:03 Re: vacuumdb: add --dry-run