emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] /srv/bzr/emacs/trunk r105585: * ccl.c: Improve and simplif


From: Paul Eggert
Subject: [Emacs-diffs] /srv/bzr/emacs/trunk r105585: * ccl.c: Improve and simplify overflow checking (Bug#9196).
Date: Sat, 27 Aug 2011 00:07:32 -0700
User-agent: Bazaar (2.3.1)

------------------------------------------------------------
revno: 105585
committer: Paul Eggert <address@hidden>
branch nick: trunk
timestamp: Sat 2011-08-27 00:07:32 -0700
message:
  * ccl.c: Improve and simplify overflow checking (Bug#9196).
  
  (ccl_driver): Do not generate an out-of-range pointer.
  (Fccl_execute_on_string): Remove unnecessary check for
  integer overflow, noted by Stefan Monnier in
  <http://lists.gnu.org/archive/html/emacs-devel/2011-08/msg00979.html>.
  Remove a FIXME that didn't need fixing.
  Simplify the newly-introduced buffer reallocation code.
modified:
  src/ChangeLog
  src/ccl.c
=== modified file 'src/ChangeLog'
--- a/src/ChangeLog     2011-08-27 01:42:00 +0000
+++ b/src/ChangeLog     2011-08-27 07:07:32 +0000
@@ -1,3 +1,13 @@
+2011-08-27  Paul Eggert  <address@hidden>
+
+       * ccl.c: Improve and simplify overflow checking (Bug#9196).
+       (ccl_driver): Do not generate an out-of-range pointer.
+       (Fccl_execute_on_string): Remove unnecessary check for
+       integer overflow, noted by Stefan Monnier in
+       <http://lists.gnu.org/archive/html/emacs-devel/2011-08/msg00979.html>.
+       Remove a FIXME that didn't need fixing.
+       Simplify the newly-introduced buffer reallocation code.
+
 2011-08-27  Juanma Barranquero  <address@hidden>
 
        * makefile.w32-in ($(BLD)/alloc.$(O)): Depend on lib/verify.h.

=== modified file 'src/ccl.c'
--- a/src/ccl.c 2011-08-05 02:15:35 +0000
+++ b/src/ccl.c 2011-08-27 07:07:32 +0000
@@ -1770,7 +1770,7 @@
        }
 
       msglen = strlen (msg);
-      if (dst + msglen <= dst_end)
+      if (msglen <= dst_end - dst)
        {
          for (i = 0; i < msglen; i++)
            *dst++ = msg[i];
@@ -2127,37 +2127,25 @@
       src_size = j;
       while (1)
        {
+         int max_expansion = NILP (unibyte_p) ? MAX_MULTIBYTE_LENGTH : 1;
+         ptrdiff_t offset, shortfall;
          ccl_driver (&ccl, src, destination, src_size, CCL_EXECUTE_BUF_SIZE,
                      Qnil);
          produced_chars += ccl.produced;
+         offset = outp - outbuf;
+         shortfall = ccl.produced * max_expansion - (outbufsize - offset);
+         if (0 < shortfall)
+           {
+             outbuf = xpalloc (outbuf, &outbufsize, shortfall, -1, 1);
+             outp = outbuf + offset;
+           }
          if (NILP (unibyte_p))
            {
-             /* FIXME: Surely this should be buf_magnification instead.
-                MAX_MULTIBYTE_LENGTH overestimates the storage needed.  */
-             int magnification = MAX_MULTIBYTE_LENGTH;
-
-             ptrdiff_t offset = outp - outbuf;
-             ptrdiff_t shortfall;
-             if (INT_MULTIPLY_OVERFLOW (ccl.produced, magnification))
-               memory_full (SIZE_MAX);
-             shortfall = ccl.produced * magnification - (outbufsize - offset);
-             if (0 < shortfall)
-               {
-                 outbuf = xpalloc (outbuf, &outbufsize, shortfall, -1, 1);
-                 outp = outbuf + offset;
-               }
              for (j = 0; j < ccl.produced; j++)
                CHAR_STRING_ADVANCE (destination[j], outp);
            }
          else
            {
-             ptrdiff_t offset = outp - outbuf;
-             ptrdiff_t shortfall = ccl.produced - (outbufsize - offset);
-             if (0 < shortfall)
-               {
-                 outbuf = xpalloc (outbuf, &outbufsize, shortfall, -1, 1);
-                 outp = outbuf + offset;
-               }
              for (j = 0; j < ccl.produced; j++)
                *outp++ = destination[j];
            }


reply via email to

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