This is the mail archive of the glibc-bugs@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug libc/11435] New: <ctype.h> inhibits -Wchar-subscript warning on invalid use of character classification macros


Consider e.g. the following code:

char c = 0xeb;
isalpha(c);

Assuming that char is a signed type, this code accesses the array
__ctype_b_loc[] outside the range -1 .. 255 because 'c' is sign-extended to the
type int during compilation of the above code. With older versions of the glibc
library it was possible to detect such programming errors by using the gcc
command-line option -Wchar-subscript. Newer glibc versions cast arguments of
character classification macros to int and hence make it impossible to detect
such errors via -Wchar-subscript. Can <ctype.h> please be modified such that it
again becomes possible to detect these errors via -Wchar-subscript ? I found the
following in <ctype.h>:

#define __isctype(c, type) \
  ((*__ctype_b_loc ())[(int) (c)] & (unsigned short int) type)

Why has the cast from (c) to (int)(c) been added in this macro ?

-- 
           Summary: <ctype.h> inhibits -Wchar-subscript warning on invalid
                    use of character classification macros
           Product: glibc
           Version: 2.9
            Status: NEW
          Severity: normal
          Priority: P2
         Component: libc
        AssignedTo: drepper at redhat dot com
        ReportedBy: bart dot vanassche at gmail dot com
                CC: glibc-bugs at sources dot redhat dot com


http://sourceware.org/bugzilla/show_bug.cgi?id=11435

------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]