From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Paul Eggert Newsgroups: gmane.emacs.devel Subject: Re: EMACS_INT vs int for range checking Date: Sat, 26 May 2012 12:05:48 -0700 Organization: UCLA Computer Science Department Message-ID: <4FC1298C.2090801@cs.ucla.edu> References: <4FC09ECC.5050206@cs.ucla.edu> <8362bjw8t9.fsf@gnu.org> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Trace: dough.gmane.org 1338059163 31003 80.91.229.3 (26 May 2012 19:06:03 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Sat, 26 May 2012 19:06:03 +0000 (UTC) Cc: emacs-devel@gnu.org To: Eli Zaretskii Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sat May 26 21:06:02 2012 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1SYMJL-00038r-Q1 for ged-emacs-devel@m.gmane.org; Sat, 26 May 2012 21:05:59 +0200 Original-Received: from localhost ([::1]:42062 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SYMJL-0007dj-Fq for ged-emacs-devel@m.gmane.org; Sat, 26 May 2012 15:05:59 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:36467) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SYMJI-0007dP-1z for emacs-devel@gnu.org; Sat, 26 May 2012 15:05:57 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SYMJG-0003DO-CG for emacs-devel@gnu.org; Sat, 26 May 2012 15:05:55 -0400 Original-Received: from smtp.cs.ucla.edu ([131.179.128.62]:40416) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SYMJD-0003D2-Iw; Sat, 26 May 2012 15:05:51 -0400 Original-Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp.cs.ucla.edu (Postfix) with ESMTP id F246E39E800E; Sat, 26 May 2012 12:05:48 -0700 (PDT) X-Virus-Scanned: amavisd-new at smtp.cs.ucla.edu Original-Received: from smtp.cs.ucla.edu ([127.0.0.1]) by localhost (smtp.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 1qaHqFugGCXT; Sat, 26 May 2012 12:05:48 -0700 (PDT) Original-Received: from [192.168.1.10] (pool-71-189-109-235.lsanca.fios.verizon.net [71.189.109.235]) by smtp.cs.ucla.edu (Postfix) with ESMTPSA id 2C5AC39E800D; Sat, 26 May 2012 12:05:48 -0700 (PDT) User-Agent: Mozilla/5.0 (X11; Linux i686; rv:12.0) Gecko/20120430 Thunderbird/12.0.1 In-Reply-To: <8362bjw8t9.fsf@gnu.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 131.179.128.62 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:150650 Archived-At: On 05/26/2012 03:11 AM, Eli Zaretskii wrote: > If we need protection against overflowing a 32-bit int, > it should be part of CHAR_TABLE_REF But character tables can contain any Lisp objects, including integers greater than INT_MAX, so CHAR_TABLE_REF can't reject such integers. > That test is about making sure the result is a valid character code. Yes, but the current test does not reliably do that. On a 64-bit host with 32-bit int it's possible, for example, that bidi_mirror_char can return a garbage value. This is because assigning an out-of-int-range value to an 'int' results in undefined behavior. If it's the EMACS_INT that's annoying, how about this further patch? It shortens and clarifies the source code and fixes the portability problem. === modified file 'src/bidi.c' --- src/bidi.c 2012-05-26 07:03:39 +0000 +++ src/bidi.c 2012-05-26 18:22:13 +0000 @@ -204,12 +204,10 @@ bidi_mirror_char (int c) val = CHAR_TABLE_REF (bidi_mirror_table, c); if (INTEGERP (val)) { - int v = XINT (val); - - if (v < 0 || v > MAX_CHAR) + if (! CHAR_VALID_P (XINT (val))) abort (); - return v; + return XINT (val); } return c;