cleaning up armor structs

rearranging code to avoid nullpointer-crashes
This commit is contained in:
Enno Rehling 2005-07-31 08:28:21 +00:00
parent d026b324fd
commit 137e26e670
1 changed files with 7 additions and 2 deletions

View File

@ -3013,11 +3013,11 @@ make_fighter(battle * b, unit * u, side * s1, boolean attack)
for (itm=u->items; itm; itm=itm->next) { for (itm=u->items; itm; itm=itm->next) {
if (itm->type->rtype->atype) { if (itm->type->rtype->atype) {
struct armor * adata = malloc(sizeof(armor)), **aptr; struct armor * adata = malloc(sizeof(armor)), **aptr;
adata->atype = itm->type->rtype->atype;
adata->count = itm->number;
for (aptr=&fig->armors;*aptr;aptr=&(*aptr)->next) { for (aptr=&fig->armors;*aptr;aptr=&(*aptr)->next) {
if (adata->atype->prot > (*aptr)->atype->prot) break; if (adata->atype->prot > (*aptr)->atype->prot) break;
} }
adata->count = itm->number;
adata->atype = itm->type->rtype->atype;
adata->next = *aptr; adata->next = *aptr;
*aptr = adata; *aptr = adata;
} }
@ -3186,6 +3186,11 @@ free_fighter(fighter * fig)
while (fig->loot) { while (fig->loot) {
i_free(i_remove(&fig->loot, fig->loot)); i_free(i_remove(&fig->loot, fig->loot));
} }
while (fig->armors) {
armor * a = fig->armors;
fig->armors = a->next;
free(a);
}
free(fig->person); free(fig->person);
free(fig->weapons); free(fig->weapons);