[PATCH] Add cast in ctype.h macro to avoid gcc -pedantic warning.

Sam Clegg sbc@chromium.org
Thu Feb 20 18:33:00 GMT 2014

Hi newlib,

A tiny patch to ctype.h.  I found that without this gcc will generate
a 'array subscript has type ‘char’' warnings when run with -pedantic
and -Wall.  I found this when compiling libssh which uses -pedandic
and -pedantic-errors.


 newlib/ChangeLog            | 5 +++++
 newlib/libc/include/ctype.h | 2 +-
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/newlib/ChangeLog b/newlib/ChangeLog
index 0116fd1..ba4ac1f 100644
--- a/newlib/ChangeLog
+++ b/newlib/ChangeLog
@@ -1,3 +1,8 @@
+2014-02-20  Sam Clegg  <sbc@chromium.org>
+       * newlib/libc/include/ctype.h (__ctype_lookup): Add extra cast to
+       prevent GCC warning when run with -Wall and -pedantic.
 2014-02-20  Corinna Vinschen  <vinschen@redhat.com>

        * libc/stdio/open_memstream.c (internal_open_memstream_r): Initialize
diff --git a/newlib/libc/include/ctype.h b/newlib/libc/include/ctype.h
index 56ad5ab..f4e8caf 100644
--- a/newlib/libc/include/ctype.h
+++ b/newlib/libc/include/ctype.h
@@ -54,7 +54,7 @@ extern        __IMPORT char   *__ctype_ptr__;
    Meanwhile, the real index to __ctype_ptr__+1 must be cast to int,
    since isalpha(0x100000001LL) must equal isalpha(1), rather than being
    an out-of-bounds reference on a 64-bit machine.  */
-#define __ctype_lookup(__c) ((__ctype_ptr__+sizeof(""[__c]))[(int)(__c)])
+#define __ctype_lookup(__c)

 #define        isalpha(__c)    (__ctype_lookup(__c)&(_U|_L))
 #define        isupper(__c)    ((__ctype_lookup(__c)&(_U|_L))==_U)

More information about the Newlib mailing list