Merge pull request #395 from stm2/fix394

add missing NULL check to in_safe_building
This commit is contained in:
Enno Rehling 2015-11-13 11:18:08 +01:00
commit c9c5a22c85
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) { bool in_safe_building(unit *u1, unit *u2) {
if (u1->building) { if (u1->building) {
building * b = inside_building(u1); building * b = inside_building(u1);
if (b->type->flags & BTF_FORTIFICATION) { if (b && b->type->flags & BTF_FORTIFICATION) {
if (!u2->building) { if (!u2->building) {
return true; return true;
} }

View File

@ -410,7 +410,9 @@ static void test_safe_building(CuTest *tc) {
CuAssertIntEquals(tc, true, in_safe_building(u1, u2)); CuAssertIntEquals(tc, true, in_safe_building(u1, u2));
u2->building = u1->building; u2->building = u1->building;
CuAssertIntEquals(tc, true, in_safe_building(u1, u2)); 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)); CuAssertIntEquals(tc, false, in_safe_building(u1, u2));
test_cleanup(); test_cleanup();
} }