}
msglen = strlen (msg);
- if (dst + msglen <= dst_end)
+ if (msglen <= dst_end - dst)
{
for (i = 0; i < msglen; i++)
*dst++ = msg[i];
#define CCL_EXECUTE_BUF_SIZE 1024
int source[CCL_EXECUTE_BUF_SIZE], destination[CCL_EXECUTE_BUF_SIZE];
ptrdiff_t consumed_chars, consumed_bytes, produced_chars;
+ int buf_magnification;
if (setup_ccl_program (&ccl, ccl_prog) < 0)
error ("Invalid CCL program");
ccl.ic = i;
}
- if (((min (PTRDIFF_MAX, SIZE_MAX) - 256)
- / (ccl.buf_magnification ? ccl.buf_magnification : 1))
- < str_bytes)
+ buf_magnification = ccl.buf_magnification ? ccl.buf_magnification : 1;
+
+ if ((min (PTRDIFF_MAX, SIZE_MAX) - 256) / buf_magnification < str_bytes)
memory_full (SIZE_MAX);
outbufsize = (ccl.buf_magnification
? str_bytes * ccl.buf_magnification + 256
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))
{
- ptrdiff_t offset = outp - outbuf;
- if ((outbufsize - offset) / MAX_MULTIBYTE_LENGTH < ccl.produced)
- {
- ptrdiff_t produced;
- if (((min (PTRDIFF_MAX, SIZE_MAX) - outbufsize)
- / MAX_MULTIBYTE_LENGTH)
- < ccl.produced)
- {
- xfree (outbuf);
- memory_full (SIZE_MAX);
- }
- produced = ccl.produced;
- outbufsize += MAX_MULTIBYTE_LENGTH * produced;
- outbuf = (unsigned char *) xrealloc (outbuf, outbufsize);
- outp = outbuf + offset;
- }
for (j = 0; j < ccl.produced; j++)
CHAR_STRING_ADVANCE (destination[j], outp);
}
else
{
- ptrdiff_t offset = outp - outbuf;
- if (outbufsize - offset < ccl.produced)
- {
- if (min (PTRDIFF_MAX, SIZE_MAX) - outbufsize < ccl.produced)
- {
- xfree (outbuf);
- memory_full (SIZE_MAX);
- }
- outbufsize += ccl.produced;
- outbuf = (unsigned char *) xrealloc (outbuf, outbufsize);
- outp = outbuf + offset;
- }
for (j = 0; j < ccl.produced; j++)
*outp++ = destination[j];
}