Commit a37520c6 authored by Kenichi Handa's avatar Kenichi Handa

(CCL_WRITE_CHAR): Check variable `extra_bytes'.

(ccl_driver): New local variable `extra_bytes'.
parent 9371f831
...@@ -698,26 +698,26 @@ static int stack_idx_of_map_multiple; ...@@ -698,26 +698,26 @@ static int stack_idx_of_map_multiple;
/* Encode one character CH to multibyte form and write to the current /* Encode one character CH to multibyte form and write to the current
output buffer. If CH is less than 256, CH is written as is. */ output buffer. If CH is less than 256, CH is written as is. */
#define CCL_WRITE_CHAR(ch) \ #define CCL_WRITE_CHAR(ch) \
do { \ do { \
int bytes = SINGLE_BYTE_CHAR_P (ch) ? 1: CHAR_BYTES (ch); \ int bytes = SINGLE_BYTE_CHAR_P (ch) ? 1: CHAR_BYTES (ch); \
if (!dst) \ if (!dst) \
CCL_INVALID_CMD; \ CCL_INVALID_CMD; \
else if (dst + bytes <= (dst_bytes ? dst_end : src)) \ else if (dst + bytes + extra_bytes < (dst_bytes ? dst_end : src)) \
{ \ { \
if (bytes == 1) \ if (bytes == 1) \
{ \ { \
*dst++ = (ch); \ *dst++ = (ch); \
if ((ch) >= 0x80 && (ch) < 0xA0) \ if ((ch) >= 0x80 && (ch) < 0xA0) \
/* We may have to convert this eight-bit char to \ /* We may have to convert this eight-bit char to \
multibyte form later. */ \ multibyte form later. */ \
dst_end--; \ extra_bytes++; \
} \ } \
else \ else \
dst += CHAR_STRING (ch, dst); \ dst += CHAR_STRING (ch, dst); \
} \ } \
else \ else \
CCL_SUSPEND (CCL_STAT_SUSPEND_BY_DST); \ CCL_SUSPEND (CCL_STAT_SUSPEND_BY_DST); \
} while (0) } while (0)
/* Write a string at ccl_prog[IC] of length LEN to the current output /* Write a string at ccl_prog[IC] of length LEN to the current output
...@@ -840,6 +840,11 @@ ccl_driver (ccl, source, destination, src_bytes, dst_bytes, consumed) ...@@ -840,6 +840,11 @@ ccl_driver (ccl, source, destination, src_bytes, dst_bytes, consumed)
int stack_idx = ccl->stack_idx; int stack_idx = ccl->stack_idx;
/* Instruction counter of the current CCL code. */ /* Instruction counter of the current CCL code. */
int this_ic; int this_ic;
/* CCL_WRITE_CHAR will produce 8-bit code of range 0x80..0x9F. But,
each of them will be converted to multibyte form of 2-byte
sequence. For that conversion, we remember how many more bytes
we must keep in DESTINATION in this variable. */
int extra_bytes = 0;
if (ic >= ccl->eof_ic) if (ic >= ccl->eof_ic)
ic = CCL_HEADER_MAIN; ic = CCL_HEADER_MAIN;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment