From: Paul Eggert <eggert@cs.ucla.edu>
To: Eli Zaretskii <eliz@gnu.org>
Cc: emacs-devel@gnu.org
Subject: Re: EMACS_INT vs int for range checking
Date: Sat, 26 May 2012 12:05:48 -0700 [thread overview]
Message-ID: <4FC1298C.2090801@cs.ucla.edu> (raw)
In-Reply-To: <8362bjw8t9.fsf@gnu.org>
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;
next prev parent reply other threads:[~2012-05-26 19:05 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-05-26 9:13 EMACS_INT vs int for range checking Paul Eggert
2012-05-26 10:11 ` Eli Zaretskii
2012-05-26 19:05 ` Paul Eggert [this message]
2012-05-27 6:19 ` Eli Zaretskii
2012-05-27 7:34 ` Paul Eggert
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4FC1298C.2090801@cs.ucla.edu \
--to=eggert@cs.ucla.edu \
--cc=eliz@gnu.org \
--cc=emacs-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.