From owner-svn-src-head@FreeBSD.ORG Thu Sep 3 07:26:04 2009 Return-Path: Delivered-To: svn-src-head@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id DB191106566B; Thu, 3 Sep 2009 07:26:04 +0000 (UTC) (envelope-from des@des.no) Received: from tim.des.no (tim.des.no [194.63.250.121]) by mx1.freebsd.org (Postfix) with ESMTP id 969A38FC18; Thu, 3 Sep 2009 07:26:04 +0000 (UTC) Received: from ds4.des.no (des.no [84.49.246.2]) by smtp.des.no (Postfix) with ESMTP id 46F6E6D41B; Thu, 3 Sep 2009 07:26:03 +0000 (UTC) Received: by ds4.des.no (Postfix, from userid 1001) id 1E57B844B4; Thu, 3 Sep 2009 09:26:03 +0200 (CEST) From: =?utf-8?Q?Dag-Erling_Sm=C3=B8rgrav?= To: Andrey Chernov References: <200909020456.n824uUqQ082136@svn.freebsd.org> <20090902070808.GA1290@arthur.nitro.dk> <20090902084002.GA17325@nagual.pp.ru> Date: Thu, 03 Sep 2009 09:26:03 +0200 In-Reply-To: <20090902084002.GA17325@nagual.pp.ru> (Andrey Chernov's message of "Wed, 2 Sep 2009 12:40:03 +0400") Message-ID: <867hwgcwvo.fsf@ds4.des.no> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.92 (berkeley-unix) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Cc: svn-src-head@FreeBSD.org, svn-src-all@FreeBSD.org, src-committers@FreeBSD.org, "Simon L. Nielsen" Subject: Re: svn commit: r196752 - head/lib/libc/stdtime X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 03 Sep 2009 07:26:04 -0000 Andrey Chernov writes: > "Simon L. Nielsen" 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