Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 03 Sep 2009 09:26:03 +0200
From:      =?utf-8?Q?Dag-Erling_Sm=C3=B8rgrav?= <des@des.no>
To:        Andrey Chernov <ache@nagual.pp.ru>
Cc:        svn-src-head@FreeBSD.org, svn-src-all@FreeBSD.org, src-committers@FreeBSD.org, "Simon L. Nielsen" <simon@FreeBSD.org>
Subject:   Re: svn commit: r196752 - head/lib/libc/stdtime
Message-ID:  <867hwgcwvo.fsf@ds4.des.no>
In-Reply-To: <20090902084002.GA17325@nagual.pp.ru> (Andrey Chernov's message of "Wed, 2 Sep 2009 12:40:03 %2B0400")
References:  <200909020456.n824uUqQ082136@svn.freebsd.org> <20090902070808.GA1290@arthur.nitro.dk> <20090902084002.GA17325@nagual.pp.ru>

next in thread | previous in thread | raw e-mail | index | archive | help
Andrey Chernov <ache@nagual.pp.ru> writes:
> "Simon L. Nielsen" <simon@FreeBSD.org> writes:
> > Acording to the manual page and the C standard book I have,
> > isdigit() takes an int for an argument, so why change this?
> "The value of the argument must be representable as an unsigned char or
> the value of EOF."
>
> Signed char (automatically casted to int in expression even without direc=
t=20
> (int) cast) passed to any ctype macro potentically may cause a lot of=20
> problems, such as: incorrect char class detection or even core dump in=20
> some systems.
>
> This is due to automatic sign extension of 8bit (if present).

To put it more clearly:

 - The is*() functions expect an int for the same reason fgetc() returns
   one: a char alone can't represent all possible char values *plus*
   EOF.

 - In most 8-bit locales, there are valid characters outside the 0-127
   range.  When stored in a signed char, such characters are represented
   as negative values.  When that signed char is promoted to a signed
   int, the negative values remain negative instead of being converted
   to the correct positive value.

 - This would not be a problem if C distinguished between a character
   (unsigned) and a "short short int" (signed).

 - The core dump ache refers to can occur with a na=C3=AFve implementation
   that uses a lookup table and checks for EOF, but not for other
   negative values.

DES
--=20
Dag-Erling Sm=C3=B8rgrav - des@des.no



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?867hwgcwvo.fsf>