[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: EMACS_INT vs int for range checking

From: Paul Eggert
Subject: Re: EMACS_INT vs int for range checking
Date: Sat, 26 May 2012 12:05:48 -0700
User-agent: Mozilla/5.0 (X11; Linux i686; rv:12.0) Gecko/20120430 Thunderbird/12.0.1

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;

reply via email to

[Prev in Thread] Current Thread [Next in Thread]