From da92a98c3dd992778e06f8eda376599d670922cb Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Mon, 28 May 2012 00:13:45 -0700 Subject: [PATCH] * 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. --- src/ChangeLog | 6 ++++++ src/bidi.c | 8 +++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index 8a625602bbc..f4447da7010 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,9 @@ +2012-05-28 Paul Eggert + + * 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 * makefile.w32-in ($(BLD)/w32inevt.$(O), $(BLD)/w32console.$(O)): diff --git a/src/bidi.c b/src/bidi.c index 29abfb90838..7a716d3f0b0 100644 --- a/src/bidi.c +++ b/src/bidi.c @@ -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) -- 2.39.2