From: Paul Eggert Date: Thu, 11 Sep 2014 00:29:54 +0000 (-0700) Subject: * charset.c (Fget_unused_iso_final_char): Fix subscript error. X-Git-Tag: emacs-25.0.90~2635^2~679^2~310 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=fe252976a18bf7bb66009fa80c1c6f02b124404f;p=emacs.git * charset.c (Fget_unused_iso_final_char): Fix subscript error. Use check_iso_charset_parameter instead of doing the checks by hand. (check_iso_charset_parameter): Move up. Check parameters a bit more carefully, and return true for 96-char sets. All callers changed. --- diff --git a/src/ChangeLog b/src/ChangeLog index 50f5fb8ca1e..f6cf9938573 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,10 @@ +2014-09-10 Paul Eggert + + * charset.c (Fget_unused_iso_final_char): Fix subscript error. + Use check_iso_charset_parameter instead of doing the checks by hand. + (check_iso_charset_parameter): Move up. Check parameters a bit + more carefully, and return true for 96-char sets. All callers changed. + 2014-09-10 Paul Eggert Simplify lisp.h by removing the __COUNTER__ business. diff --git a/src/charset.c b/src/charset.c index 6964208137b..501075621cd 100644 --- a/src/charset.c +++ b/src/charset.c @@ -1400,6 +1400,32 @@ Optional third argument DEUNIFY, if non-nil, means to de-unify CHARSET. */) return Qnil; } +/* Check that DIMENSION, CHARS, and FINAL_CHAR specify a valid ISO charset. + Return true if it's a 96-character set, false if 94. */ + +static bool +check_iso_charset_parameter (Lisp_Object dimension, Lisp_Object chars, + Lisp_Object final_char) +{ + CHECK_NUMBER (dimension); + CHECK_NUMBER (chars); + CHECK_CHARACTER (final_char); + + if (! (1 <= XINT (dimension) && XINT (dimension) <= 3)) + error ("Invalid DIMENSION %"pI"d, it should be 1, 2, or 3", + XINT (dimension)); + + bool chars_flag = XINT (chars) == 96; + if (! (chars_flag || XINT (chars) == 94)) + error ("Invalid CHARS %"pI"d, it should be 94 or 96", XINT (chars)); + + int final_ch = XFASTINT (final_char); + if (! ('0' <= final_ch && final_ch <= '~')) + error ("Invalid FINAL-CHAR '%c', it should be '0'..'~'", final_ch); + + return chars_flag; +} + DEFUN ("get-unused-iso-final-char", Fget_unused_iso_final_char, Sget_unused_iso_final_char, 2, 2, 0, doc: /* @@ -1412,35 +1438,12 @@ If there's no unused final char for the specified kind of charset, return nil. */) (Lisp_Object dimension, Lisp_Object chars) { - int final_char; - - CHECK_NUMBER (dimension); - CHECK_NUMBER (chars); - if (XINT (dimension) != 1 && XINT (dimension) != 2 && XINT (dimension) != 3) - args_out_of_range_3 (dimension, make_number (1), make_number (3)); - if (XINT (chars) != 94 && XINT (chars) != 96) - args_out_of_range_3 (chars, make_number (94), make_number (96)); - for (final_char = '0'; final_char <= '?'; final_char++) - if (ISO_CHARSET_TABLE (XINT (dimension), XINT (chars), final_char) < 0) - break; - return (final_char <= '?' ? make_number (final_char) : Qnil); -} - -static void -check_iso_charset_parameter (Lisp_Object dimension, Lisp_Object chars, Lisp_Object final_char) -{ - CHECK_NATNUM (dimension); - CHECK_NATNUM (chars); - CHECK_CHARACTER (final_char); - - if (XINT (dimension) > 3) - error ("Invalid DIMENSION %"pI"d, it should be 1, 2, or 3", - XINT (dimension)); - if (XINT (chars) != 94 && XINT (chars) != 96) - error ("Invalid CHARS %"pI"d, it should be 94 or 96", XINT (chars)); - if (XINT (final_char) < '0' || XINT (final_char) > '~') - error ("Invalid FINAL-CHAR %c, it should be `0'..`~'", - (int)XINT (final_char)); + bool chars_flag = check_iso_charset_parameter (dimension, chars, + make_number ('0')); + for (int final_char = '0'; final_char <= '?'; final_char++) + if (ISO_CHARSET_TABLE (XINT (dimension), chars_flag, final_char) < 0) + return make_number (final_char); + return Qnil; } @@ -1454,12 +1457,10 @@ if CHARSET is designated instead. */) (Lisp_Object dimension, Lisp_Object chars, Lisp_Object final_char, Lisp_Object charset) { int id; - bool chars_flag; CHECK_CHARSET_GET_ID (charset, id); - check_iso_charset_parameter (dimension, chars, final_char); - chars_flag = XINT (chars) == 96; - ISO_CHARSET_TABLE (XINT (dimension), chars_flag, XINT (final_char)) = id; + bool chars_flag = check_iso_charset_parameter (dimension, chars, final_char); + ISO_CHARSET_TABLE (XINT (dimension), chars_flag, XFASTINT (final_char)) = id; return Qnil; } @@ -2113,13 +2114,9 @@ See the documentation of the function `charset-info' for the meanings of DIMENSION, CHARS, and FINAL-CHAR. */) (Lisp_Object dimension, Lisp_Object chars, Lisp_Object final_char) { - int id; - bool chars_flag; - - check_iso_charset_parameter (dimension, chars, final_char); - chars_flag = XFASTINT (chars) == 96; - id = ISO_CHARSET_TABLE (XFASTINT (dimension), chars_flag, - XFASTINT (final_char)); + bool chars_flag = check_iso_charset_parameter (dimension, chars, final_char); + int id = ISO_CHARSET_TABLE (XINT (dimension), chars_flag, + XFASTINT (final_char)); return (id >= 0 ? CHARSET_NAME (CHARSET_FROM_ID (id)) : Qnil); }