fix largestbuilding, broken in prev commit.

This commit is contained in:
Enno Rehling 2017-04-29 13:37:34 +02:00
parent bdc7457a08
commit 3f8de76b9d
2 changed files with 4 additions and 6 deletions

View File

@ -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, building *largestbuilding(const region * r, cmp_building_cb cmp_gt,
bool imaginary) bool imaginary)
{ {
building *b, *best = r->buildings; building *b, *best = NULL;
if (!best) { for (b = r->buildings; b; b = b->next) {
return NULL;
}
for (b = best->next; b; b = b->next) {
if (cmp_gt(b, best) <= 0) if (cmp_gt(b, best) <= 0)
continue; continue;
if (!imaginary) { if (!imaginary) {

View File

@ -536,7 +536,8 @@ static void test_building_effsize(CuTest *tc) {
} }
static int cmp_size(const building *lhs, const building *rhs) { 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) { static void test_largestbuilding(CuTest *tc) {