From: j8takagi Date: Wed, 27 Apr 2011 15:31:27 +0000 (+0900) Subject: エラー文字列が空のとき、変数にNULLではなく'\0'を設定するよう変更 X-Git-Tag: v0.1p45~1 X-Git-Url: http://j8takagi.net/cgi-bin/gitweb.cgi?p=YACASL2.git;a=commitdiff_plain;h=f8636262f5c60efbb9d1c608e2276d359bc348a0 エラー文字列が空のとき、変数にNULLではなく'\0'を設定するよう変更 --- diff --git a/src/assemble.c b/src/assemble.c index c53ad5b..343aa52 100644 --- a/src/assemble.c +++ b/src/assemble.c @@ -144,7 +144,6 @@ WORD getadr(const char *prog, const char *str, PASS pass) */ WORD getgr(const char *str, bool is_x) { - assert(str != NULL); WORD r; /* "GR[0-7]" 以外の文字列では、0xFFFFを返して終了 */ @@ -156,7 +155,7 @@ WORD getgr(const char *str, bool is_x) r = (WORD)(*(str+2) - '0'); /* GR0は指標レジスタとして用いることができない */ if(is_x == true && r == 0x0) { - setcerr(120, NULL); /* GR0 in operand x */ + setcerr(120, ""); /* GR0 in operand x */ return 0x0; } return r; @@ -255,11 +254,11 @@ void writedc(const char *str, PASS pass) void assemble_start(const CMDLINE *cmdl, PASS pass) { if(cmdl->opd->opdc > 1) { - setcerr(106, NULL); /* operand count mismatch */ + setcerr(106, ""); /* operand count mismatch */ return; } if(cmdl->label == NULL) { - setcerr(107, NULL); /* no label in START */ + setcerr(107, ""); /* no label in START */ return; } /* プログラム名の設定 */ @@ -279,7 +278,7 @@ void assemble_start(const CMDLINE *cmdl, PASS pass) void assemble_end(const CMDLINE *cmdl, PASS pass) { if(cmdl->opd->opdc > 0) { - setcerr(106, NULL); /* operand count mismatch */ + setcerr(106, ""); /* operand count mismatch */ return; } /* 1回目のアセンブルの場合は、リテラル領域開始アドレスを設定 */ @@ -301,7 +300,7 @@ void assemble_ds(const CMDLINE *cmdl, PASS pass) { int i; if(cmdl->opd->opdc != 1) { - setcerr(106, NULL); /* operand count mismatch */ + setcerr(106, ""); /* operand count mismatch */ return; } for(i = 0; i < atoi(cmdl->opd->opdv[0]); i++) { @@ -320,7 +319,7 @@ void assemble_dc(const CMDLINE *cmdl, PASS pass) { int i; if(cmdl->opd->opdc == 0 || cmdl->opd->opdc >= OPDSIZE) { - setcerr(106, NULL); /* operand count mismatch */ + setcerr(106, ""); /* operand count mismatch */ return; } for(i = 0; i < cmdl->opd->opdc; i++) { @@ -348,7 +347,7 @@ void assemble_in(const CMDLINE *cmdl, PASS pass) { char *line = malloc_chk(LINESIZE + 1, "assemble_in.line"); if(cmdl->opd->opdc == 0 || cmdl->opd->opdc > 2) { - setcerr(106, NULL); /* operand count mismatch */ + setcerr(106, ""); /* operand count mismatch */ return; } assembleline(" PUSH 0,GR1", pass); @@ -383,7 +382,7 @@ void assemble_out(const CMDLINE *cmdl, PASS pass) { char *line = malloc_chk(LINESIZE + 1, "assemble_out.line"); if(cmdl->opd->opdc == 0 || cmdl->opd->opdc > 2) { - setcerr(106, NULL); /* operand count mismatch */ + setcerr(106, ""); /* operand count mismatch */ return; } assembleline(" PUSH 0,GR1", pass); @@ -419,7 +418,7 @@ void assemble_rpush(const CMDLINE *cmdl, PASS pass) int i; char *line = malloc_chk(LINESIZE + 1, "assemble_rpush.line"); if(cmdl->opd->opdc > 0) { - setcerr(106, NULL); /* operand count mismatch */ + setcerr(106, ""); /* operand count mismatch */ return; } for(i = 1; i <= GRSIZE-1; i++) { @@ -448,7 +447,7 @@ void assemble_rpop(const CMDLINE *cmdl, PASS pass) int i; char *line = malloc_chk(LINESIZE + 1, "assemble_rpop.line"); if(cmdl->opd->opdc > 0) { - setcerr(106, NULL); /* operand count mismatch */ + setcerr(106, ""); /* operand count mismatch */ return; } for(i = GRSIZE-1; i >= 1; i--) { diff --git a/src/casl2.c b/src/casl2.c index b1430ff..47490a1 100644 --- a/src/casl2.c +++ b/src/casl2.c @@ -169,7 +169,7 @@ int main(int argc, char *argv[]) } /* ソースファイルが指定されていない場合は終了 */ if(argv[optind] == NULL) { - setcerr(126, NULL); /* no source file */ + setcerr(126, ""); /* no source file */ fprintf(stderr, "CASL2 error - %d: %s\n", cerr->num, cerr->msg); exit(1); } diff --git a/src/cerr.c b/src/cerr.c index ae35d57..116312b 100644 --- a/src/cerr.c +++ b/src/cerr.c @@ -71,7 +71,7 @@ void setcerr(int num, const char *str) cerr->num = num; /* 現在のエラーメッセージを設定 */ cerr->msg = malloc_chk(CERRMSGSIZE + 1, "cerr.msg"); - if(str != NULL && strlen(str) <= CERRSTRSIZE) { + if(0 < strlen(str) && strlen(str) <= CERRSTRSIZE) { sprintf(cerr->msg, "%s: %s", str, getcerrmsg(cerr->num)); } else { strcpy(cerr->msg, getcerrmsg(cerr->num)); diff --git a/src/comet2.c b/src/comet2.c index f9eaa4e..1bdc3e9 100644 --- a/src/comet2.c +++ b/src/comet2.c @@ -62,7 +62,7 @@ int main(int argc, char *argv[]) } } if(argv[optind] == NULL) { - setcerr(211, NULL); /* object file not specified */ + setcerr(211, ""); /* object file not specified */ fprintf(stderr, "comet2 error - %d: %s\n", cerr->num, cerr->msg); exit(1); } diff --git a/src/exec.c b/src/exec.c index 73b30cd..caa8588 100644 --- a/src/exec.c +++ b/src/exec.c @@ -100,7 +100,7 @@ void svcin() break; } if(sys->cpu->gr[1] + i > execptr->end) { - setcerr(208, NULL); /* SVC input - memory overflow */ + setcerr(208, ""); /* SVC input - memory overflow */ break; } sys->memory[sys->cpu->gr[1]+i] = *(buffer + i); @@ -119,7 +119,7 @@ void svcout() for(i = 0; i < sys->memory[sys->cpu->gr[2]]; i++) { if(sys->cpu->gr[1] + i > execptr->end) { - setcerr(209, NULL); /* SVC output - memory overflow */ + setcerr(209, ""); /* SVC output - memory overflow */ return; } /* 「文字の組」の符号表に記載された文字と、改行(CR)/タブを表示 */ diff --git a/src/token.c b/src/token.c index dac982f..fb35c8b 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[]"); @@ -141,7 +141,7 @@ CMDLINE *linetok(const char *line) /* 命令とオペランドの取得 */ if(*p == '\n' || *p == '\0') { /* 命令がない場合は、終了 */ if(cmdl->label != NULL) { /* ラベルが定義されていて命令がない場合はエラー */ - setcerr(105, NULL); /* no command in the line */ + setcerr(105, ""); /* no command in the line */ } FREE(cmdl); } else {