From abd0f5600364576bb66858b2825d3ff0e2c91610 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Wed, 28 Jun 2023 00:40:46 +0300 Subject: [PATCH 24/24] Correct city size asserts - Both city_size_add() and citizens_nation_add() had off-by-one error causing assert to fail when adding final citizen for maximal city size - Changed city_size_add() assert to disallow shrinking city to size 0 on server side, require at least size 1. Client side needs to be able to set city size to 0. See osdn #48296 Signed-off-by: Marko Lindqvist --- common/citizens.c | 2 +- common/city.c | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/common/citizens.c b/common/citizens.c index 2d83875816..2decdb33b1 100644 --- a/common/citizens.c +++ b/common/citizens.c @@ -114,7 +114,7 @@ void citizens_nation_add(struct city *pcity, const struct player_slot *pslot, fc_assert_ret(pcity != NULL); fc_assert_ret(pcity->nationality != NULL); - fc_assert_ret(MAX_CITY_SIZE - nationality > add); + fc_assert_ret(MAX_CITY_SIZE - nationality >= add); fc_assert_ret(nationality >= -add); citizens_nation_set(pcity, pslot, nationality + add); diff --git a/common/city.c b/common/city.c index d9b91bf465..e122a992e4 100644 --- a/common/city.c +++ b/common/city.c @@ -1154,8 +1154,10 @@ void city_size_add(struct city *pcity, int add) citizens size = city_size_get(pcity); fc_assert_ret(pcity != NULL); - fc_assert_ret(MAX_CITY_SIZE - size > add); - fc_assert_ret(size >= -add); + fc_assert_ret(MAX_CITY_SIZE - size >= add); + + /* Client sets size to zero to start stacking citizens in */ + fc_assert_ret(size > -add || (!is_server() && size == add)); city_size_set(pcity, size + add); } -- 2.40.1