Project

General

Profile

Actions

Bug #6108

closed

plain-char for isdigit()

Added by nobu (Nobuyoshi Nakada) over 13 years ago. Updated over 13 years ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
r34880
Backport:
[ruby-core:43060]

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


Related issues 1 (0 open1 closed)

Related to Ruby - Bug #6109: plain-char for isdigit(), etcClosedtadf (tadayoshi funaba)03/03/2012Actions
Actions

Also available in: Atom PDF

Like0
Like0