Re: Cast "const char *" pointers to "char *" to avoid compiler warnings.

Corinna Vinschen <[email protected]>
Newsgroups gmane.comp.lib.newlib
Message-ID <[email protected]>
On Oct  2 11:10, Christophe Lyon wrote:
> On Tue, 2 Oct 2018 at 00:50, Craig Howland <[email protected]> wrote:
> >
> > On 10/01/2018 05:33 PM, Christophe Lyon wrote:
> > > Hi,
> > >
> > > GCC complains that some assignments loose the const-ness of several
> > > data. This small patch adds explicit (char *) casts, but I'm not
> > > familiar enough with what newlib does with these to be sure that they
> > > are not modified. Maybe the proper fix would be to declare the
> > > destinations as "const"?
> > >
> > > Christophe
> > If I understand what you're saying properly, it amounts to saying that you did
> > not verify whether the GCC warnings about discarding const are valid or not, yet
> > you are suppressing them.  Is this a proper understanding?  If so, it seems like
> > these proposed patches are a bad idea, as they might be hiding a real problem,
> > or changing the wrong thing.  (In a very quick look at locale.c, for example,
> > locale can definitely be written to--it is definitely not const. This implies
> > that the const on new_locale is what is wrong.)
> 
> I did have this "very quick look at locale.c" before writing the
> patch, and not adding
> the cast at the assignment point means removing "const" from __loadlocale()
> prototype:
> char *__loadlocale (struct __locale_t *loc, int category, const char
> *new_locale)
> which in turn has a significant impact on the callers which I hope
> people familiar
> with this area can confirm, or not.

The bug was, in fact, to define the third parameter as const, given it
gets potentially overwritten.  None of the incoming values is const
anyway.  I pushed a patch.


Corinna

-- 
Corinna Vinschen
Cygwin Maintainer
Red Hat
signature.asc (application/pgp-signature, 833 B)
-----BEGIN PGP SIGNATURE-----

iQIzBAEBCAAdFiEEoVYPmneWZnwT6kwF9TYGna5ET6AFAlu9xNkACgkQ9TYGna5E
T6BxEw/+La1IBOQWnPlEpxvm4bD6V20aSqko67N2nNqe/EgAp8z+SLdBdw0dbwsm
dak34BhR2qBjgvrBE2B38riioPXs6nSKv0RV38eJMsXjzzuhK5Chy9JK+z/f3k21
7pW1SHZBaTHqizEG0NJ/Xz8LIj8A2weYTqvSIfHAjNkiNFPk6tXV9n+GdO0d1Vuk
MJraZf5QU3S0B79/Jbf3VSGmZJeB/JJvW94IQVvaRLZGjUNanMxiYGDrnXedp/p0
YBFBhsvIuwqn2wbK6BEDBdtn/rcOfwGGPX/ytQO/dLiEpR8+OFeeD5dYRJ8aEhr4
mKyarSab4T92bBaKDvl4JgUBvOcNgfTubI/t93s21goaV/ZxMPAjykAiK5T5hYS+
ZFLym76q78igrfy29vhESu5DjlHii97O7ZrZJd8QI6re2v0rWYiH7S8RjMHeQF8Q
gDMH7W50M+qowNWQ8/Dcrv/XpAjnfiDSsRM16+BEf5iQTvWfENGZdHYtkh0HBury
7HakRde20urLGTSj3qJlxMyr/FITt6xvFspq7PT2Mi8ygrPrfiBpWrZ6VqPDmdWM
CFNkryArziMKCp5GDiDB6XzSPgk6HA8eCjHt4kNbQFXGB0kdMwyfzmkEpZDQ/OzD
acbwFR5aEOrpMD2Ed64Zz/lGFVSslPTi4lPyM6lj5cSORmDnNuE=
=E1/W
-----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.