Bug #6108
closedplain-char for isdigit()
Description
=begin
On cygwin, ((%syck%)) is warned as:
compiling rubyext.c
rubyext.c: In function 'mktime_do':
rubyext.c:280:9: warning: array subscript has type 'char'
compiling token.c
token.re: In function 'sycklex_yaml_utf8':
token.re:942:13: warning: array subscript has type 'char'
These come from (({isdigit()})) with plain char.
Citing from ((%ctype.h%)) of cygwin:
/* These macros are intentionally written in a manner that will trigger
a gcc -Wall warning if the user mistakenly passes a 'char' instead
of an int containing an 'unsigned char'. Note that the sizeof will
always be 1, which is what we want for mapping EOF to ctype_ptr[0];
the use of a raw index inside the sizeof triggers the gcc warning if
__c was of type char, and sizeof masks side effects of the extra __c.
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)])
And Linux manpage of ((%ctype%)) also states as:
DESCRIPTION
These functions check whether c, which must have the value of
an unsigned char or EOF, falls into a certain character class
according to the current locale.
Therefore, you MUST NOT use plain (or unlikely, (({signed}))) (({char})) for
(({isalpha()})), (({isspace()})), (({isdigit()})), and so on. You should use (({ISALPH()}))
etc instead, or cast as (({unsigned char})) explicitly.
=end
Updated by nobu (Nobuyoshi Nakada) about 12 years ago
- Status changed from Open to Closed
- % Done changed from 0 to 100
This issue was solved with changeset r34881.
Nobuyoshi, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.
- ext/syck/rubyext.c (mktime_do): use ISDIGIT().
[ruby-core:43060] [Bug #6108] - ext/syck/token.c (sycklex_yaml_utf8): cast as unsigned char.
[ruby-core:43060] [Bug #6108]