On Monday 15 October 2007 13:26:42 Tony Balinski wrote:
> Quoting Ivan Skytte Jørgensen <[EMAIL PROTECTED]>:
> > selection.c:95-110
> >     char *endptr;
> >     ...
> >     if (isdigit((unsigned char) *endptr ) ...
> > Why the cast?
>
> These "ctype function" casts were added when passing a plain char caused
> problems. I think it was on older Sun machines that the bug occurred. The
> implementation used macros to implement is...() and toupper/tolower, using
> the character's ordinal value as an index into a table. This worked for
> ASCII, but, since char was a signed value, failed for non-ASCII (eg Latin1)
> characters. The cast to unsigned char cured this. (A cast to int was
> rejected since this would cause sign extension.)
>
> I would prefer that these casts remain; it was a painful problem to find
> in the first place, and I wouldn't want to see a regression.

I just checked values -128..255 on Solaris 8 with isdigit() and isalpha():
Plain program:
        -128..-1: bogus;  0..127: ok;   128..255: all-0/ok
Program with setlocale(LC_CTYPE,""):
        -128..-1: bogus;  0..127: ok;   128..255: all-0/ok (??)
Program with setlocale(LC_CTYPE,"") and LC_CTYPE=en_US.UTF-8
        -128..-1: bogus;  0..127: ok;   128..255: all-0/ok
Program with setlocale(LC_CTYPE,"") and LC_CTYPE=nl_BE.ISO8859-1
        -128..-1: bogus;  0..127: ok;   128..255: ok

So I can confirm that the is..() functions are quite weird on Solaris for 
negative values. The default character type on Solaris is signed.

So I agree: the casts should stay. A comment somewhere in the sources on why 
it is done would be a good idea. Allthough I wonder what can go wrong in 
nedit if isdigit() etc. return random but consistent values.


Regards,
  Ivan
--
NEdit Develop mailing list - [email protected]
http://www.nedit.org/mailman/listinfo/develop

Reply via email to