diff options
| author | Paul Eggert | 2012-05-28 00:13:45 -0700 |
|---|---|---|
| committer | Paul Eggert | 2012-05-28 00:13:45 -0700 |
| commit | da92a98c3dd992778e06f8eda376599d670922cb (patch) | |
| tree | 7c83e70d6c8b583c61480920ce2614a357cea508 /src | |
| parent | fda91268666fe6c082ee08c0c9519a248a3a3d1f (diff) | |
| download | emacs-da92a98c3dd992778e06f8eda376599d670922cb.tar.gz emacs-da92a98c3dd992778e06f8eda376599d670922cb.zip | |
* 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.
Diffstat (limited to 'src')
| -rw-r--r-- | src/ChangeLog | 6 | ||||
| -rw-r--r-- | 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 @@ | |||
| 1 | 2012-05-28 Paul Eggert <eggert@cs.ucla.edu> | ||
| 2 | |||
| 3 | * bidi.c (bidi_mirror_char): Put eassert before conversion to int. | ||
| 4 | This avoids undefined behavior that might cause the eassert | ||
| 5 | to not catch an out-of-range value. | ||
| 6 | |||
| 1 | 2012-05-28 Juanma Barranquero <lekktu@gmail.com> | 7 | 2012-05-28 Juanma Barranquero <lekktu@gmail.com> |
| 2 | 8 | ||
| 3 | * makefile.w32-in ($(BLD)/w32inevt.$(O), $(BLD)/w32console.$(O)): | 9 | * 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) | |||
| 204 | val = CHAR_TABLE_REF (bidi_mirror_table, c); | 204 | val = CHAR_TABLE_REF (bidi_mirror_table, c); |
| 205 | if (INTEGERP (val)) | 205 | if (INTEGERP (val)) |
| 206 | { | 206 | { |
| 207 | int v = XINT (val); | 207 | int v; |
| 208 | 208 | ||
| 209 | /* In a build with extra checks, make sure the value does not | 209 | /* When debugging, check before assigning to V, so that the check |
| 210 | overflow a 32-bit int. */ | 210 | isn't broken by undefined behavior due to int overflow. */ |
| 211 | eassert (CHAR_VALID_P (XINT (val))); | 211 | eassert (CHAR_VALID_P (XINT (val))); |
| 212 | 212 | ||
| 213 | v = XINT (val); | ||
| 214 | |||
| 213 | /* Minimal test we must do in optimized builds, to prevent weird | 215 | /* Minimal test we must do in optimized builds, to prevent weird |
| 214 | crashes further down the road. */ | 216 | crashes further down the road. */ |
| 215 | if (v < 0 || v > MAX_CHAR) | 217 | if (v < 0 || v > MAX_CHAR) |