X-Git-Url: http://j8takagi.net/cgi-bin/gitweb.cgi?p=YACASL2.git;a=blobdiff_plain;f=src%2Ftoken.c;h=074b6c41b2e2de365d5cbdf27544adcff4b09733;hp=dac982fdfcd21f8b71fbcf0e97763835485cce05;hb=8993a52e06e3f33aad16c8bb842f62307cae8063;hpb=80d4fc2d9a7022362c88cac0adbddd32ce7a3a62 diff --git a/src/token.c b/src/token.c index dac982f..074b6c4 100644 --- a/src/token.c +++ b/src/token.c @@ -50,7 +50,7 @@ OPD *opdtok(const char *str) do { /* オペランド数が多すぎる場合はエラー */ if(opd->opdc >= OPDSIZE) { - setcerr(117, NULL); /* operand is too many */ + setcerr(117, ""); /* operand is too many */ break; } /* 先頭が等号(=)の場合 */ @@ -80,11 +80,11 @@ OPD *opdtok(const char *str) sepc = *sepp; *sepp = '\0'; if(*q == '\0') { - setcerr(121, NULL); /* cannot get operand token */ + setcerr(121, ""); /* cannot get operand token */ break; } if(strlen(q) - rcnt > OPDSIZE) { - setcerr(118, NULL); /* operand length is too long */ + setcerr(118, ""); /* operand length is too long */ break; } opd->opdv[(++opd->opdc)-1] = strdup_chk(q, "opd.opdv[]"); @@ -122,16 +122,17 @@ CMDLINE *linetok(const char *line) if(*tokens != '\n' && *tokens != '\0') { p = tokens; cmdl = malloc_chk(sizeof(CMDLINE), "cmdl"); + cmdl->label = malloc_chk(LABELSIZE + 1, "cmdl.label"); /* ラベルの取得。行の先頭が空白またはタブの場合、ラベルは空 */ if((sepp = p + strcspn(p, " \t\n")) == p){ - cmdl->label = NULL; + *(cmdl->label) = '\0'; } else { /* ラベルを取得 */ *sepp = '\0'; /* 文字列が長すぎる場合はエラー */ if(strlen(p) > LABELSIZE) { setcerr(104, p); /* label length is too long */ } - cmdl->label = strdup_chk(p, "cmdl.label"); + strcpy(cmdl->label, p); p = sepp + 1; } /* ラベルと命令の間の空白をスキップ */ @@ -140,9 +141,10 @@ CMDLINE *linetok(const char *line) } /* 命令とオペランドの取得 */ if(*p == '\n' || *p == '\0') { /* 命令がない場合は、終了 */ - if(cmdl->label != NULL) { /* ラベルが定義されていて命令がない場合はエラー */ - setcerr(105, NULL); /* no command in the line */ + if(*(cmdl->label) != '\0') { /* ラベルが定義されていて命令がない場合はエラー */ + setcerr(105, ""); /* no command in the line */ } + FREE(cmdl->label); FREE(cmdl); } else { /* 命令の取得 */