fix some crashes when attributes refer to a unit that is dead.

This commit is contained in:
Enno Rehling 2008-05-24 23:26:44 +00:00
parent 3a476bb279
commit f051b5576f
6 changed files with 23 additions and 12 deletions

View File

@ -678,7 +678,7 @@ cr_output_unit(FILE * F, const region * r,
itemcloak = curse_active(get_curse(u->attribs, itemcloak_ct));
}
assert(u);
assert(u && u->number);
#if KARMA_MODULE
if (fspecial(u->faction, FS_HIDDEN))

View File

@ -374,7 +374,7 @@ register_buildings(void)
void
write_building_reference(const struct building * b, struct storage * store)
{
store->w_id(store, b?b->no:0);
store->w_id(store, (b && b->region)?b->no:0);
}

View File

@ -292,7 +292,6 @@ extern struct curse * get_curse(struct attrib *ap, const curse_type * ctype);
* oder einen NULL-pointer
* */
struct unit * get_tracingunit(struct attrib **ap, const curse_type * ct);
int find_cursebyname(const char *c);
const curse_type * ct_find(const char *c);
void ct_register(const curse_type *);

View File

@ -2108,7 +2108,7 @@ sm_familiar(const unit * u, const region * r, skill_t sk, int value) /* skillmod
int mod;
unit * familiar = get_familiar(u);
if (familiar==NULL) {
log_error(("[sm_familiar] %s has a familiar-skillmod, but no familiar\n", unitname(u)));
/* the familiar is dead */
return value;
}
mod = eff_skill(familiar, sk, r)/2;
@ -2391,16 +2391,22 @@ attrib_type at_clone = {
unit *
get_familiar(const unit *u)
{
attrib * a = a_find(u->attribs, &at_familiar);
if (a!=NULL) return (unit*)a->data.v;
return NULL;
attrib * a = a_find(u->attribs, &at_familiar);
if (a!=NULL) {
unit * u = (unit*)a->data.v;
if (u->number>0) return u;
}
return NULL;
}
unit *
get_familiar_mage(const unit *u)
{
attrib * a = a_find(u->attribs, &at_familiarmage);
if (a!=NULL) return (unit*)a->data.v;
if (a!=NULL) {
unit * u = (unit*)a->data.v;
if (u->number>0) return u;
}
return NULL;
}
@ -2408,7 +2414,10 @@ unit *
get_clone(const unit *u)
{
attrib * a = a_find(u->attribs, &at_clone);
if (a!=NULL) return (unit*)a->data.v;
if (a!=NULL) {
unit * u = (unit*)a->data.v;
if (u->number>0) return u;
}
return NULL;
}
@ -2416,7 +2425,10 @@ unit *
get_clone_mage(const unit *u)
{
attrib * a = a_find(u->attribs, &at_clonemage);
if (a!=NULL) return (unit*)a->data.v;
if (a!=NULL) {
unit * u = (unit*)a->data.v;
if (u->number>0) return u;
}
return NULL;
}

View File

@ -307,7 +307,7 @@ shipowner(const ship * sh)
void
write_ship_reference(const struct ship * sh, struct storage * store)
{
store->w_id(store, sh?sh->no:0);
store->w_id(store, (sh && sh->region)?sh->no:0);
}
void

View File

@ -624,7 +624,7 @@ free_units(void)
void
write_unit_reference(const unit * u, struct storage * store)
{
store->w_id(store, u?u->no:0);
store->w_id(store, (u && u->region)?u->no:0);
}
int