From bfa4b1895bee8d9e85b0ada75e1f21dbf2f938d9 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Wed, 15 Jun 2022 03:56:31 +0300 Subject: [PATCH 16/16] Update distribute() fingerprint Make 'groups' and 'ratios' unsigned See osdn #44617 Signed-off-by: Marko Lindqvist --- ai/default/aihand.c | 18 +++++++++++++++--- common/city.c | 7 ++++--- utility/distribute.c | 6 +++--- utility/distribute.h | 5 +++-- 4 files changed, 25 insertions(+), 11 deletions(-) diff --git a/ai/default/aihand.c b/ai/default/aihand.c index 8cc3229c26..b64be3be04 100644 --- a/ai/default/aihand.c +++ b/ai/default/aihand.c @@ -222,7 +222,9 @@ static void dai_manage_taxes(struct ai_type *ait, struct player *pplayer) int expenses = 0; /* total amount of gold upkeep */ int income = 0; /* total amount of gold income */ int turns_for_rapture; /* additional reserve needed for rapture */ - int rates_save[AI_RATE_COUNT], rates[AI_RATE_COUNT], result[AI_RATE_COUNT]; + unsigned rates_save[AI_RATE_COUNT], rates_tmp[AI_RATE_COUNT]; + int rates[AI_RATE_COUNT]; + int result[AI_RATE_COUNT]; int rate_tax_min = RATE_NOT_SET; int rate_tax_balance = RATE_NOT_SET; int rate_sci_min = RATE_NOT_SET; @@ -311,8 +313,13 @@ static void dai_manage_taxes(struct ai_type *ait, struct player *pplayer) && rates[AI_RATE_LUX] >= 0) { bool refill_coffers = pplayer->economic.gold < dai_gold_reserve(pplayer); int balance_tax, balance_tax_min; + int i; - distribute(trade, AI_RATE_COUNT, rates, result); + for (i = 0; i < AI_RATE_COUNT; i++) { + fc_assert(rates[i] >= 0); + rates_tmp[i] = rates[i]; + } + distribute(trade, AI_RATE_COUNT, rates_tmp, result); /* Consider the delta between the result and the real value from the * last turn to get better estimates. */ @@ -395,8 +402,13 @@ static void dai_manage_taxes(struct ai_type *ait, struct player *pplayer) && rates[AI_RATE_TAX] >= 0 && rates[AI_RATE_LUX] >= 0) { int balance_sci, balance_sci_min; + int i; - distribute(trade, AI_RATE_COUNT, rates, result); + for (i = 0; i < AI_RATE_COUNT; i++) { + fc_assert(rates[i] >= 0); + rates_tmp[i] = rates[i]; + } + distribute(trade, AI_RATE_COUNT, rates_tmp, result); /* Consider the delta between the result and the real value from the * last turn. */ diff --git a/common/city.c b/common/city.c index 038bbd5115..21ae9f12d9 100644 --- a/common/city.c +++ b/common/city.c @@ -2162,13 +2162,14 @@ int get_city_tithes_bonus(const struct city *pcity) } /************************************************************************** - Add the incomes of a city according to the taxrates (ignore # of + Add the incomes of a city according to the taxrates (ignore # of specialists). trade should be in output[O_TRADE]. **************************************************************************/ void add_tax_income(const struct player *pplayer, int trade, int *output) { const int SCIENCE = 0, TAX = 1, LUXURY = 2; - int rates[3], result[3]; + unsigned rates[3]; + int result[3]; if (game.info.changable_tax) { rates[SCIENCE] = pplayer->economic.science; @@ -2179,7 +2180,7 @@ void add_tax_income(const struct player *pplayer, int trade, int *output) rates[LUXURY] = game.info.forced_luxury; rates[TAX] = game.info.forced_gold; } - + /* ANARCHY */ if (government_of_player(pplayer) == game.government_during_revolution) { rates[SCIENCE] = 0; diff --git a/utility/distribute.c b/utility/distribute.c index e1668f5533..1719abadae 100644 --- a/utility/distribute.c +++ b/utility/distribute.c @@ -30,14 +30,15 @@ The algorithm used to determine the distribution is Hamilton's Method. ****************************************************************************/ -void distribute(int number, int groups, int *ratios, int *result) +void distribute(int number, unsigned groups, const unsigned *ratios, + int *result) { int i, sum = 0, rest[groups], max_groups[groups], max_count, max; #ifdef FREECIV_DEBUG const int original_number = number; #endif - /* + /* * Distribution of a number of items into a number of groups with a given * ratio. This follows a modified Hare/Niemeyer algorithm (also known * as "Hamilton's Method"): @@ -52,7 +53,6 @@ void distribute(int number, int groups, int *ratios, int *result) */ for (i = 0; i < groups; i++) { - fc_assert(ratios[i] >= 0); sum += ratios[i]; } diff --git a/utility/distribute.h b/utility/distribute.h index bb088b1e8c..d05495c3de 100644 --- a/utility/distribute.h +++ b/utility/distribute.h @@ -1,4 +1,4 @@ -/********************************************************************** +/*********************************************************************** Freeciv - Copyright (C) 2004 - The Freeciv Project This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -18,7 +18,8 @@ extern "C" { #endif /* __cplusplus */ -void distribute(int number, int groups, int *ratios, int *result); +void distribute(int number, unsigned groups, const unsigned *ratios, + int *result); #ifdef __cplusplus } -- 2.35.1