From: j8takagi Date: Mon, 28 Feb 2011 15:31:38 +0000 (+0900) Subject: Ubuntu 10.04 PPC版で判明した問題を修正 X-Git-Tag: v0.1p20 X-Git-Url: http://j8takagi.net/cgi-bin/gitweb.cgi?p=YACASL2.git;a=commitdiff_plain;h=fd77389ef0a4c9c31228b5f71e9073a11ada9853;ds=sidebyside Ubuntu 10.04 PPC版で判明した問題を修正 実行時のエラー処理手順を整理、修正 cerr->msgを開放する時にSermantation Faultが発生するため、あらかじめcerr->msgをNULLにして現象回避 --- diff --git a/.gitignore b/.gitignore index 6796310..0150d2a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ /casl2 /comet2 /dumpword +*.o *~ diff --git a/src/cerr.c b/src/cerr.c index 069564b..6ab5e56 100644 --- a/src/cerr.c +++ b/src/cerr.c @@ -112,7 +112,7 @@ void freecerr() p = q; } /* 現在のエラーメッセージを解放 */ - /* free_chk(cerr->msg, "cerr->msg"); */ + free_chk(cerr->msg, "cerr.msg"); /* 現在のエラーを解放 */ free_chk(cerr, "cerr"); } diff --git a/src/cmd.c b/src/cmd.c index fc5da13..cc7a207 100644 --- a/src/cmd.c +++ b/src/cmd.c @@ -104,7 +104,7 @@ bool create_cmdtype_code() *(cmdtype_code + i) = NULL; } for(i = 0; i < comet2cmdsize; i++) { - np = malloc_chk(sizeof(CMDTAB), "cmdtype_code.next"); + np = malloc_chk(sizeof(CMDTAB), "cmdtype_code.np"); np->cmd = NULL; np->next = NULL; /* ハッシュ値の生成 */ @@ -183,7 +183,7 @@ bool create_code_type() *(code_type + i) = NULL; } for(i = 0; i < comet2cmdsize; i++) { - np = malloc_chk(sizeof(CMDTAB), "code_type.next"); + np = malloc_chk(sizeof(CMDTAB), "code_type.np"); np->cmd = NULL; np->next = NULL; /* ハッシュ値の生成 */ @@ -222,7 +222,7 @@ void free_code_type() np = code_type[i]; while(np != NULL) { nq = np->next; - free_chk(np, "np"); + free_chk(np, "code_type.np"); np = nq; } } diff --git a/src/exec.c b/src/exec.c index 4bbe350..e942602 100644 --- a/src/exec.c +++ b/src/exec.c @@ -356,15 +356,19 @@ bool exec() sprintf(errpr, "PR:#%04X", sys->cpu->pr); setcerr(204, errpr); /* Program Register (PR) - out of COMET II memory */ } + /* スタック領域を確保できない場合はエラー */ + else if(sys->cpu->sp <= prog->end) { + sprintf(errpr, "PR:#%04X", sys->cpu->pr); + setcerr(205, errpr); /* Stack Pointer (SP) - cannot allocate stack buffer */ + } /* スタック領域のアドレスが主記憶の範囲外の場合はエラー */ - if(sys->cpu->sp > sys->memsize) { + else if(sys->cpu->sp > sys->memsize) { sprintf(errpr, "PR:#%04X", sys->cpu->pr); setcerr(207, errpr); /* Stack Pointer (SP) - out of COMET II memory */ } - /* スタック領域を確保できない場合はエラー */ - if(sys->cpu->sp <= prog->end) { - sprintf(errpr, "PR:#%04X", sys->cpu->pr); - setcerr(205, errpr); /* Stack Pointer (SP) - cannot allocate stack buffer */ + /* エラー発生時は終了 */ + if(cerr->num > 0) { + goto execerr; } /* 命令の取り出し */ op = sys->memory[sys->cpu->pr] & 0xFF00; @@ -372,10 +376,6 @@ bool exec() cmdtype = getcmdtype(op); r_r1 = (sys->memory[sys->cpu->pr] >> 4) & 0xF; x_r2 = sys->memory[sys->cpu->pr] & 0xF; - /* エラー発生時は終了 */ - if(cerr->num > 0) { - goto execerr; - } /* traceオプション指定時、レジスタを出力 */ if(execmode.trace){ fprintf(stdout, "#%04X: Register::::\n", sys->cpu->pr); @@ -386,7 +386,7 @@ bool exec() fprintf(stdout, "#%04X: Memory::::\n", sys->cpu->pr); dumpmemory(); } - /* どちらかのオプション指定時、改行を出力 */ + /* traceまたはdumpオプション指定時、改行を出力 */ if(execmode.dump || execmode.trace) { fprintf(stdout, "\n"); } @@ -544,5 +544,6 @@ bool exec() return true; execerr: fprintf(stderr, "Execute error - %d: %s\n", cerr->num, cerr->msg); + cerr->msg = NULL; /* Ubuntu 10.04 PPCでcerr.msg開放時にSegmentation Faultが発生する現象を回避するため */ return false; }