emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] trunk r117397: Consistently use validate_subarray to verif


From: Dmitry Antipov
Subject: [Emacs-diffs] trunk r117397: Consistently use validate_subarray to verify substring.
Date: Wed, 25 Jun 2014 12:47:01 +0000
User-agent: Bazaar (2.6b2)

------------------------------------------------------------
revno: 117397
revision-id: address@hidden
parent: address@hidden
committer: Dmitry Antipov <address@hidden>
branch nick: trunk
timestamp: Wed 2014-06-25 16:11:08 +0400
message:
  Consistently use validate_subarray to verify substring.
  * fns.c (validate_substring): Not static any more.  Adjust to
  use ptrdiff_t, not EMACS_INT, becase string and vector limits
  can't exceed ptrdiff_t even if EMACS_INT is wider.
  * lisp.h (validate_subarray): Add prototype.
  * coding.c (Fundecodable_char_position):
  * composite.c (Fcomposition_get_gstring, Fcompose_string_internal):
  Use validate_subarray.  Adjust comment to mention substring.
modified:
  src/ChangeLog                  changelog-20091113204419-o5vbwnq5f7feedwu-1438
  src/coding.c                   coding.c-20091113204419-o5vbwnq5f7feedwu-1077
  src/composite.c                
composite.c-20091113204419-o5vbwnq5f7feedwu-1728
  src/fns.c                      fns.c-20091113204419-o5vbwnq5f7feedwu-203
  src/lisp.h                     lisp.h-20091113204419-o5vbwnq5f7feedwu-253
=== modified file 'src/ChangeLog'
--- a/src/ChangeLog     2014-06-25 10:36:51 +0000
+++ b/src/ChangeLog     2014-06-25 12:11:08 +0000
@@ -1,5 +1,16 @@
 2014-06-25  Dmitry Antipov  <address@hidden>
 
+       Consistently use validate_subarray to verify substring.
+       * fns.c (validate_substring): Not static any more.  Adjust to
+       use ptrdiff_t, not EMACS_INT, becase string and vector limits
+       can't exceed ptrdiff_t even if EMACS_INT is wider.
+       * lisp.h (validate_subarray): Add prototype.
+       * coding.c (Fundecodable_char_position):
+       * composite.c (Fcomposition_get_gstring, Fcompose_string_internal):
+       Use validate_subarray.  Adjust comment to mention substring.
+
+2014-06-25  Dmitry Antipov  <address@hidden>
+
        Do not allow out-of-range character position in Fcompare_strings.
        * fns.c (validate_subarray): Add prototype.
        (Fcompare_substring): Use validate_subarray to check ranges.

=== modified file 'src/coding.c'
--- a/src/coding.c      2014-06-23 04:11:29 +0000
+++ b/src/coding.c      2014-06-25 12:11:08 +0000
@@ -9091,8 +9091,7 @@
 
 DEFUN ("unencodable-char-position", Funencodable_char_position,
        Sunencodable_char_position, 3, 5, 0,
-       doc: /*
-Return position of first un-encodable character in a region.
+       doc: /* Return position of first un-encodable character in a region.
 START and END specify the region and CODING-SYSTEM specifies the
 encoding to check.  Return nil if CODING-SYSTEM does encode the region.
 
@@ -9102,8 +9101,9 @@
 
 If optional 5th argument STRING is non-nil, it is a string to search
 for un-encodable characters.  In that case, START and END are indexes
-to the string.  */)
-  (Lisp_Object start, Lisp_Object end, Lisp_Object coding_system, Lisp_Object 
count, Lisp_Object string)
+to the string and treated as in `substring'.  */)
+  (Lisp_Object start, Lisp_Object end, Lisp_Object coding_system,
+   Lisp_Object count, Lisp_Object string)
 {
   EMACS_INT n;
   struct coding_system coding;
@@ -9140,12 +9140,7 @@
   else
     {
       CHECK_STRING (string);
-      CHECK_NATNUM (start);
-      CHECK_NATNUM (end);
-      if (! (XINT (start) <= XINT (end) && XINT (end) <= SCHARS (string)))
-       args_out_of_range_3 (string, start, end);
-      from = XINT (start);
-      to = XINT (end);
+      validate_subarray (string, start, end, SCHARS (string), &from, &to);
       if (! STRING_MULTIBYTE (string))
        return Qnil;
       p = SDATA (string) + string_char_to_byte (string, from);

=== modified file 'src/composite.c'
--- a/src/composite.c   2014-06-17 03:14:00 +0000
+++ b/src/composite.c   2014-06-25 12:11:08 +0000
@@ -1684,9 +1684,10 @@
 frame, or nil for the selected frame's terminal device.
 
 If the optional 4th argument STRING is not nil, it is a string
-containing the target characters between indices FROM and TO.
-Otherwise FROM and TO are character positions in current buffer;
-they can be in either order, and can be integers or markers.
+containing the target characters between indices FROM and TO,
+which are treated as in `substring'.  Otherwise FROM and TO are
+character positions in current buffer; they can be in either order,
+and can be integers or markers.
 
 A glyph-string is a vector containing information about how to display
 a specific character sequence.  The format is:
@@ -1742,15 +1743,10 @@
     }
   else
     {
-      CHECK_NATNUM (from);
-      CHECK_NATNUM (to);
       CHECK_STRING (string);
+      validate_subarray (string, from, to, SCHARS (string), &frompos, &topos);
       if (! STRING_MULTIBYTE (string))
        error ("Attempt to shape unibyte text");
-      if (! (XINT (from) <= XINT (to) && XINT (to) <= SCHARS (string)))
-       args_out_of_range_3 (string, from, to);
-      frompos = XFASTINT (from);
-      topos = XFASTINT (to);
       frombyte = string_char_to_byte (string, frompos);
     }
 
