From 3f8de76b9d20a178cd08fd89d155c1c2feea05fb Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 29 Apr 2017 13:37:34 +0200 Subject: [PATCH] fix largestbuilding, broken in prev commit. --- src/kernel/building.c | 7 ++----- src/kernel/building.test.c | 3 ++- 2 files changed, 4 insertions(+), 6 deletions(-) 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) {