Re: [PATCH] Fix const warnings on Arch linux with the latest glibc.

Alejandro Colomar via Mutt-dev <[email protected]>
Newsgroups gmane.mail.mutt.devel
Message-ID <aZ7mzZlp7fxwf3Pq@devuan>
Hi Kevin,

On 2026-02-25T20:03:33+0800, Kevin J. McCarthy wrote:
> On Wed, Feb 25, 2026 at 12:07:03PM +0100, Alejandro Colomar wrote:
> > > diff --git a/parse.c b/parse.c
> > > index 141947f4..c46a5811 100644
> > > --- a/parse.c
> > > +++ b/parse.c
> > [...]
> > > @@ -1001,7 +1001,8 @@ time_t mutt_parse_date (const char *s, HEADER *h)
> > >          {
> > >            struct tz_t *tz;
> > > 
> > > -          tz = bsearch (ptz, TimeZones, sizeof TimeZones/sizeof (struct tz_t),
> > > +          tz = (struct tz_t *)bsearch (ptz, TimeZones,
> > > +                        sizeof TimeZones/sizeof (struct tz_t),
> > >                          sizeof (struct tz_t),
> > >                          (int (*)(const void *, const void *)) ascii_strcasecmp
> > >                          /* This is safe to do: A pointer to a struct equals
> > 
> > But, why do we need to cast here?
> 
> Oh, for this one I'm not sure.  It was in the patch Rene sent out initially,

Ahh, that was just to mark the places that needed inspection, IIRC, not
to actually use those casts.

bsearch(3) is one of the functions that now preserve const.

> so I just included it.  Rene, can you confirm the need for the cast?

I've now checked the code, and we don't write to it, so the solution
would be to declare 'tz' to be const, I think.

	-struct tz_t *tz;
	+const struct tz_t *tz;


Have a lovely day!
Alex

-- 
<https://www.alejandro-colomar.es>
signature.asc (application/pgp-signature, 833 B)
-----BEGIN PGP SIGNATURE-----

iQIzBAABCgAdFiEES7Jt9u9GbmlWADAi64mZXMKQwqkFAmme53oACgkQ64mZXMKQ
wqly0xAAp0a/800Mrm7+OpRaWZisk7CaisiQLrUB0eWM8bGRWaBWacSNyvO2USmm
diPcaN2YypDwM4hoJ5upNWxuFQnWjBQb0hiKnDkNZea3LoPTj7U85UoEtXhTbZ1b
yskpsjqRbFbsXNuO37WQRu0VWvg3pli+go/k4dbPIR53XVekYjFe/NmjnquxsIfl
LmWGgXNF5Ly/bPyULBhoq+yQXjwbOeU453LZAflLQzkwuSNaZBfOfTR0SwGPVa1Y
gdx4q8WHcCKc4D4acnbrDzzBle24Ol2gv2xLJuBhgl4HId0SLRRRGU8hPmPAIyAA
nKTYbECLVpo+655P271jSWGlEGdC5JtAaeBuheg0GBVyUFiW6HBeoZeMPLE8Yxf6
QIAJm61RVwn5xh1rHy3AGhEsXuHVnUm2vPs4q0eGYCWilxk3W5lgRTUyOueBpafx
vvHQO8bXPR4Iun2a69Q5OVrfg9abliPak/6QO+S1d8hDqoEZ9vj4MJn8IYf7i3uQ
g15kGNAyk7jheAfdD2tqbCllFsO8O/uhbhNfgUP+1UTqPp0QQyGTkWNchwyXiziP
xe0T0ExAflEAEiCYCsJbWYv2UTjSKhVitup1aLt0lnOAObFaC1Hc4fGFYRwaMXyq
3sLVxboNLNbn5PACUKUbh/m9z2VH3GTJvYHe7Tt/Gt09IyrDVvw=
=/Er9
-----END PGP SIGNATURE-----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.