Bug #6109
closedplain-char for isdigit(), etc
Description
=begin
cygwinで、以下のように((%date%))で警告が出ます。
compiling date_parse.c
date_parse.c: In function ‘s3e’:
date_parse.c:92:2: 警告: array subscript has type ‘char’
date_parse.c:141:2: 警告: array subscript has type ‘char’
date_parse.c:173:2: 警告: array subscript has type ‘char’
date_parse.c:195:2: 警告: array subscript has type ‘char’
date_parse.c: In function ‘date_zone_to_diff’:
date_parse.c:384:2: 警告: array subscript has type ‘char’
date_parse.c:390:6: 警告: array subscript has type ‘char’
date_parse.c:391:3: 警告: array subscript has type ‘char’
date_parse.c: In function ‘parse_ddd_cb’:
date_parse.c:1416:6: 警告: array subscript has type ‘char’
date_parse.c: In function ‘check_class’:
date_parse.c:1523:6: 警告: array subscript has type ‘char’
date_parse.c:1525:6: 警告: array subscript has type ‘char’
compiling date_strftime.c
compiling date_strptime.c
date_strptime.c: In function ‘num_pattern_p’:
date_strptime.c:61:5: 警告: array subscript has type ‘char’
date_strptime.c:68:6: 警告: array subscript has type ‘char’
date_strptime.c: In function ‘date__strptime_internal’:
date_strptime.c:627:6: 警告: array subscript has type ‘char’
これらは(({isdigit()})), (({isspace()})), (({isalpha()}))などを(({plain char}))に対して使っているためです。
cygwinの((%ctype.h%))から引用:
/* 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)])
わざわざ(({unsigned char}))以外を使うと警告するようにしてあるということです。
また、Linuxの((%ctype%))のmanpageでも以下のように明確に規定されています。
説明
これらの関数は、現在のロケールに従って c を分類する。 c は unsigned char か EOF でなければならない。
つまり、(({plain char}))(または、あまりなさそうですが、(({signed char})))を(({isalpha()})), (({isspace()})), (({isdigit()}))などに使うことは誤りです。代わりに(({ISALPHA()}))などを使うか、明示的に(({unsigned char}))にキャストすべきです。
=end
Updated by tadf (tadayoshi funaba) over 12 years ago
- Priority changed from Normal to 3
Updated by tadf (tadayoshi funaba) over 12 years ago
- Status changed from Open to Closed