From: j8takagi Date: Tue, 5 Mar 2019 13:41:51 +0000 (+0900) Subject: ソースコードの推敲 X-Git-Tag: v0.5p14 X-Git-Url: https://j8takagi.net/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b4050c46133a58386b6ff3962357a56cf84a19aa;p=YACASL2.git ソースコードの推敲 --- diff --git a/VERSION b/VERSION index 446eb86..2609bed 100644 --- a/VERSION +++ b/VERSION @@ -1,2 +1,2 @@ -v0.5p13 +v0.5p14 diff --git a/src/assemble.c b/src/assemble.c index e982082..e45bb84 100644 --- a/src/assemble.c +++ b/src/assemble.c @@ -412,7 +412,7 @@ void writestr(const char *str, bool literal, PASS pass) void writedc(const char *str, PASS pass) { - WORD adr = 0x0; + WORD adr = 0; if(*str == '\'') { writestr(str, false, pass); @@ -493,9 +493,8 @@ void assemble_dc(const CMDLINE *cmdl, PASS pass) void assemble_in(const CMDLINE *cmdl, PASS pass) { - char *line = NULL; + char *line = malloc_chk(LINESIZE + 1, "assemble_in.line"); - line = malloc_chk(LINESIZE + 1, "assemble_in.line"); if(cmdl->opd->opdc == 0 || cmdl->opd->opdc > 2) { setcerr(106, ""); /* operand count mismatch */ return; @@ -514,9 +513,8 @@ void assemble_in(const CMDLINE *cmdl, PASS pass) void assemble_out(const CMDLINE *cmdl, PASS pass) { - char *line = NULL; + char *line = malloc_chk(LINESIZE + 1, "assemble_out.line"); - line = malloc_chk(LINESIZE + 1, "assemble_out.line"); if(cmdl->opd->opdc == 0 || cmdl->opd->opdc > 2) { setcerr(106, ""); /* operand count mismatch */ return; @@ -538,9 +536,8 @@ void assemble_out(const CMDLINE *cmdl, PASS pass) void assemble_rpush(const CMDLINE *cmdl, PASS pass) { - char *line = NULL; + char *line = malloc_chk(LINESIZE + 1, "assemble_rpush.line"); - line = malloc_chk(LINESIZE + 1, "assemble_rpush.line"); if(cmdl->opd->opdc > 0) { setcerr(106, ""); /* operand count mismatch */ return; @@ -554,9 +551,8 @@ void assemble_rpush(const CMDLINE *cmdl, PASS pass) void assemble_rpop(const CMDLINE *cmdl, PASS pass) { - char *line = NULL; + char *line = malloc_chk(LINESIZE + 1, "assemble_rpop.line"); - line = malloc_chk(LINESIZE + 1, "assemble_rpop.line"); if(cmdl->opd->opdc > 0) { setcerr(106, ""); /* operand count mismatch */ return; diff --git a/src/exec.c b/src/exec.c index 65bd3a7..8df0765 100644 --- a/src/exec.c +++ b/src/exec.c @@ -297,10 +297,11 @@ void suba_r1_r2() void addl_gr(WORD r, WORD val, bool add) { - unsigned long o, s; + unsigned long o = 0; + unsigned long s = 0; o = sys->cpu->gr[r]; - sys->cpu->fr = 0x0; /* flag initialize */ + sys->cpu->fr = 0; /* flag initialize */ if(add == true) { s = o + val; diff --git a/src/monitor.c b/src/monitor.c index d923771..8ad69ce 100644 --- a/src/monitor.c +++ b/src/monitor.c @@ -88,11 +88,11 @@ bool delbps(WORD adr) void listbps() { - int i, cnt = 0; + int cnt = 0; BPSLIST *p = NULL; fprintf(stdout, "List of breakpoints\n"); - for(i = 0; i < BPSTABSIZE; i++) { + for(int i = 0; i < BPSTABSIZE; i++) { for(p = bps[i]; p != NULL; p = p->next) { fprintf(stdout, "#%04X\n", p->adr); cnt++; diff --git a/src/word.c b/src/word.c index 1c1f845..4f42d62 100644 --- a/src/word.c +++ b/src/word.c @@ -102,20 +102,20 @@ WORD nh2word(const char *str) char *word2n(WORD word) { enum { - MAXLEN = 5, /* WORD値を10進数で表したときの最大桁数 */ + MAXLEN = 5, /* WORD値を10進数で表したときの最大けた数 */ }; - char *n = malloc_chk(MAXLEN + 1, "word2n.n"), tmp; - int i = 0, j; + char *n = malloc_chk(MAXLEN + 1, "word2n.n"); + int d = 0; /* けた数 */ do{ - n[i++] = word % 10 + '0'; + n[d++] = word % 10 + '0'; } while((word /= 10) > 0); - for(j = 0; j < i; j++) { - tmp = n[j]; - n[j] = n[(i-1)-j]; - n[(i-1)-j] = tmp; + for(int i = 0; i < d; i++) { + char tmp = n[i]; + n[i] = n[(d-1)-i]; + n[(d-1)-i] = tmp; } - n[j] = '\0'; + n[d] = '\0'; return n; }