@@ -1795,21 +1791,18 @@
        Scompose_string_internal, 3, 5, 0,
        doc: /* Internal use only.
 
-Compose text between indices START and END of STRING.
-Optional 4th and 5th arguments are COMPONENTS and MODIFICATION-FUNC
+Compose text between indices START and END of STRING, where
+START and END are treated as in `substring'.  Optional 4th
+and 5th arguments are COMPONENTS and MODIFICATION-FUNC
 for the composition.  See `compose-string' for more details.  */)
-  (Lisp_Object string, Lisp_Object start, Lisp_Object end, Lisp_Object 
components, Lisp_Object modification_func)
+  (Lisp_Object string, Lisp_Object start, Lisp_Object end,
+   Lisp_Object components, Lisp_Object modification_func)
 {
+  ptrdiff_t from, to;
+
   CHECK_STRING (string);
-  CHECK_NUMBER (start);
-  CHECK_NUMBER (end);
-
-  if (XINT (start) < 0 ||
-      XINT (start) > XINT (end)
-      || XINT (end) > SCHARS (string))
-    args_out_of_range (start, end);
-
-  compose_text (XINT (start), XINT (end), components, modification_func, 
string);
+  validate_subarray (string, start, end, SCHARS (string), &from, &to);
+  compose_text (from, to, components, modification_func, string);
   return string;
 }
 

=== modified file 'src/fns.c'
--- a/src/fns.c 2014-06-25 10:36:51 +0000
+++ b/src/fns.c 2014-06-25 12:11:08 +0000
@@ -50,8 +50,6 @@
 static Lisp_Object Qmd5, Qsha1, Qsha224, Qsha256, Qsha384, Qsha512;
 
 static bool internal_equal (Lisp_Object, Lisp_Object, int, bool, Lisp_Object);
-static void validate_subarray (Lisp_Object, Lisp_Object, Lisp_Object,
-                              ptrdiff_t, EMACS_INT *, EMACS_INT *);
 
 DEFUN ("identity", Fidentity, Sidentity, 1, 1, 0,
        doc: /* Return the argument unchanged.  */)
@@ -250,8 +248,7 @@
   (Lisp_Object str1, Lisp_Object start1, Lisp_Object end1, Lisp_Object str2,
    Lisp_Object start2, Lisp_Object end2, Lisp_Object ignore_case)
 {
-  EMACS_INT from1, to1, from2, to2;
-  ptrdiff_t i1, i1_byte, i2, i2_byte;
+  ptrdiff_t from1, to1, from2, to2, i1, i1_byte, i2, i2_byte;
 
   CHECK_STRING (str1);
   CHECK_STRING (str2);
@@ -1114,9 +1111,9 @@
    Count negative values backwards from the end.
    Set *IFROM and *ITO to the two indexes used.  */
 
-static void
+void
 validate_subarray (Lisp_Object array, Lisp_Object from, Lisp_Object to,
-                  ptrdiff_t size, EMACS_INT *ifrom, EMACS_INT *ito)
+                  ptrdiff_t size, ptrdiff_t *ifrom, ptrdiff_t *ito)
 {
   EMACS_INT f, t;
 
@@ -1165,8 +1162,7 @@
   (Lisp_Object string, Lisp_Object from, Lisp_Object to)
 {
   Lisp_Object res;
-  ptrdiff_t size;
-  EMACS_INT ifrom, ito;
+  ptrdiff_t size, ifrom, ito;
 
   if (STRINGP (string))
     size = SCHARS (string);
@@ -1206,9 +1202,7 @@
 With one argument, just copy STRING without its properties.  */)
   (Lisp_Object string, register Lisp_Object from, Lisp_Object to)
 {
-  ptrdiff_t size;
-  EMACS_INT from_char, to_char;
-  ptrdiff_t from_byte, to_byte;
+  ptrdiff_t from_char, to_char, from_byte, to_byte, size;
 
   CHECK_STRING (string);
 
@@ -4637,12 +4631,12 @@
 /* ALGORITHM is a symbol: md5, sha1, sha224 and so on. */
 
 static Lisp_Object
-secure_hash (Lisp_Object algorithm, Lisp_Object object, Lisp_Object start, 
Lisp_Object end, Lisp_Object coding_system, Lisp_Object noerror, Lisp_Object 
binary)
+secure_hash (Lisp_Object algorithm, Lisp_Object object, Lisp_Object start,
+            Lisp_Object end, Lisp_Object coding_system, Lisp_Object noerror,
+            Lisp_Object binary)
 {
   int i;
-  ptrdiff_t size;
-  EMACS_INT start_char = 0, end_char = 0;
-  ptrdiff_t start_byte, end_byte;
+  ptrdiff_t size, start_char = 0, start_byte, end_char = 0, end_byte;
   register EMACS_INT b, e;
   register struct buffer *bp;
   EMACS_INT temp;

=== modified file 'src/lisp.h'
--- a/src/lisp.h        2014-06-24 08:10:48 +0000
+++ b/src/lisp.h        2014-06-25 12:11:08 +0000
@@ -3464,7 +3464,8 @@
 ptrdiff_t hash_put (struct Lisp_Hash_Table *, Lisp_Object, Lisp_Object,
                    EMACS_UINT);
 extern struct hash_table_test hashtest_eql, hashtest_equal;
-
+extern void validate_subarray (Lisp_Object, Lisp_Object, Lisp_Object,
+                              ptrdiff_t, ptrdiff_t *, ptrdiff_t *);
 extern Lisp_Object substring_both (Lisp_Object, ptrdiff_t, ptrdiff_t,
                                   ptrdiff_t, ptrdiff_t);
 extern Lisp_Object merge (Lisp_Object, Lisp_Object, Lisp_Object);


reply via email to

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