diff options
Diffstat (limited to 'src/ccl.c')
| -rw-r--r-- | src/ccl.c | 41 |
1 files changed, 20 insertions, 21 deletions
| @@ -1303,7 +1303,7 @@ ccl_driver (struct ccl_program *ccl, int *source, int *destination, int src_size | |||
| 1303 | 1303 | ||
| 1304 | case CCL_LookupIntConstTbl: | 1304 | case CCL_LookupIntConstTbl: |
| 1305 | { | 1305 | { |
| 1306 | EMACS_INT eop; | 1306 | ptrdiff_t eop; |
| 1307 | struct Lisp_Hash_Table *h; | 1307 | struct Lisp_Hash_Table *h; |
| 1308 | GET_CCL_RANGE (eop, ccl_prog, ic++, 0, | 1308 | GET_CCL_RANGE (eop, ccl_prog, ic++, 0, |
| 1309 | (VECTORP (Vtranslation_hash_table_vector) | 1309 | (VECTORP (Vtranslation_hash_table_vector) |
| @@ -1329,7 +1329,7 @@ ccl_driver (struct ccl_program *ccl, int *source, int *destination, int src_size | |||
| 1329 | 1329 | ||
| 1330 | case CCL_LookupCharConstTbl: | 1330 | case CCL_LookupCharConstTbl: |
| 1331 | { | 1331 | { |
| 1332 | EMACS_INT eop; | 1332 | ptrdiff_t eop; |
| 1333 | struct Lisp_Hash_Table *h; | 1333 | struct Lisp_Hash_Table *h; |
| 1334 | GET_CCL_RANGE (eop, ccl_prog, ic++, 0, | 1334 | GET_CCL_RANGE (eop, ccl_prog, ic++, 0, |
| 1335 | (VECTORP (Vtranslation_hash_table_vector) | 1335 | (VECTORP (Vtranslation_hash_table_vector) |
| @@ -1770,7 +1770,7 @@ ccl_driver (struct ccl_program *ccl, int *source, int *destination, int src_size | |||
| 1770 | } | 1770 | } |
| 1771 | 1771 | ||
| 1772 | msglen = strlen (msg); | 1772 | msglen = strlen (msg); |
| 1773 | if (dst + msglen <= dst_end) | 1773 | if (msglen <= dst_end - dst) |
| 1774 | { | 1774 | { |
| 1775 | for (i = 0; i < msglen; i++) | 1775 | for (i = 0; i < msglen; i++) |
| 1776 | *dst++ = msg[i]; | 1776 | *dst++ = msg[i]; |
| @@ -2061,12 +2061,13 @@ usage: (ccl-execute-on-string CCL-PROGRAM STATUS STRING &optional CONTINUE UNIBY | |||
| 2061 | Lisp_Object val; | 2061 | Lisp_Object val; |
| 2062 | struct ccl_program ccl; | 2062 | struct ccl_program ccl; |
| 2063 | int i; | 2063 | int i; |
| 2064 | EMACS_INT outbufsize; | 2064 | ptrdiff_t outbufsize; |
| 2065 | unsigned char *outbuf, *outp; | 2065 | unsigned char *outbuf, *outp; |
| 2066 | EMACS_INT str_chars, str_bytes; | 2066 | ptrdiff_t str_chars, str_bytes; |
| 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 | EMACS_INT 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,6 +2094,10 @@ usage: (ccl-execute-on-string CCL-PROGRAM STATUS STRING &optional CONTINUE UNIBY | |||
| 2093 | ccl.ic = i; | 2094 | ccl.ic = i; |
| 2094 | } | 2095 | } |
| 2095 | 2096 | ||
| 2097 | buf_magnification = ccl.buf_magnification ? ccl.buf_magnification : 1; | ||
| 2098 | |||
| 2099 | if ((min (PTRDIFF_MAX, SIZE_MAX) - 256) / buf_magnification < str_bytes) | ||
| 2100 | memory_full (SIZE_MAX); | ||
| 2096 | outbufsize = (ccl.buf_magnification | 2101 | outbufsize = (ccl.buf_magnification |
| 2097 | ? str_bytes * ccl.buf_magnification + 256 | 2102 | ? str_bytes * ccl.buf_magnification + 256 |
| 2098 | : str_bytes + 256); | 2103 | : str_bytes + 256); |
| @@ -2122,31 +2127,25 @@ usage: (ccl-execute-on-string CCL-PROGRAM STATUS STRING &optional CONTINUE UNIBY | |||
| 2122 | src_size = j; | 2127 | src_size = j; |
| 2123 | while (1) | 2128 | while (1) |
| 2124 | { | 2129 | { |
| 2130 | int max_expansion = NILP (unibyte_p) ? MAX_MULTIBYTE_LENGTH : 1; | ||
| 2131 | ptrdiff_t offset, shortfall; | ||
| 2125 | ccl_driver (&ccl, src, destination, src_size, CCL_EXECUTE_BUF_SIZE, | 2132 | ccl_driver (&ccl, src, destination, src_size, CCL_EXECUTE_BUF_SIZE, |
| 2126 | Qnil); | 2133 | Qnil); |
| 2127 | produced_chars += ccl.produced; | 2134 | produced_chars += ccl.produced; |
| 2135 | offset = outp - outbuf; | ||
| 2136 | shortfall = ccl.produced * max_expansion - (outbufsize - offset); | ||
| 2137 | if (0 < shortfall) | ||
| 2138 | { | ||
| 2139 | outbuf = xpalloc (outbuf, &outbufsize, shortfall, -1, 1); | ||
| 2140 | outp = outbuf + offset; | ||
| 2141 | } | ||
| 2128 | if (NILP (unibyte_p)) | 2142 | if (NILP (unibyte_p)) |
| 2129 | { | 2143 | { |
| 2130 | if (outp - outbuf + MAX_MULTIBYTE_LENGTH * ccl.produced | ||
| 2131 | > outbufsize) | ||
| 2132 | { | ||
| 2133 | EMACS_INT offset = outp - outbuf; | ||
| 2134 | outbufsize += MAX_MULTIBYTE_LENGTH * ccl.produced; | ||
| 2135 | outbuf = (unsigned char *) xrealloc (outbuf, outbufsize); | ||
| 2136 | outp = outbuf + offset; | ||
| 2137 | } | ||
| 2138 | for (j = 0; j < ccl.produced; j++) | 2144 | for (j = 0; j < ccl.produced; j++) |
| 2139 | CHAR_STRING_ADVANCE (destination[j], outp); | 2145 | CHAR_STRING_ADVANCE (destination[j], outp); |
| 2140 | } | 2146 | } |
| 2141 | else | 2147 | else |
| 2142 | { | 2148 | { |
| 2143 | if (outp - outbuf + ccl.produced > outbufsize) | ||
| 2144 | { | ||
| 2145 | EMACS_INT offset = outp - outbuf; | ||
| 2146 | outbufsize += ccl.produced; | ||
| 2147 | outbuf = (unsigned char *) xrealloc (outbuf, outbufsize); | ||
| 2148 | outp = outbuf + offset; | ||
| 2149 | } | ||
| 2150 | for (j = 0; j < ccl.produced; j++) | 2149 | for (j = 0; j < ccl.produced; j++) |
| 2151 | *outp++ = destination[j]; | 2150 | *outp++ = destination[j]; |
| 2152 | } | 2151 | } |