Make sure a 64-bit char is never passed to ENCODE_CHAR.
authorPaul Eggert <eggert@cs.ucla.edu>
Mon, 13 Jun 2011 01:07:35 +0000 (18:07 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Mon, 13 Jun 2011 01:07:35 +0000 (18:07 -0700)
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.

src/ChangeLog
src/charset.c
src/charset.h

index 01068fe..6a6ae7d 100644 (file)
@@ -1,5 +1,13 @@
 2011-06-13  Paul Eggert  <eggert@cs.ucla.edu>
 
+       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.
index 770e98c..29f98f2 100644 (file)
@@ -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);
index 16f45ff..24f0fc4 100644 (file)
@@ -27,6 +27,8 @@ along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
 #ifndef EMACS_CHARSET_H
 #define EMACS_CHARSET_H
 
+#include <verify.h>
+
 /* 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))                                       \