Merge remote-tracking branch 'origin/master' into for-steve
[sxemacs] / src / mule / mule-ccl.c
index 56a3db4..a158776 100644 (file)
@@ -95,7 +95,7 @@ Lisp_Object Vccl_program_table;
               cccccccccccccccccccc          rrr       XXXXX
   or
        |------------- constant or other args ----------------|
-                     cccccccccccccccccccccccccccc
+                    cccccccccccccccccccccccccccc
 
    where, `cc...c' is a non-negative integer indicating constant value
    (the left most `c' is always 0) or an absolute jump address, `RRR'
@@ -674,8 +674,8 @@ static int stack_idx_of_map_multiple;
                                   r[7] = LOWER_BYTE (SJIS (Y, Z) */
 
 /* Terminate CCL program successfully.  */
-#define CCL_SUCCESS                    \
-  do {                                 \
+#define CCL_SUCCESS                    \
+  do {                                 \
     ccl->status = CCL_STAT_SUCCESS;    \
   /* The "if (1)" inhibits the warning \
      "end-of loop code not reached" */ \
@@ -696,8 +696,8 @@ static int stack_idx_of_map_multiple;
 
 /* Terminate CCL program because of invalid command.  Should not occur
    in the normal case.  */
-#define CCL_INVALID_CMD                        \
-  do {                                 \
+#define CCL_INVALID_CMD                        \
+  do {                                 \
     ccl->status = CCL_STAT_INVALID_CMD;        \
   /* The "if (1)" inhibits the warning \
      "end-of loop code not reached" */ \
@@ -959,7 +959,7 @@ ccl_driver(struct ccl_program *ccl,
                case CCL_SetArray:      /* CCCCCCCCCCCCCCCCCCCCRRRrrrXXXXX */
                        i = reg[RRR];
                        j = field1 >> 3;
-                       if ((unsigned int)i < j)
+                       if (i < j)
                                reg[rrr] = XINT(ccl_prog[ic + i]);
                        ic += j;
                        break;
@@ -1011,7 +1011,7 @@ ccl_driver(struct ccl_program *ccl,
                case CCL_WriteArrayReadJump:    /* A--D--D--R--E--S--S-rrrXXXXX */
                        i = reg[rrr];
                        j = XINT(ccl_prog[ic]);
-                       if ((unsigned int)i < j) {
+                       if (i < j) {
                                i = XINT(ccl_prog[ic + 1 + i]);
                                CCL_WRITE_CHAR(i);
                        }
@@ -1029,7 +1029,7 @@ ccl_driver(struct ccl_program *ccl,
                        CCL_READ_CHAR(reg[rrr]);
                        /* fall through ... */
                case CCL_Branch:        /* CCCCCCCCCCCCCCCCCCCCrrrXXXXX */
-                       if ((unsigned int)reg[rrr] < field1)
+                       if (reg[rrr] < field1)
                                ic += XINT(ccl_prog[ic + reg[rrr]]);
                        else
                                ic += XINT(ccl_prog[ic + field1]);
@@ -1129,7 +1129,7 @@ ccl_driver(struct ccl_program *ccl,
 
                case CCL_WriteArray:    /* CCCCCCCCCCCCCCCCCCCCrrrXXXXX */
                        i = reg[rrr];
-                       if ((unsigned int)i < field1) {
+                       if (i < field1) {
                                j = XINT(ccl_prog[ic + i]);
                                CCL_WRITE_CHAR(j);
                        }
@@ -1934,12 +1934,13 @@ ccl_driver(struct ccl_program *ccl,
                   specified and we still have a room to store the message
                   there.  */
                char msg[256];
-
+               int sz;
                switch (ccl->status) {
                case CCL_STAT_INVALID_CMD:
-                       sprintf(msg,
-                               "\nCCL: Invalid command %x (ccl_code = %x) at %d.",
-                               code & 0x1F, code, this_ic);
+                       sz = snprintf(msg, sizeof(msg),
+                                    "\nCCL: Invalid command %x (ccl_code = %x) at %d.",
+                                    code & 0x1F, code, this_ic);
+                       assert(sz >= 0 && sz < sizeof(msg));
 #ifdef CCL_DEBUG
                        {
                                int i = ccl_backtrace_idx - 1;
@@ -1955,8 +1956,9 @@ ccl_driver(struct ccl_program *ccl,
                                                i = CCL_DEBUG_BACKTRACE_LEN - 1;
                                        if (ccl_backtrace_table[i] == 0)
                                                break;
-                                       sprintf(msg, " %d",
-                                               ccl_backtrace_table[i]);
+                                       sz = snprintf(msg, sizeof(msg), " %d",
+                                                     ccl_backtrace_table[i]);
+                                       assert(sz >= 0 && sz < sizeof(msg));
                                        Dynarr_add_many(destination,
                                                        (unsigned char *)msg,
                                                        strlen(msg));
@@ -1967,12 +1969,14 @@ ccl_driver(struct ccl_program *ccl,
                        break;
 
                case CCL_STAT_QUIT:
-                       sprintf(msg, "\nCCL: Exited.");
+                       sz = snprintf(msg, sizeof(msg), "\nCCL: Exited.");
+                       assert(sz >= 0 && sz < sizeof(msg));
                        break;
 
                default:
-                       sprintf(msg, "\nCCL: Unknown error type (%d).",
-                               ccl->status);
+                       sz = snprintf(msg, sizeof(msg), "\nCCL: Unknown error type (%d).",
+                                     ccl->status);
+                       assert(sz >= 0 && sz < sizeof(msg));
                }
 
                Dynarr_add_many(destination, (unsigned char *)msg, strlen(msg));