From: j8takagi Date: Wed, 27 Apr 2011 15:22:24 +0000 (+0900) Subject: progが設定されていない場合、変数にNULLではなく'\0'を設定して判定するよう変更 X-Git-Tag: v0.1p45~2 X-Git-Url: http://j8takagi.net/cgi-bin/gitweb.cgi?p=YACASL2.git;a=commitdiff_plain;h=176a22fd90e39acf9b4bdae260d71b8d31be6db0 progが設定されていない場合、変数にNULLではなく'\0'を設定して判定するよう変更 --- diff --git a/src/assemble.c b/src/assemble.c index 989173f..c53ad5b 100644 --- a/src/assemble.c +++ b/src/assemble.c @@ -128,8 +128,8 @@ WORD getadr(const char *prog, const char *str, PASS pass) } else if(isdigit(*str) || *str == '-' || *str == '#') { adr = nh2word(str); } else { - if(pass == SECOND && (adr = getlabel(prog, str)) == 0xFFFF) { - if(prog != NULL) { + if(pass == SECOND) { + if((adr = getlabel(prog, str)) == 0xFFFF) { setcerr(103, str); /* label not found */ } } @@ -263,7 +263,7 @@ void assemble_start(const CMDLINE *cmdl, PASS pass) return; } /* プログラム名の設定 */ - asptr->prog = strdup_chk(cmdl->label, "asptr.prog"); + strcpy(asptr->prog, cmdl->label); /* オペランドがある場合、実行開始アドレスを設定 */ if(pass == SECOND && cmdl->opd->opdv[0] != NULL) { if((execptr->start = getlabel(asptr->prog, cmdl->opd->opdv[0])) == 0xFFFF) { @@ -290,7 +290,7 @@ void assemble_end(const CMDLINE *cmdl, PASS pass) else if(pass == SECOND) { execptr->end = asptr->lptr; } - FREE(asptr->prog); + *(asptr->prog) = '\0'; } /** @@ -558,7 +558,7 @@ bool assemble_comet2cmd(const CMDLINE *cmdl, PASS pass) /* CALL以外の命令の場合と、プログラムの入口名を取得できない場合は、 */ /* 同一プログラム内のラベルを取得 */ if(pass == SECOND && cmd == 0x8000) { /* CALL命令 */ - adr = getlabel(NULL, cmdl->opd->opdv[0]); + adr = getlabel("", cmdl->opd->opdv[0]); } if(cmd != 0x8000 || (pass == SECOND && adr == 0xFFFF)) { adr = getadr(asptr->prog, cmdl->opd->opdv[0], pass); diff --git a/src/casl2.c b/src/casl2.c index d510e9f..b1430ff 100644 --- a/src/casl2.c +++ b/src/casl2.c @@ -65,6 +65,7 @@ void assemble(int filec, char *filev[]) create_cmdtype_code(); /* 命令の名前とタイプがキーのハッシュ表を作成 */ asptr = malloc_chk(sizeof(ASPTR), "asptr"); /* アセンブル時のプロパティ用の領域確保 */ + asptr->prog = malloc_chk(sizeof(LABELSIZE + 1), "asptr.prog"); asptr->ptr = 0; /* アセンブル。ラベル表作成のため、2回行う */ for(pass = FIRST; pass <= SECOND; pass++) { @@ -96,7 +97,8 @@ void assemble(int filec, char *filev[]) asfin: freelabel(); /* ラベルハッシュ表を解放 */ free_cmdtype_code(); /* 命令の名前とタイプがキーのハッシュ表を解放 */ - FREE(asptr); /* アセンブル時のプロパティを解放 */ + FREE(asptr->prog); /* アセンブル時のプロパティを解放 */ + FREE(asptr); } /** diff --git a/src/label.c b/src/label.c index 85fb172..5650a1f 100644 --- a/src/label.c +++ b/src/label.c @@ -37,7 +37,7 @@ unsigned labelhash(const char *prog, const char *label) int i = 0, j; unsigned h; - if(prog != NULL) { + if(*prog != '\0') { keys[i] = malloc_chk(sizeof(HKEY), "labelhash.key"); keys[i]->type = CHARS; keys[i]->val.s = strdup_chk(prog, "labelhash.key.val"); @@ -63,7 +63,7 @@ WORD getlabel(const char *prog, const char *label) LABELTAB *p; for(p = labels[labelhash(prog, label)]; p != NULL; p = p->next) { - if((prog == NULL || (p->prog != NULL && strcmp(prog, p->prog) == 0)) && + if((*prog == '\0' || (strcmp(prog, p->prog) == 0)) && strcmp(label, p->label) == 0) { return p->adr; @@ -89,11 +89,7 @@ bool addlabel(const char *prog, const char *label, WORD adr) /* メモリを確保 */ p = malloc_chk(sizeof(LABELTAB), "labels.next"); /* プログラム名を設定 */ - if(prog == NULL) { - p->prog = NULL; - } else { - p->prog = strdup_chk(prog, "labels.prog"); - } + p->prog = strdup_chk(prog, "labels.prog"); /* ラベルを設定 */ p->label = strdup_chk(label, "labels.label"); /* アドレスを設定 */ @@ -129,18 +125,14 @@ void printlabel() for(p = labels[i]; p != NULL; p = p->next) { assert(p->label != NULL); l[s] = malloc_chk(sizeof(LABELARRAY), "lables"); - if(p->prog == NULL) { - l[s]->prog = NULL; - } else { - l[s]->prog = strdup_chk(p->prog, "labels.prog"); - } + l[s]->prog = strdup_chk(p->prog, "labels.prog"); l[s]->label = strdup_chk(p->label, "labels.label"); l[s++]->adr = p->adr; } } qsort(l, s, sizeof(*l), compare_adr); for(i = 0; i < s; i++) { - if(l[i]->prog != NULL) { + if(*(l[i]->prog) != '\0') { fprintf(stdout, "%s.", l[i]->prog); } fprintf(stdout, "%s ---> #%04X\n", l[i]->label, l[i]->adr);