HKEY *keys[2];
int i = 0;
if(prog != NULL) {
- keys[i] = malloc(sizeof(HKEY));
+ keys[i] = malloc_chk(sizeof(HKEY), "labelhash.key");
keys[i]->type = CHARS;
keys[i++]->val.s = strdup(prog);
}
- keys[i] = malloc(sizeof(HKEY));
+ keys[i] = malloc_chk(sizeof(HKEY), "labelhash.key");
keys[i]->type = CHARS;
keys[i]->val.s = strdup(label);
/* ハッシュ値を返す */
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_chk(sizeof(LABELTAB), "addlabel.np")) == 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;
- /* ã\83©ã\83\99ã\83«æ\95°ã\81®設定 */
+ /* ã\83©ã\83\99ã\83«æ\95°ã\82\92設定 */
labelcnt++;
- /* ã\83\8fã\83\83ã\82·ã\83¥è¡¨ã\81®è¨å®\9a */
+ /* ã\83\8fã\83\83ã\82·ã\83¥è¡¨ã\81¸è¿½å\8a */
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)
for(i = 0; i < LABELTABSIZE; i++) {
for(np = labels[i]; np != NULL; np = np->next) {
assert(np->label != NULL);
- ar[asize] = malloc(sizeof(LABELARRAY));
+ ar[asize] = malloc_chk(sizeof(LABELARRAY), "ar[asize]");
ar[asize]->prog = (np->prog == NULL ? NULL : strdup(np->prog));
ar[asize]->label = strdup(np->label);
ar[asize++]->adr = np->adr;