add missing NULL check to in_safe_building

This commit is contained in:
Steffen Mecke 2015-11-13 00:50:54 +01:00
parent 449f1c51ac
commit 251126054e
2 changed files with 4 additions and 2 deletions

View file

@ -666,7 +666,7 @@ void building_setregion(building * b, region * r)
bool in_safe_building(unit *u1, unit *u2) {
if (u1->building) {
building * b = inside_building(u1);
if (b->type->flags & BTF_FORTIFICATION) {
if (b && b->type->flags & BTF_FORTIFICATION) {
if (!u2->building) {
return true;
}

View file

@ -410,7 +410,9 @@ static void test_safe_building(CuTest *tc) {
CuAssertIntEquals(tc, true, in_safe_building(u1, u2));
u2->building = u1->building;
CuAssertIntEquals(tc, true, in_safe_building(u1, u2));
u1->building->size = 2;
u1->number = 2;
CuAssertIntEquals(tc, false, in_safe_building(u1, u2));
u1->building->size = 3;
CuAssertIntEquals(tc, false, in_safe_building(u1, u2));
test_cleanup();
}