bugfix: portals crash buildingtype().

only type that has no construction.
This commit is contained in:
Enno Rehling 2017-04-30 03:42:39 +02:00
parent e6f8c943fa
commit e5f898ce87
2 changed files with 16 additions and 1 deletions

View File

@ -190,7 +190,7 @@ const char *buildingtype(const building_type * btype, const building * b, int bs
if (btype->name) { if (btype->name) {
return btype->name(btype, b, bsize); return btype->name(btype, b, bsize);
} }
if (btype->construction->extra.name) { if (btype->construction && btype->construction->extra.name) {
if (b) { if (b) {
assert(b->type == btype); assert(b->type == btype);
bsize = adjust_size(b, bsize); bsize = adjust_size(b, bsize);

View File

@ -558,9 +558,24 @@ static void test_largestbuilding(CuTest *tc) {
test_cleanup(); test_cleanup();
} }
static void test_buildingtype(CuTest *tc) {
building_type *btype;
test_setup();
btype = test_create_buildingtype("hodor");
CuAssertPtrNotNull(tc, btype->construction);
CuAssertStrEquals(tc, "hodor", buildingtype(btype, NULL, 1));
btype->construction->extra.name = strdup("castle");
CuAssertStrEquals(tc, "castle", buildingtype(btype, NULL, 1));
btype = bt_get_or_create("portal");
CuAssertPtrEquals(tc, NULL, btype->construction);
CuAssertStrEquals(tc, "portal", buildingtype(btype, NULL, 1));
test_cleanup();
}
CuSuite *get_building_suite(void) CuSuite *get_building_suite(void)
{ {
CuSuite *suite = CuSuiteNew(); CuSuite *suite = CuSuiteNew();
SUITE_ADD_TEST(suite, test_buildingtype);
SUITE_ADD_TEST(suite, test_largestbuilding); SUITE_ADD_TEST(suite, test_largestbuilding);
SUITE_ADD_TEST(suite, test_cmp_castle_size); SUITE_ADD_TEST(suite, test_cmp_castle_size);
SUITE_ADD_TEST(suite, test_cmp_taxes); SUITE_ADD_TEST(suite, test_cmp_taxes);