オペランドに文字定数が指定された場合の動作を修正
[YACASL2.git] / src / token.c
index c46c9f2..aa0a620 100644 (file)
@@ -10,14 +10,14 @@ OPD *opdtok(const char *str)
     bool quoting = false;
 
     opd->opdc = 0;
-    if(str == NULL || strlen(str) == 0) {
+    if(str == NULL) {
         return opd;
     }
     p = q = strdup(str);
     do {
         /* オペランド数が多すぎる場合はエラー */
         if(opd->opdc >= OPDSIZE) {
-            setcerr(117, NULL);    /* operand is too many */
+            setcerr(117, str);    /* operand is too many */
             break;
         }
         /* 先頭が「=」の場合の処理 */
@@ -29,6 +29,11 @@ OPD *opdtok(const char *str)
             quoting = !quoting;
         }
         if(quoting == true) {
+            /* 閉じ「'」がないまま文字列が終了した場合 */
+            if(*q == '\0') {
+                setcerr(123, str);    /* illegal string */
+                break;
+            }
             q++;
         } else {
             sepp = q + strcspn(q, ", ");
@@ -38,7 +43,7 @@ OPD *opdtok(const char *str)
                 setcerr(121, NULL);    /* cannot get operand token */
                 break;
             }
-            if(strlen(p) > OPDSIZE + 1) {
+            if(strlen(p) > OPDSIZE + 2) {    /* OPDSIZE + 「'」2文字分 */
                 setcerr(118, p);    /* operand length is too long */
                 break;
             }