From 5562b8293058464957a1f833777e187a78220ed5 Mon Sep 17 00:00:00 2001 From: j8takagi Date: Thu, 18 Mar 2010 01:15:02 +0900 Subject: [PATCH] =?utf8?q?=E3=83=A9=E3=83=99=E3=83=AB=E8=BF=BD=E5=8A=A0?= =?utf8?q?=E3=81=A7=E3=80=81=E3=83=97=E3=83=AD=E3=82=B0=E3=83=A9=E3=83=A0?= =?utf8?q?=E5=90=8D=E6=9C=AA=E8=A8=AD=E5=AE=9A=E6=99=82=E3=81=AB=E5=88=9D?= =?utf8?q?=E6=9C=9F=E5=8C=96=E3=81=95=E3=82=8C=E3=81=AA=E3=81=84=E3=83=90?= =?utf8?q?=E3=82=B0=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- src/label.c | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/src/label.c b/src/label.c index a9e4bc3..c705ad1 100644 --- a/src/label.c +++ b/src/label.c @@ -48,21 +48,34 @@ bool addlabel(const char *prog, const char *label, WORD adr) setcerr(101, label); /* label already defined */ return false; } - /* プログラム名、ラベル、アドレスを設定。メモリを確保できない場合はエラー発生 */ - if((np = malloc(sizeof(LABELTAB))) == NULL || (np->label = strdup(label)) == NULL || - (prog != NULL && (np->prog = strdup(prog)) == NULL)) - { - setcerr(102, NULL); /* label table is full */ - return false; + /* メモリを確保 */ + if((np = malloc(sizeof(LABELTAB))) == NULL) { + goto cerr102; + } + /* プログラム名を設定 */ + if(prog == NULL) { + np->prog = NULL; + } else { + if((np->prog = strdup(prog)) == NULL) { + goto cerr102; + } + } + /* ラベルを設定 */ + if((np->label = strdup(label)) == NULL) { + goto cerr102; } + /* アドレスを設定 */ np->adr = adr; - /* ラベル数の設定 */ + /* ラベル数を設定 */ labelcnt++; - /* ハッシュ表の設定 */ + /* ハッシュ表へ追加 */ hashval = labelhash(prog, label); np->next = labels[hashval]; labels[hashval] = np; return true; +cerr102: + setcerr(102, NULL); /* label table is full */ + return false; } int compare_adr(const void *a, const void *b) -- 2.18.0