p = q->next = malloc_chk(sizeof(CERRLIST), "cerrlist.next");
}
for(i = 0; i < newerrc; i++) {
- p->cerr = &(newerrv[i]);
- p->next = malloc_chk(sizeof(CERRLIST), "cerrlist.next");
+ p->cerr = &newerrv[i];
q = p;
- p = p->next;
+ p = p->next = malloc_chk(sizeof(CERRLIST), "cerrlist.next");
}
q->next = NULL;
return true;
char *getcerrmsg(int num)
{
CERRLIST *p;
+ char *msg = "unknown error";
for(p = cerrlist; p != NULL; p = p->next) {
if(num == p->cerr->num) {
- return p->cerr->msg;
+ msg = p->cerr->msg;
+ break;
}
}
- return "unknown error";
+ return msg;
}
/**
{
CERRLIST *p = cerrlist, *q;
- /* エラーリストを解放 */
- while(p != NULL) {
- q = p->next;
- free_chk(p, "freecerr.p");
- p = q;
- }
/* 現在のエラーメッセージを解放 */
free_chk(cerr->msg, "cerr.msg");
/* 現在のエラーを解放 */
free_chk(cerr, "cerr");
+ /* エラーリストを解放 */
+ for(p = cerrlist; p != NULL; p = q) {
+ q = p->next;
+ free_chk(p, "freecerr.p");
+ }
}