From: Paul Eggert Date: Sat, 28 Feb 2015 21:19:55 +0000 (-0800) Subject: * character.c (alphabeticp, decimalnump): Avoid undefined behavior X-Git-Tag: emacs-25.0.90~2564^2~269 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=159e9f4b1c119ef0172ad22520e8342db337ff7d;p=emacs.git * character.c (alphabeticp, decimalnump): Avoid undefined behavior if CATEGORY is not an integer, or is an integer out of unicode_category_t range. --- diff --git a/src/ChangeLog b/src/ChangeLog index 63ee7dffa21..4aa64c1d6f9 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,9 @@ +2015-02-28 Paul Eggert + + * character.c (alphabeticp, decimalnump): Avoid undefined behavior + if CATEGORY is not an integer, or is an integer out of + unicode_category_t range. + 2015-02-28 Martin Rudalics * frame.c (make_initial_frame, Fmake_terminal_frame): Set diff --git a/src/character.c b/src/character.c index 999f99aa003..ad78f512f43 100644 --- a/src/character.c +++ b/src/character.c @@ -990,24 +990,22 @@ bool alphabeticp (int c) { Lisp_Object category = CHAR_TABLE_REF (Vunicode_category_table, c); - - if (INTEGERP (category)) - { - unicode_category_t gen_cat = XINT (category); - - /* See UTS #18. There are additional characters that should be - here, those designated as Other_uppercase, Other_lowercase, - and Other_alphabetic; FIXME. */ - return (gen_cat == UNICODE_CATEGORY_Lu - || gen_cat == UNICODE_CATEGORY_Ll - || gen_cat == UNICODE_CATEGORY_Lt - || gen_cat == UNICODE_CATEGORY_Lm - || gen_cat == UNICODE_CATEGORY_Lo - || gen_cat == UNICODE_CATEGORY_Mn - || gen_cat == UNICODE_CATEGORY_Mc - || gen_cat == UNICODE_CATEGORY_Me - || gen_cat == UNICODE_CATEGORY_Nl) ? true : false; - } + if (! INTEGERP (category)) + return false; + EMACS_INT gen_cat = XINT (category); + + /* See UTS #18. There are additional characters that should be + here, those designated as Other_uppercase, Other_lowercase, + and Other_alphabetic; FIXME. */ + return (gen_cat == UNICODE_CATEGORY_Lu + || gen_cat == UNICODE_CATEGORY_Ll + || gen_cat == UNICODE_CATEGORY_Lt + || gen_cat == UNICODE_CATEGORY_Lm + || gen_cat == UNICODE_CATEGORY_Lo + || gen_cat == UNICODE_CATEGORY_Mn + || gen_cat == UNICODE_CATEGORY_Mc + || gen_cat == UNICODE_CATEGORY_Me + || gen_cat == UNICODE_CATEGORY_Nl); } /* Return 'true' if C is an decimal-number character as defined by its @@ -1016,14 +1014,12 @@ bool decimalnump (int c) { Lisp_Object category = CHAR_TABLE_REF (Vunicode_category_table, c); + if (! INTEGERP (category)) + return false; + EMACS_INT gen_cat = XINT (category); - if (INTEGERP (category)) - { - unicode_category_t gen_cat = XINT (category); - - /* See UTS #18. */ - return (gen_cat == UNICODE_CATEGORY_Nd) ? true : false; - } + /* See UTS #18. */ + return gen_cat == UNICODE_CATEGORY_Nd; } void