From 251126054e7d7916fbae17333f842edab35dd528 Mon Sep 17 00:00:00 2001 From: Steffen Mecke Date: Fri, 13 Nov 2015 00:50:54 +0100 Subject: [PATCH] add missing NULL check to in_safe_building --- src/kernel/building.c | 2 +- src/kernel/building.test.c | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/kernel/building.c b/src/kernel/building.c index d4a7fbbbd..55005722e 100644 --- a/src/kernel/building.c +++ b/src/kernel/building.c @@ -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; } diff --git a/src/kernel/building.test.c b/src/kernel/building.test.c index 4241e893f..f3e66e34d 100644 --- a/src/kernel/building.test.c +++ b/src/kernel/building.test.c @@ -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(); }