From 9a48fd93fe01972f0de42c6349e2e8a8160ec5df Mon Sep 17 00:00:00 2001 From: j8takagi Date: Thu, 28 Apr 2011 00:46:11 +0900 Subject: [PATCH] =?utf8?q?=E3=83=A9=E3=83=99=E3=83=AB=E3=81=8C=E7=A9=BA?= =?utf8?q?=E3=81=AE=E3=81=A8=E3=81=8D=E3=80=81=E5=A4=89=E6=95=B0=E3=81=ABN?= =?utf8?q?ULL=E3=81=A7=E3=81=AF=E3=81=AA=E3=81=8F'\0'=E3=82=92=E8=A8=AD?= =?utf8?q?=E5=AE=9A=E3=81=99=E3=82=8B=E3=82=88=E3=81=86=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- src/assemble.c | 20 ++++++++++---------- src/label.c | 2 +- src/token.c | 7 ++++--- 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/assemble.c b/src/assemble.c index 343aa52..23ce8ac 100644 --- a/src/assemble.c +++ b/src/assemble.c @@ -82,7 +82,7 @@ static CMD ascmd[] = { { "END", assemble_end }, { "DS", assemble_ds }, { "DC", assemble_dc }, - { NULL, NULL } + { "", NULL } }; /** @@ -93,7 +93,7 @@ static CMD macrocmd[] = { { "IN", assemble_in }, { "RPUSH", assemble_rpush }, { "RPOP", assemble_rpop }, - { NULL, NULL } + { "", NULL } }; /** @@ -257,7 +257,7 @@ void assemble_start(const CMDLINE *cmdl, PASS pass) setcerr(106, ""); /* operand count mismatch */ return; } - if(cmdl->label == NULL) { + if(cmdl->label == '\0') { setcerr(107, ""); /* no label in START */ return; } @@ -468,7 +468,7 @@ bool casl2cmd(CMD *cmdtbl, const CMDLINE *cmdl, PASS pass) { int i; void (*cmdptr)(); - for(i = 0; cmdtbl[i].name != NULL; i++) { + for(i = 0; *(cmdtbl[i].name) != '\0'; i++) { if(strcmp(cmdl->cmd, cmdtbl[i].name) == 0) { cmdptr = cmdtbl[i].ptr; (*cmdptr)(cmdl, pass); @@ -575,7 +575,7 @@ bool assemble_comet2cmd(const CMDLINE *cmdl, PASS pass) bool assembletok(const CMDLINE *cmdl, PASS pass) { /* 命令がない場合 */ - if(cmdl->cmd == NULL) { + if(*(cmdl->cmd) == '\0') { return true; } /* アセンブラ命令またはマクロ命令の書込 */ @@ -604,14 +604,14 @@ bool assembleline(const char *line, PASS pass) stat = (cerr->num == 0) ? true : false; if(cmdl != NULL) { if(stat == true) { - if(pass == FIRST && cmdl->label != NULL) { + if(pass == FIRST && cmdl->label != '\0') { stat = addlabel(asptr->prog, cmdl->label, asptr->ptr); } - if(stat == true) { - stat = assembletok(cmdl, pass); - } - FREE(cmdl->label); } + if(stat == true) { + stat = assembletok(cmdl, pass); + } + FREE(cmdl->label); if(cmdl->opd != NULL) { for(i = 0; i < cmdl->opd->opdc; i++) { FREE(cmdl->opd->opdv[i]); diff --git a/src/label.c b/src/label.c index 5650a1f..efa52c3 100644 --- a/src/label.c +++ b/src/label.c @@ -59,7 +59,7 @@ unsigned labelhash(const char *prog, const char *label) */ WORD getlabel(const char *prog, const char *label) { - assert(label != NULL); + assert(prog != NULL && label != NULL); LABELTAB *p; for(p = labels[labelhash(prog, label)]; p != NULL; p = p->next) { diff --git a/src/token.c b/src/token.c index fb35c8b..d2242af 100644 --- a/src/token.c +++ b/src/token.c @@ -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(sizeof(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,7 +141,7 @@ CMDLINE *linetok(const char *line) } /* 命令とオペランドの取得 */ if(*p == '\n' || *p == '\0') { /* 命令がない場合は、終了 */ - if(cmdl->label != NULL) { /* ラベルが定義されていて命令がない場合はエラー */ + if(cmdl->label != '\0') { /* ラベルが定義されていて命令がない場合はエラー */ setcerr(105, ""); /* no command in the line */ } FREE(cmdl); -- 2.18.0