[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: Sun, 27 May 2012 00:34:39 -0700
User-agent: Mozilla/5.0 (X11; Linux i686; rv:12.0) Gecko/20120430 Thunderbird/12.0.1

On 05/26/2012 11:19 PM, Eli Zaretskii wrote:
> If that garbage passes the [0..MAX_CHAR] test, it's garbage that the
> bidi reordering engine and the rest of redisplay can live with.

No, because the rest of redisplay cannot live with undefined
behavior.  For example, the generated machine code could use
32-bit comparison within bidi_mirror_char, so that (v < 0 ||
v > MAX_CHAR) yields false, but return an untruncated 64-bit
value to the caller, so that the returned value exceeds
MAX_CHAR and messes up the caller.

> How can that undefined behavior be any worse than aborting?

When the undefined behavior doesn't abort -- when it goes on
to cause subtle errors in later computation.

>> 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.
> I will only accept such a test as an eassert.  This code is in the
> innermost loop of the Emacs display engine, so doing all that juggling
> in an optimized build _for_every_character_we_display_ is unacceptable.

OK, thanks, I installed it as an eassert.  (Though the code
runs equally fast either way with any decent modern
compiler, as most of CHAR_VALID_P is optimized away.)

reply via email to

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