changeset 23280:b4656367043f

(CCL_WRITE_CHAR): Don't use bcopy. (ccl_driver): If BUFFER-MAGNIFICATION of the CCL program is 0, cause error if the program is going to output some bytes. When outputing a string to notify an error, check the case that DST_BYTES is zero.
author Kenichi Handa <handa@m17n.org>
date Fri, 18 Sep 1998 13:10:40 +0000
parents ca159e828a68
children e07d05f47832
files src/ccl.c
diffstat 1 files changed, 13 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/src/ccl.c	Fri Sep 18 13:10:40 1998 +0000
+++ b/src/ccl.c	Fri Sep 18 13:10:40 1998 +0000
@@ -670,8 +670,7 @@
 	int len = CHAR_STRING (ch, work, str);		\
 	if (dst + len <= (dst_bytes ? dst_end : src))	\
 	  {						\
-	    bcopy (str, dst, len);			\
-	    dst += len;					\
+	    while (len--) *dst++ = *str++;		\
 	  }						\
 	else						\
 	  CCL_SUSPEND (CCL_STAT_SUSPEND_BY_DST);	\
@@ -751,6 +750,9 @@
   if (ic >= ccl->eof_ic)
     ic = CCL_HEADER_MAIN;
 
+  if (ccl->buf_magnification ==0) /* We can't produce any bytes.  */
+    dst = NULL;
+
 #ifdef CCL_DEBUG
   ccl_backtrace_idx = 0;
 #endif
@@ -1543,6 +1545,9 @@
       char msg[256];
       int msglen;
 
+      if (!dst)
+	dst = destination;
+
       switch (ccl->status)
 	{
 	case CCL_STAT_INVALID_CMD:
@@ -1554,7 +1559,7 @@
 	    int j;
 
 	    msglen = strlen (msg);
-	    if (dst + msglen <= dst_end)
+	    if (dst + msglen <= (dst_bytes ? dst_end : src))
 	      {
 		bcopy (msg, dst, msglen);
 		dst += msglen;
@@ -1567,14 +1572,15 @@
 		  break;
 		sprintf(msg, " %d", ccl_backtrace_table[i]);
 		msglen = strlen (msg);
-		if (dst + msglen > dst_end)
+		if (dst + msglen > (dst_bytes ? dst_end : src))
 		  break;
 		bcopy (msg, dst, msglen);
 		dst += msglen;
 	      }
+	    goto ccl_finish;
 	  }
 #endif
-	  goto ccl_finish;
+	  break;
 
 	case CCL_STAT_QUIT:
 	  sprintf(msg, "\nCCL: Quited.");
@@ -1585,7 +1591,7 @@
 	}
 
       msglen = strlen (msg);
-      if (dst + msglen <= dst_end)
+      if (dst + msglen <= (dst_bytes ? dst_end : src))
 	{
 	  bcopy (msg, dst, msglen);
 	  dst += msglen;
@@ -1595,7 +1601,7 @@
  ccl_finish:
   ccl->ic = ic;
   if (consumed) *consumed = src - source;
-  return dst - destination;
+  return (dst ? dst - destination : 0);
 }
 
 /* Setup fields of the structure pointed by CCL appropriately for the