aboutsummaryrefslogtreecommitdiffstats
path: root/src/ccl.c
diff options
context:
space:
mode:
authorPaul Eggert2011-08-04 19:15:35 -0700
committerPaul Eggert2011-08-04 19:15:35 -0700
commit0065d05491ce5981ea20896bb26d21dcd31e6769 (patch)
tree13240167319d4a99ab5eacae4a883258eb2d28de /src/ccl.c
parent18ab493650d648ab8dca651ea2698861f926e895 (diff)
downloademacs-0065d05491ce5981ea20896bb26d21dcd31e6769.tar.gz
emacs-0065d05491ce5981ea20896bb26d21dcd31e6769.zip
Adjust in response to jan.h.d's comments.
See, for example <http://debbugs.gnu.org/cgi/bugreport.cgi?bug=9196#26>.
Diffstat (limited to 'src/ccl.c')
-rw-r--r--src/ccl.c40
1 files changed, 17 insertions, 23 deletions
diff --git a/src/ccl.c b/src/ccl.c
index 0a9b3d90708..dc0adae6877 100644
--- a/src/ccl.c
+++ b/src/ccl.c
@@ -2067,6 +2067,7 @@ usage: (ccl-execute-on-string CCL-PROGRAM STATUS STRING &optional CONTINUE UNIBY
2067#define CCL_EXECUTE_BUF_SIZE 1024 2067#define CCL_EXECUTE_BUF_SIZE 1024
2068 int source[CCL_EXECUTE_BUF_SIZE], destination[CCL_EXECUTE_BUF_SIZE]; 2068 int source[CCL_EXECUTE_BUF_SIZE], destination[CCL_EXECUTE_BUF_SIZE];
2069 ptrdiff_t consumed_chars, consumed_bytes, produced_chars; 2069 ptrdiff_t consumed_chars, consumed_bytes, produced_chars;
2070 int buf_magnification;
2070 2071
2071 if (setup_ccl_program (&ccl, ccl_prog) < 0) 2072 if (setup_ccl_program (&ccl, ccl_prog) < 0)
2072 error ("Invalid CCL program"); 2073 error ("Invalid CCL program");
@@ -2093,9 +2094,9 @@ usage: (ccl-execute-on-string CCL-PROGRAM STATUS STRING &optional CONTINUE UNIBY
2093 ccl.ic = i; 2094 ccl.ic = i;
2094 } 2095 }
2095 2096
2096 if (((min (PTRDIFF_MAX, SIZE_MAX) - 256) 2097 buf_magnification = ccl.buf_magnification ? ccl.buf_magnification : 1;
2097 / (ccl.buf_magnification ? ccl.buf_magnification : 1)) 2098
2098 < str_bytes) 2099 if ((min (PTRDIFF_MAX, SIZE_MAX) - 256) / buf_magnification < str_bytes)
2099 memory_full (SIZE_MAX); 2100 memory_full (SIZE_MAX);
2100 outbufsize = (ccl.buf_magnification 2101 outbufsize = (ccl.buf_magnification
2101 ? str_bytes * ccl.buf_magnification + 256 2102 ? str_bytes * ccl.buf_magnification + 256
@@ -2131,20 +2132,18 @@ usage: (ccl-execute-on-string CCL-PROGRAM STATUS STRING &optional CONTINUE UNIBY
2131 produced_chars += ccl.produced; 2132 produced_chars += ccl.produced;
2132 if (NILP (unibyte_p)) 2133 if (NILP (unibyte_p))
2133 { 2134 {
2135 /* FIXME: Surely this should be buf_magnification instead.
2136 MAX_MULTIBYTE_LENGTH overestimates the storage needed. */
2137 int magnification = MAX_MULTIBYTE_LENGTH;
2138
2134 ptrdiff_t offset = outp - outbuf; 2139 ptrdiff_t offset = outp - outbuf;
2135 if ((outbufsize - offset) / MAX_MULTIBYTE_LENGTH < ccl.produced) 2140 ptrdiff_t shortfall;
2141 if (INT_MULTIPLY_OVERFLOW (ccl.produced, magnification))
2142 memory_full (SIZE_MAX);
2143 shortfall = ccl.produced * magnification - (outbufsize - offset);
2144 if (0 < shortfall)
2136 { 2145 {
2137 ptrdiff_t produced; 2146 outbuf = xpalloc (outbuf, &outbufsize, shortfall, -1, 1);
2138 if (((min (PTRDIFF_MAX, SIZE_MAX) - outbufsize)
2139 / MAX_MULTIBYTE_LENGTH)
2140 < ccl.produced)
2141 {
2142 xfree (outbuf);
2143 memory_full (SIZE_MAX);
2144 }
2145 produced = ccl.produced;
2146 outbufsize += MAX_MULTIBYTE_LENGTH * produced;
2147 outbuf = (unsigned char *) xrealloc (outbuf, outbufsize);
2148 outp = outbuf + offset; 2147 outp = outbuf + offset;
2149 } 2148 }
2150 for (j = 0; j < ccl.produced; j++) 2149 for (j = 0; j < ccl.produced; j++)
@@ -2153,15 +2152,10 @@ usage: (ccl-execute-on-string CCL-PROGRAM STATUS STRING &optional CONTINUE UNIBY
2153 else 2152 else
2154 { 2153 {
2155 ptrdiff_t offset = outp - outbuf; 2154 ptrdiff_t offset = outp - outbuf;
2156 if (outbufsize - offset < ccl.produced) 2155 ptrdiff_t shortfall = ccl.produced - (outbufsize - offset);
2156 if (0 < shortfall)
2157 { 2157 {
2158 if (min (PTRDIFF_MAX, SIZE_MAX) - outbufsize < ccl.produced) 2158 outbuf = xpalloc (outbuf, &outbufsize, shortfall, -1, 1);
2159 {
2160 xfree (outbuf);
2161 memory_full (SIZE_MAX);
2162 }
2163 outbufsize += ccl.produced;
2164 outbuf = (unsigned char *) xrealloc (outbuf, outbufsize);
2165 outp = outbuf + offset; 2159 outp = outbuf + offset;
2166 } 2160 }
2167 for (j = 0; j < ccl.produced; j++) 2161 for (j = 0; j < ccl.produced; j++)