From 22e78310b185b8a0d149b113c15a030d7efd4e48 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Wed, 28 Jun 2023 00:40:46 +0300 Subject: [PATCH 15/15] 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 See osdn #48296 Signed-off-by: Marko Lindqvist --- common/citizens.c | 2 +- common/city.c | 4 +++- 2 files changed, 4 insertions(+), 2 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 d4e35b9619..49c32ecef9 100644 --- a/common/city.c +++ b/common/city.c @@ -1132,7 +1132,9 @@ 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(MAX_CITY_SIZE - size >= add); + + /* Client sets size to zero to start stacking citizens in */ fc_assert_ret(size >= -add); city_size_set(pcity, size + add); -- 2.40.1