isdigit macro in <ctype.h> triggers -Wchar-subscripts when expanded in user code
hexian000 opened this issue · comments
msys2-runtime/newlib/libc/include/ctype.h
Line 90 in 76fd7ea
Macro argument __c should always be casted to int before use.
I think it should be:
#define __ctype_lookup(__c) ((__CTYPE_PTR+sizeof(""[(int)(__c)]))[(int)(__c)])
Sorry, my mistake.
Could you kindly provide information about the mistake that was made? It would greatly assist us to have this knowledge.
Could you kindly provide information about the mistake that was made? It would greatly assist us to have this knowledge.
I didn't read the comments above the quoted line carefully. This useful warning is triggered intentionally only by MSYS. (but not in normal Linux gcc toolchains, which is why I mistakenly thought it was a msys issue)
This error usually means that isdigit()
is called with char
parameters, i.e. signed 8-bit values. If you cast those to (int)
, you end up with 32-bit values in the range -128...127, which is really, really wrong here. What should be done is to cast the char
to (unsigned char)
. But that requires validating that the original parameter is actually a char
.