eliminate some possible null-pointer exceptions

This commit is contained in:
Enno Rehling 2016-08-28 21:03:23 +01:00
parent 5bc5dbdca1
commit 194f96c50f
3 changed files with 20 additions and 9 deletions

View File

@ -218,6 +218,7 @@ static void message_faction(battle * b, faction * f, struct message *m)
assert(f);
if (f->battles == NULL || f->battles->r != r) {
struct bmsg *bm = (struct bmsg *)calloc(1, sizeof(struct bmsg));
assert(bm || !"out of memory");
bm->next = f->battles;
f->battles = bm;
bm->r = r;
@ -251,6 +252,7 @@ static void fbattlerecord(battle * b, faction * f, const char *s)
static bool set_enemy(side * as, side * ds, bool attacking)
{
int i;
assert(as && ds);
for (i = 0; i != MAXSIDES; ++i) {
if (ds->enemies[i] == NULL)
ds->enemies[i] = as;
@ -1942,10 +1944,12 @@ int skilldiff(troop at, troop dt, int dist)
is_protected = 2;
}
}
if (magicwalls_ct
&& curse_active(get_curse(df->building->attribs, magicwalls_ct))) {
/* Verdoppelt Burgenbonus */
skdiff -= df->building->type->protection(df->building, du, DEFENSE_BONUS);
if (df->building->type->protection) {
if (magicwalls_ct
&& curse_active(get_curse(df->building->attribs, magicwalls_ct))) {
/* Verdoppelt Burgenbonus */
skdiff -= df->building->type->protection(df->building, du, DEFENSE_BONUS);
}
}
}
/* Goblin-Verteidigung

View File

@ -127,6 +127,7 @@ get_followers(unit * target, region * r, const region_list * route_end,
const attrib *a = a_find(uf->attribs, &at_follow);
if (a && a->data.v == target) {
follower *fnew = (follower *)malloc(sizeof(follower));
assert(fnew || !"out of memory");
fnew->uf = uf;
fnew->ut = target;
fnew->route_end = route_end;
@ -585,18 +586,21 @@ static void leave_trail(ship * sh, region * from, region_list * route)
while (a != NULL && a->type == &at_shiptrail) {
td = (traveldir *)a->data.v;
if (td->no == sh->no)
if (td->no == sh->no) {
td->dir = dir;
td->age = 2;
break;
}
a = a->next;
}
if (a == NULL || a->type != &at_shiptrail) {
if (a == NULL) {
a = a_add(&(r->attribs), a_new(&at_shiptrail));
td = (traveldir *)a->data.v;
td->no = sh->no;
td->dir = dir;
td->age = 2;
}
td->dir = dir;
td->age = 2;
}
route = route->next;
r = rn;
@ -769,8 +773,9 @@ static void msg_to_ship_inmates(ship *sh, unit **firstu, unit **lastu, message *
*lastu = u->next;
}
}
if (shipfirst)
if (shipfirst) {
*firstu = shipfirst;
}
for (u = *firstu; u != *lastu; u = u->next) {
freset(u->faction, FFL_MARK);
}
@ -1540,6 +1545,7 @@ static arg_regions *var_copy_regions(const region_list * begin, int size)
assert(size > 0);
arg_regions *dst =
(arg_regions *)malloc(sizeof(arg_regions) + sizeof(region *) * (size_t)size);
assert(dst || !"out of memory");
dst->nregions = size;
dst->regions = (region **)(dst + 1);
for (rsrc = begin; i != size; rsrc = rsrc->next) {

View File

@ -1263,6 +1263,7 @@ add_ironweapon(const struct item_type *type, const struct item_type *rusty,
float chance)
{
iron_weapon *iweapon = malloc(sizeof(iron_weapon));
assert(iweapon || !"out of memory");
iweapon->type = type;
iweapon->rusty = rusty;
iweapon->chance = chance;