[ruby-trunk - Bug #6109][Open] plain-char for isdigit(), etc

Issue #6109 has been reported by Nobuyoshi N…


Bug #6109: plain-char for isdigit(), etc
https://bugs.ruby-lang.org/issues/6109

Author: Nobuyoshi N.
Status: Open
Priority: Normal
Assignee: tadayoshi funaba
Category: ext
Target version:
ruby -v: r34880

=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

Issue #6109 has been updated by tadayoshi funaba.

Status changed from Open to Closed


Bug #6109: plain-char for isdigit(), etc
https://bugs.ruby-lang.org/issues/6109

Author: Nobuyoshi N.
Status: Closed
Priority: Low
Assignee: tadayoshi funaba
Category: ext
Target version:
ruby -v: r34880

=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

Issue #6109 has been updated by tadayoshi funaba.

Priority changed from Normal to Low


Bug #6109: plain-char for isdigit(), etc
https://bugs.ruby-lang.org/issues/6109

Author: Nobuyoshi N.
Status: Open
Priority: Low
Assignee: tadayoshi funaba
Category: ext
Target version:
ruby -v: r34880

=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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs