Commit 34206dd2 authored by Paul Eggert's avatar 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.
parent c5958d4c
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.
......
......@@ -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);
......
......@@ -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)) \
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment