diff --git a/src/kernel/building.c b/src/kernel/building.c index 77718e2ea..90bfced16 100644 --- a/src/kernel/building.c +++ b/src/kernel/building.c @@ -643,12 +643,9 @@ bool is_building_type(const struct building_type *btype, const char *name) { building *largestbuilding(const region * r, cmp_building_cb cmp_gt, bool imaginary) { - building *b, *best = r->buildings; + building *b, *best = NULL; - if (!best) { - return NULL; - } - for (b = best->next; b; b = b->next) { + for (b = r->buildings; b; b = b->next) { if (cmp_gt(b, best) <= 0) continue; if (!imaginary) { diff --git a/src/kernel/building.test.c b/src/kernel/building.test.c index 233212026..bbe8447b5 100644 --- a/src/kernel/building.test.c +++ b/src/kernel/building.test.c @@ -536,7 +536,8 @@ static void test_building_effsize(CuTest *tc) { } static int cmp_size(const building *lhs, const building *rhs) { - return lhs->size - rhs->size; + assert(lhs); + return rhs ? lhs->size - rhs->size : 1; } static void test_largestbuilding(CuTest *tc) {