From e5f898ce87525be8dd09efa08ccfa5b75be88db0 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 30 Apr 2017 03:42:39 +0200 Subject: [PATCH] bugfix: portals crash buildingtype(). only type that has no construction. --- src/kernel/building.c | 2 +- src/kernel/building.test.c | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/kernel/building.c b/src/kernel/building.c index 2107551de..cdd33b022 100644 --- a/src/kernel/building.c +++ b/src/kernel/building.c @@ -190,7 +190,7 @@ const char *buildingtype(const building_type * btype, const building * b, int bs if (btype->name) { return btype->name(btype, b, bsize); } - if (btype->construction->extra.name) { + if (btype->construction && btype->construction->extra.name) { if (b) { assert(b->type == btype); bsize = adjust_size(b, bsize); diff --git a/src/kernel/building.test.c b/src/kernel/building.test.c index 2b546cd79..3d25cd9a1 100644 --- a/src/kernel/building.test.c +++ b/src/kernel/building.test.c @@ -558,9 +558,24 @@ static void test_largestbuilding(CuTest *tc) { 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 *suite = CuSuiteNew(); + SUITE_ADD_TEST(suite, test_buildingtype); SUITE_ADD_TEST(suite, test_largestbuilding); SUITE_ADD_TEST(suite, test_cmp_castle_size); SUITE_ADD_TEST(suite, test_cmp_taxes);