* bidi.c (bidi_mirror_char): Put eassert before conversion to int.

This avoids undefined behavior that might cause the eassert
to not catch an out-of-range value.
This commit is contained in:
Paul Eggert 2012-05-28 00:13:45 -07:00
parent fda9126866
commit da92a98c3d
2 changed files with 11 additions and 3 deletions

View file

@ -1,3 +1,9 @@
2012-05-28 Paul Eggert <eggert@cs.ucla.edu>
* bidi.c (bidi_mirror_char): Put eassert before conversion to int.
This avoids undefined behavior that might cause the eassert
to not catch an out-of-range value.
2012-05-28 Juanma Barranquero <lekktu@gmail.com>
* makefile.w32-in ($(BLD)/w32inevt.$(O), $(BLD)/w32console.$(O)):

View file

@ -204,12 +204,14 @@ bidi_mirror_char (int c)
val = CHAR_TABLE_REF (bidi_mirror_table, c);
if (INTEGERP (val))
{
int v = XINT (val);
int v;
/* In a build with extra checks, make sure the value does not
overflow a 32-bit int. */
/* When debugging, check before assigning to V, so that the check
isn't broken by undefined behavior due to int overflow. */
eassert (CHAR_VALID_P (XINT (val)));
v = XINT (val);
/* Minimal test we must do in optimized builds, to prevent weird
crashes further down the road. */
if (v < 0 || v > MAX_CHAR)