Project

General

Profile

Bug #872 » 0034-Check-get_discounted_reward-return-value.patch

Marko Lindqvist, 09/18/2024 06:26 AM

View differences:

common/aicore/caravan.c
#include "caravan.h"
static void caravan_result_init(struct caravan_result *result,
const struct city *src,
const struct city *dest,
int arrival_time)
fc__attribute((nonnull(2)));
/************************************************************************//**
Create a valid parameter with default values.
****************************************************************************/
......
/************************************************************************//**
Initialize the result to go from src to dest with the given amount
of time. This is useful for calling get_discounted_reward and the such.
of time. This is useful for calling get_discounted_reward() and the such.
****************************************************************************/
static void caravan_result_init(struct caravan_result *result,
const struct city *src,
......
} else if (a->value < b->value) {
return -1;
} else {
/* faster time is better, so reverse-sort on time. */
/* Faster time is better, so reverse-sort on time. */
return b->arrival_time - a->arrival_time ;
}
}
......
}
pcity = tile_city(pos.tile);
if (pcity && callback(nmap, callback_data, pcity, turns_before + pos.turn,
pos.moves_left)) {
if (pcity != NULL
&& callback(nmap, callback_data, pcity, turns_before + pos.turn,
pos.moves_left)) {
break;
}
} pf_map_positions_iterate_end;
......
struct goods_type *pgood;
const struct civ_map *nmap = &(wld.map);
/* if no foreign trade is allowed, just quit. */
/* If no foreign trade is allowed, just quit. */
if (!does_foreign_trade_param_allow(parameter, pplayer_src, pplayer_dest)) {
caravan_result_init_zero(result);
return FALSE;
......
if ((consider_trade
|| (consider_windfall
&& (!parameter->consider_trade /* can only enter marketplaces */
&& (!parameter->consider_trade /* Can only enter marketplaces */
/* (FIXME: test any extra restrictions for trade routes) */
/* or the result is so big that we are still in plus */
/* (consider having produced IF_GOLD instead) */
......
if (does_foreign_trade_param_allow(param, src_owner, dest_owner)) {
city_list_iterate(dest_owner->cities, dest) {
caravan_result_init(&current, pcity, dest, 0);
get_discounted_reward(caravan, param, &current);
if (caravan_result_compare(&current, best) > 0) {
if (get_discounted_reward(caravan, param, &current)
&& caravan_result_compare(&current, best) > 0) {
*best = current;
}
} city_list_iterate_end;
......
caravan_result_init(&current, data->best->src, dest, arrival_time);
get_discounted_reward(data->caravan, data->param, &current);
if (caravan_result_compare(&current, data->best) > 0) {
if (get_discounted_reward(data->caravan, data->param, &current)
&& caravan_result_compare(&current, data->best) > 0) {
*data->best = current;
}
return FALSE; /* don't stop. */
return FALSE; /* Don't stop. */
}
/************************************************************************//**
(1-1/2)