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

Christophe Lyon <[email protected]>
Newsgroups gmane.comp.lib.newlib
Message-ID <CAKdteOaix2wyhp62oQrmf6TigBOBdJK1cVDJMzFqqM2b47KHOw@mail.gmail.com>
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
newlib-4.txt (text/plain, 2.2 KB)
commit 349a08c43cd4baf0d93f28ea8ca7351bf9606d50
Author: Christophe Lyon <[email protected]>
Date:   Mon Oct 1 18:53:37 2018 +0000

    Cast "const char *" pointers to "char *" to avoid compiler warnings.
    
    2018-10-01  Christophe Lyon  <[email protected]>
    
    	* newlib/libc/ctype/ctype_.c (__set_ctype): Cast "_ctype_" to "char *".
    	* newlib/libc/ctype/jp2uc.c (_jp2uc_l, _uc2jp_l): Cast output of
    	"__locale_charset()" and "__current_locale_charset()" to "char *".
    	* newlib/libc/locale/locale.c (__loadlocale): Cast "new_locale" to
    	"char *".

diff --git a/newlib/libc/ctype/ctype_.c b/newlib/libc/ctype/ctype_.c
index 28727e8..851fc06 100644
--- a/newlib/libc/ctype/ctype_.c
+++ b/newlib/libc/ctype/ctype_.c
@@ -176,7 +176,7 @@ __set_ctype (struct __locale_t *loc, const char *charset)
 #  if defined(ALLOW_NEGATIVE_CTYPE_INDEX)
      ctype_ptr = _ctype_b;
 #  else
-     ctype_ptr = _ctype_;
+     ctype_ptr = (char *) _ctype_;
 #  endif
     }
 #  if defined(ALLOW_NEGATIVE_CTYPE_INDEX)
diff --git a/newlib/libc/ctype/jp2uc.c b/newlib/libc/ctype/jp2uc.c
index b89b5ea..00272eb 100644
--- a/newlib/libc/ctype/jp2uc.c
+++ b/newlib/libc/ctype/jp2uc.c
@@ -166,7 +166,7 @@ __uc2jp (wint_t c, int type)
 wint_t
 _jp2uc_l (wint_t c, struct __locale_t * l)
 {
-  char * cs = l ? __locale_charset(l) : __current_locale_charset();
+  char * cs = l ? (char *) __locale_charset(l) : (char *) __current_locale_charset();
   if (0 == strcmp (cs, "JIS"))
     c = __jp2uc (c, JP_JIS);
   else if (0 == strcmp (cs, "SJIS"))
@@ -186,7 +186,7 @@ _jp2uc (wint_t c)
 wint_t
 _uc2jp_l (wint_t c, struct __locale_t * l)
 {
-  char * cs = l ? __locale_charset(l) : __current_locale_charset();
+  char * cs = l ? (char *) __locale_charset(l) : (char *) __current_locale_charset();
   if (0 == strcmp (cs, "JIS"))
     c = __uc2jp (c, JP_JIS);
   else if (0 == strcmp (cs, "SJIS"))
diff --git a/newlib/libc/locale/locale.c b/newlib/libc/locale/locale.c
index 791a775..79da35f 100644
--- a/newlib/libc/locale/locale.c
+++ b/newlib/libc/locale/locale.c
@@ -515,7 +515,7 @@ restart:
     }
 # define FAIL	goto restart
 #else
-  locale = new_locale;
+  locale = (char *) new_locale;
 # define FAIL	return NULL
 #endif
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.