From 0a010dd49a7d35152d2ff88edad0bd2a2e33ff52 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Wed, 15 Jun 2022 03:54:18 +0300 Subject: [PATCH 39/39] Update distribute() fingerprint Make 'groups' and 'ratios' unsigned See osdn #44617 Signed-off-by: Marko Lindqvist --- ai/default/aihand.c | 18 +++++++++++++++--- common/city.c | 5 +++-- utility/distribute.c | 6 +++--- utility/distribute.h | 5 +++-- 4 files changed, 24 insertions(+), 10 deletions(-) diff --git a/ai/default/aihand.c b/ai/default/aihand.c index c026b97fa9..a6abecf7df 100644 --- a/ai/default/aihand.c +++ b/ai/default/aihand.c @@ -221,7 +221,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; @@ -310,8 +312,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. */ @@ -394,8 +401,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 01efbd8855..5007cb87f0 100644 --- a/common/city.c +++ b/common/city.c @@ -2168,13 +2168,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; diff --git a/utility/distribute.c b/utility/distribute.c index 5ff1a66971..c2aaafaa42 100644 --- a/utility/distribute.c +++ b/utility/distribute.c @@ -31,14 +31,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"): @@ -53,7 +54,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