diff --git a/src/ChangeLog b/src/ChangeLog index 01068fea0be7b752f55ce13f7580302448f10555..6a6ae7d53cf8ecf21f3b2fac1c1fbb8a52d65ee5 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,5 +1,13 @@ 2011-06-13 Paul Eggert + 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. + * character.c (char_string): Remove unnecessary casts. Make sure a 64-bit char is never passed to CHAR_STRING. diff --git a/src/charset.c b/src/charset.c index 770e98c99e131c05e808305b7758b8880e9ce81a..29f98f24089acdc36bcb30f22e2504c75d63809b 100644 --- a/src/charset.c +++ b/src/charset.c @@ -1862,14 +1862,15 @@ Optional argument RESTRICTION specifies a way to map CH to a code-point in CCS. Currently not supported and just ignored. */) (Lisp_Object ch, Lisp_Object charset, Lisp_Object restriction) { - int id; + int c, id; unsigned code; struct charset *charsetp; CHECK_CHARSET_GET_ID (charset, id); - CHECK_NATNUM (ch); + CHECK_CHARACTER (ch); + c = XFASTINT (ch); charsetp = CHARSET_FROM_ID (id); - code = ENCODE_CHAR (charsetp, XINT (ch)); + code = ENCODE_CHAR (charsetp, c); if (code == CHARSET_INVALID_CODE (charsetp)) return Qnil; return INTEGER_TO_CONS (code); diff --git a/src/charset.h b/src/charset.h index 16f45ff9865a1dd09d4702be207a679cdd49d175..24f0fc46dec18f91a206295944699f3dccc56de5 100644 --- a/src/charset.h +++ b/src/charset.h @@ -27,6 +27,8 @@ along with GNU Emacs. If not, see . */ #ifndef EMACS_CHARSET_H #define EMACS_CHARSET_H +#include + /* Index to arguments of Fdefine_charset_internal. */ enum define_charset_arg_index @@ -427,7 +429,8 @@ extern Lisp_Object charset_work; #define ENCODE_CHAR(charset, c) \ ((ASCII_CHAR_P (c) && (charset)->ascii_compatible_p) \ ? (c) \ - : ((charset)->unified_p \ + : (!verify_true (sizeof (c) <= sizeof (int)) \ + || (charset)->unified_p \ || (charset)->method == CHARSET_METHOD_SUBSET \ || (charset)->method == CHARSET_METHOD_SUPERSET) \ ? encode_char ((charset), (c)) \