From: j8takagi Date: Fri, 18 Mar 2011 15:21:58 +0000 (+0900) Subject: malloc周りの修正 X-Git-Tag: v0.1p25~2 X-Git-Url: https://j8takagi.net/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=02d7b9b5209b2cb08151f7d1c160e2d18bc7c0d0;p=YACASL2.git malloc周りの修正 --- diff --git a/src/cerr.c b/src/cerr.c index 6b9ab40..ae35d57 100644 --- a/src/cerr.c +++ b/src/cerr.c @@ -10,7 +10,7 @@ */ void cerr_init() { - cerr = malloc_chk(sizeof(CERR *), "cerr"); + cerr = malloc_chk(sizeof(CERR), "cerr"); cerr->num = 0; } @@ -30,14 +30,14 @@ CERRLIST *cerrlist = NULL; void addcerrlist(int errc, CERR errv[]) { int i; - CERRLIST *p = NULL, *q = malloc_chk(sizeof(CERRLIST *), "cerrlist"); + CERRLIST *p = NULL, *q = malloc_chk(sizeof(CERRLIST), "cerrlist"); assert(errc > 0 && errv != NULL); for(i = 0; i < errc; i++) { if(p == NULL) { p = q; } else { - p = p->next = malloc_chk(sizeof(CERRLIST *), "cerrlist.next"); + p = p->next = malloc_chk(sizeof(CERRLIST), "cerrlist.next"); } p->cerr = &errv[i]; p->next = NULL; diff --git a/src/cmd.c b/src/cmd.c index f393c9a..effe26e 100644 --- a/src/cmd.c +++ b/src/cmd.c @@ -73,11 +73,11 @@ unsigned hash_cmdtype(const char *cmd, CMDTYPE type) unsigned hashval; /* 命令名を設定 */ - keys[0] = malloc_chk(sizeof(HKEY *), "hash_cmdtype.keys[0]"); + keys[0] = malloc_chk(sizeof(HKEY), "hash_cmdtype.keys[0]"); keys[0]->type = CHARS; keys[0]->val.s = strdup_chk(cmd, "keys[0].val.s"); /* 命令タイプを設定 */ - keys[1] = malloc_chk(sizeof(HKEY *), "hash_cmdtype.keys[1]"); + keys[1] = malloc_chk(sizeof(HKEY), "hash_cmdtype.keys[1]"); keys[1]->type = INT; keys[1]->val.i = (int)(type & 070); /* ハッシュ値の計算 */ @@ -99,9 +99,9 @@ bool create_cmdtype_code() int i; cmdtabsize = comet2cmdsize; /* ハッシュ表のサイズ */ - cmdtype_code = calloc_chk(cmdtabsize, sizeof(CMDTAB *), "cmdtype_code"); + cmdtype_code = calloc_chk(cmdtabsize, sizeof(CMDTAB), "cmdtype_code"); for(i = 0; i < comet2cmdsize; i++) { - p = malloc_chk(sizeof(CMDTAB *), "create_cmdtype_code.p"); + p = malloc_chk(sizeof(CMDTAB), "create_cmdtype_code.p"); hashval = hash_cmdtype(comet2cmd[i].name, comet2cmd[i].type); /* ハッシュ値の生成 */ p->next = cmdtype_code[hashval]; /* ハッシュ表に値を追加 */ p->cmd = &comet2cmd[i]; @@ -154,7 +154,7 @@ unsigned hash_code(WORD code) unsigned h; /* 命令コードを設定 */ - keys[0] = malloc_chk(sizeof(HKEY *), "hash_code.key"); + keys[0] = malloc_chk(sizeof(HKEY), "hash_code.key"); keys[0]->type = INT; keys[0]->val.i = (int)(code >> 8); h = hash(1, keys, cmdtabsize); @@ -172,9 +172,9 @@ bool create_code_type() int i; cmdtabsize = comet2cmdsize; /* ハッシュ表のサイズ */ - code_type = calloc_chk(comet2cmdsize, sizeof(CMDTAB *), "code_type"); + code_type = calloc_chk(comet2cmdsize, sizeof(CMDTAB), "code_type"); for(i = 0; i < comet2cmdsize; i++) { - p = malloc_chk(sizeof(CMDTAB *), "code_type.p"); + p = malloc_chk(sizeof(CMDTAB), "code_type.p"); hashval = hash_code((&comet2cmd[i])->code); /* ハッシュ値の生成 */ p->next = code_type[hashval]; /* ハッシュ表に値を追加 */ p->cmd = &comet2cmd[i]; diff --git a/src/exec.c b/src/exec.c index feb735c..5d8f62f 100644 --- a/src/exec.c +++ b/src/exec.c @@ -147,7 +147,7 @@ static WORD adda(WORD val0, WORD val1) sys->cpu->fr = 0x0; /* 引数の値を16ビット符号付整数として加算し、オーバーフローをチェック */ - assert(sizeof(short)*8 == 16 && (short)0xFFFF == -1); + assert(sizeof(short) * 8 == 16 && (short)0xFFFF == -1); if((tmp = (short)val0 + (short)val1) > 32767 || tmp < -32768) { sys->cpu->fr += OF; } diff --git a/src/struct.c b/src/struct.c index 725ca00..30323eb 100644 --- a/src/struct.c +++ b/src/struct.c @@ -32,7 +32,7 @@ void reset(int memsize, int clocks) } sys->cpu->sp = sys->cpu->pr = sys->cpu->fr = 0x0; /* CASL2プログラムの開始と終了のアドレスを初期化 */ - execptr = malloc_chk(sizeof(EXECPTR *), "prog"); + execptr = malloc_chk(sizeof(EXECPTR), "prog"); } /** diff --git a/src/token.c b/src/token.c index ce2a69b..a8e5c8e 100644 --- a/src/token.c +++ b/src/token.c @@ -159,7 +159,7 @@ CMDLINE *linetok(const char *line) *sepp = '\0'; cmdl->opd = opdtok(p); } else { - cmdl->opd = malloc_chk(sizeof(OPD *), "cmdl.opd"); + cmdl->opd = malloc_chk(sizeof(OPD), "cmdl.opd"); cmdl->opd->opdc = 0; } } diff --git a/src/word.c b/src/word.c index 925946b..415dfa4 100644 --- a/src/word.c +++ b/src/word.c @@ -53,7 +53,7 @@ WORD h2word(const char *str) { assert(*str == '#'); - WORD word = 0x0; + WORD w = 0x0; char *check; str++; if(*str == '-' || strlen(str) > 4) { @@ -61,12 +61,12 @@ WORD h2word(const char *str) return 0; } /* WORD値に変換 */ - word = (WORD)strtol(str, &check, 16); + w = (WORD)strtol(str, &check, 16); if(*check != '\0') { setcerr(115, str-1); /* not hex */ return 0x0; } - return word; + return w; } /** @@ -74,20 +74,19 @@ WORD h2word(const char *str) */ WORD nh2word(const char *str) { - assert(sizeof(WORD)*8 == 16); /* WORD型のサイズが16ビットであることを確認 */ - - WORD word; + WORD w; + assert(sizeof(WORD) * 8 == 16); /* WORD型のサイズが16ビットであることを確認 */ if(!isdigit(*str) && *str != '-' && *str != '#') { setcerr(114, str); /* not integer */ return 0x0; } if(*str == '#') { - word = h2word(str); + w = h2word(str); } else { - word = n2word(str); + w = n2word(str); } - return word; + return w; } /**