emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] master 159e9f4: * character.c (alphabeticp, decimalnump):


From: Paul Eggert
Subject: [Emacs-diffs] master 159e9f4: * character.c (alphabeticp, decimalnump): Avoid undefined behavior
Date: Sat, 28 Feb 2015 21:20:56 +0000

branch: master
commit 159e9f4b1c119ef0172ad22520e8342db337ff7d
Author: Paul Eggert <address@hidden>
Commit: Paul Eggert <address@hidden>

    * character.c (alphabeticp, decimalnump): Avoid undefined behavior
    
    if CATEGORY is not an integer, or is an integer out of
    unicode_category_t range.
---
 src/ChangeLog   |    6 ++++++
 src/character.c |   46 +++++++++++++++++++++-------------------------
 2 files changed, 27 insertions(+), 25 deletions(-)

diff --git a/src/ChangeLog b/src/ChangeLog
index 63ee7df..4aa64c1 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,9 @@
+2015-02-28  Paul Eggert  <address@hidden>
+
+       * 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  <address@hidden>
 
        * frame.c (make_initial_frame, Fmake_terminal_frame): Set
diff --git a/src/character.c b/src/character.c
index 999f99a..ad78f51 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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]