diff options
| author | Paul Eggert | 2011-06-12 18:07:35 -0700 |
|---|---|---|
| committer | Paul Eggert | 2011-06-12 18:07:35 -0700 |
| commit | 34206dd201b905b8f9eec84b4e90ba591b06a79a (patch) | |
| tree | 3a08862ed4619be5f2675986ec463d3432267cee /src | |
| parent | c5958d4cf336fdbc30364e7d701d6565acaf4002 (diff) | |
| download | emacs-34206dd201b905b8f9eec84b4e90ba591b06a79a.tar.gz emacs-34206dd201b905b8f9eec84b4e90ba591b06a79a.zip | |
Make sure a 64-bit char is never passed to ENCODE_CHAR.
This is for reasons similar to the recent CHAR_STRING fix.
* charset.c (Fencode_char): Check that character arg is actually
a character. Pass an int to ENCODE_CHAR.
* charset.h (ENCODE_CHAR): Verify that the character argument is no
wider than 'int', as a compile-time check to prevent future regressions
in this area.
Diffstat (limited to 'src')
| -rw-r--r-- | src/ChangeLog | 8 | ||||
| -rw-r--r-- | src/charset.c | 7 | ||||
| -rw-r--r-- | src/charset.h | 5 |
3 files changed, 16 insertions, 4 deletions
diff --git a/src/ChangeLog b/src/ChangeLog index 01068fea0be..6a6ae7d53cf 100644 --- a/src/ChangeLog +++ b/src/ChangeLog | |||
| @@ -1,5 +1,13 @@ | |||
| 1 | 2011-06-13 Paul Eggert <eggert@cs.ucla.edu> | 1 | 2011-06-13 Paul Eggert <eggert@cs.ucla.edu> |
| 2 | 2 | ||
| 3 | Make sure a 64-bit char is never passed to ENCODE_CHAR. | ||
| 4 | This is for reasons similar to the recent CHAR_STRING fix. | ||
| 5 | * charset.c (Fencode_char): Check that character arg is actually | ||
| 6 | a character. Pass an int to ENCODE_CHAR. | ||
| 7 | * charset.h (ENCODE_CHAR): Verify that the character argument is no | ||
| 8 | wider than 'int', as a compile-time check to prevent future regressions | ||
| 9 | in this area. | ||
| 10 | |||
| 3 | * character.c (char_string): Remove unnecessary casts. | 11 | * character.c (char_string): Remove unnecessary casts. |
| 4 | 12 | ||
| 5 | Make sure a 64-bit char is never passed to CHAR_STRING. | 13 | Make sure a 64-bit char is never passed to CHAR_STRING. |
diff --git a/src/charset.c b/src/charset.c index 770e98c99e1..29f98f24089 100644 --- a/src/charset.c +++ b/src/charset.c | |||
| @@ -1862,14 +1862,15 @@ Optional argument RESTRICTION specifies a way to map CH to a | |||
| 1862 | code-point in CCS. Currently not supported and just ignored. */) | 1862 | code-point in CCS. Currently not supported and just ignored. */) |
| 1863 | (Lisp_Object ch, Lisp_Object charset, Lisp_Object restriction) | 1863 | (Lisp_Object ch, Lisp_Object charset, Lisp_Object restriction) |
| 1864 | { | 1864 | { |
| 1865 | int id; | 1865 | int c, id; |
| 1866 | unsigned code; | 1866 | unsigned code; |
| 1867 | struct charset *charsetp; | 1867 | struct charset *charsetp; |
| 1868 | 1868 | ||
| 1869 | CHECK_CHARSET_GET_ID (charset, id); | 1869 | CHECK_CHARSET_GET_ID (charset, id); |
| 1870 | CHECK_NATNUM (ch); | 1870 | CHECK_CHARACTER (ch); |
| 1871 | c = XFASTINT (ch); | ||
| 1871 | charsetp = CHARSET_FROM_ID (id); | 1872 | charsetp = CHARSET_FROM_ID (id); |
| 1872 | code = ENCODE_CHAR (charsetp, XINT (ch)); | 1873 | code = ENCODE_CHAR (charsetp, c); |
| 1873 | if (code == CHARSET_INVALID_CODE (charsetp)) | 1874 | if (code == CHARSET_INVALID_CODE (charsetp)) |
| 1874 | return Qnil; | 1875 | return Qnil; |
| 1875 | return INTEGER_TO_CONS (code); | 1876 | return INTEGER_TO_CONS (code); |
diff --git a/src/charset.h b/src/charset.h index 16f45ff9865..24f0fc46dec 100644 --- a/src/charset.h +++ b/src/charset.h | |||
| @@ -27,6 +27,8 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ | |||
| 27 | #ifndef EMACS_CHARSET_H | 27 | #ifndef EMACS_CHARSET_H |
| 28 | #define EMACS_CHARSET_H | 28 | #define EMACS_CHARSET_H |
| 29 | 29 | ||
| 30 | #include <verify.h> | ||
| 31 | |||
| 30 | /* Index to arguments of Fdefine_charset_internal. */ | 32 | /* Index to arguments of Fdefine_charset_internal. */ |
| 31 | 33 | ||
| 32 | enum define_charset_arg_index | 34 | enum define_charset_arg_index |
| @@ -427,7 +429,8 @@ extern Lisp_Object charset_work; | |||
| 427 | #define ENCODE_CHAR(charset, c) \ | 429 | #define ENCODE_CHAR(charset, c) \ |
| 428 | ((ASCII_CHAR_P (c) && (charset)->ascii_compatible_p) \ | 430 | ((ASCII_CHAR_P (c) && (charset)->ascii_compatible_p) \ |
| 429 | ? (c) \ | 431 | ? (c) \ |
| 430 | : ((charset)->unified_p \ | 432 | : (!verify_true (sizeof (c) <= sizeof (int)) \ |
| 433 | || (charset)->unified_p \ | ||
| 431 | || (charset)->method == CHARSET_METHOD_SUBSET \ | 434 | || (charset)->method == CHARSET_METHOD_SUBSET \ |
| 432 | || (charset)->method == CHARSET_METHOD_SUPERSET) \ | 435 | || (charset)->method == CHARSET_METHOD_SUPERSET) \ |
| 433 | ? encode_char ((charset), (c)) \ | 436 | ? encode_char ((charset), (c)) \ |