summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/ChangeLog8
-rw-r--r--src/charset.c7
-rw-r--r--src/charset.h5
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 @@
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.
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
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 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/>. */
#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)) \