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); assert(f);
if (f->battles == NULL || f->battles->r != r) { if (f->battles == NULL || f->battles->r != r) {
struct bmsg *bm = (struct bmsg *)calloc(1, sizeof(struct bmsg)); struct bmsg *bm = (struct bmsg *)calloc(1, sizeof(struct bmsg));
assert(bm || !"out of memory");
bm->next = f->battles; bm->next = f->battles;
f->battles = bm; f->battles = bm;
bm->r = r; 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) static bool set_enemy(side * as, side * ds, bool attacking)
{ {
int i; int i;
assert(as && ds);
for (i = 0; i != MAXSIDES; ++i) { for (i = 0; i != MAXSIDES; ++i) {
if (ds->enemies[i] == NULL) if (ds->enemies[i] == NULL)
ds->enemies[i] = as; ds->enemies[i] = as;
@ -1942,10 +1944,12 @@ int skilldiff(troop at, troop dt, int dist)
is_protected = 2; is_protected = 2;
} }
} }
if (magicwalls_ct if (df->building->type->protection) {
&& curse_active(get_curse(df->building->attribs, magicwalls_ct))) { if (magicwalls_ct
/* Verdoppelt Burgenbonus */ && curse_active(get_curse(df->building->attribs, magicwalls_ct))) {
skdiff -= df->building->type->protection(df->building, du, DEFENSE_BONUS); /* Verdoppelt Burgenbonus */
skdiff -= df->building->type->protection(df->building, du, DEFENSE_BONUS);
}
} }
} }
/* Goblin-Verteidigung /* 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); const attrib *a = a_find(uf->attribs, &at_follow);
if (a && a->data.v == target) { if (a && a->data.v == target) {
follower *fnew = (follower *)malloc(sizeof(follower)); follower *fnew = (follower *)malloc(sizeof(follower));
assert(fnew || !"out of memory");
fnew->uf = uf; fnew->uf = uf;
fnew->ut = target; fnew->ut = target;
fnew->route_end = route_end; 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) { while (a != NULL && a->type == &at_shiptrail) {
td = (traveldir *)a->data.v; td = (traveldir *)a->data.v;
if (td->no == sh->no) if (td->no == sh->no) {
td->dir = dir;
td->age = 2;
break; break;
}
a = a->next; a = a->next;
} }
if (a == NULL || a->type != &at_shiptrail) { if (a == NULL) {
a = a_add(&(r->attribs), a_new(&at_shiptrail)); a = a_add(&(r->attribs), a_new(&at_shiptrail));
td = (traveldir *)a->data.v; td = (traveldir *)a->data.v;
td->no = sh->no; td->no = sh->no;
td->dir = dir;
td->age = 2;
} }
td->dir = dir;
td->age = 2;
} }
route = route->next; route = route->next;
r = rn; r = rn;
@ -769,8 +773,9 @@ static void msg_to_ship_inmates(ship *sh, unit **firstu, unit **lastu, message *
*lastu = u->next; *lastu = u->next;
} }
} }
if (shipfirst) if (shipfirst) {
*firstu = shipfirst; *firstu = shipfirst;
}
for (u = *firstu; u != *lastu; u = u->next) { for (u = *firstu; u != *lastu; u = u->next) {
freset(u->faction, FFL_MARK); freset(u->faction, FFL_MARK);
} }
@ -1540,6 +1545,7 @@ static arg_regions *var_copy_regions(const region_list * begin, int size)
assert(size > 0); assert(size > 0);
arg_regions *dst = arg_regions *dst =
(arg_regions *)malloc(sizeof(arg_regions) + sizeof(region *) * (size_t)size); (arg_regions *)malloc(sizeof(arg_regions) + sizeof(region *) * (size_t)size);
assert(dst || !"out of memory");
dst->nregions = size; dst->nregions = size;
dst->regions = (region **)(dst + 1); dst->regions = (region **)(dst + 1);
for (rsrc = begin; i != size; rsrc = rsrc->next) { 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) float chance)
{ {
iron_weapon *iweapon = malloc(sizeof(iron_weapon)); iron_weapon *iweapon = malloc(sizeof(iron_weapon));
assert(iweapon || !"out of memory");
iweapon->type = type; iweapon->type = type;
iweapon->rusty = rusty; iweapon->rusty = rusty;
iweapon->chance = chance; iweapon->chance = chance;