Project

General

Profile

Feature #2255 ยป 0073-agents-Replace-NULL-with-nullptr.patch

Marko Lindqvist, 09/17/2026 12:44 AM

View differences:

client/agents/agents.c
#define log_meta_callback(...) log_debug(__VA_ARGS__)
#define log_debug_freeze(...) /* log_test(__VA_ARGS__) */
#define MAX_AGENTS 10
#define MAX_AGENTS 10
struct my_agent;
......
/************************************************************************//**
Return an outstanding call. The call is removed from the agents.calls
list. Returns NULL if there no more outstanding calls.
list. Returns nullptr if there no more outstanding calls.
****************************************************************************/
static struct call *remove_and_return_a_call(void)
{
struct call *result;
if (call_list_size(agents.calls) == 0) {
return NULL;
return nullptr;
}
result = call_list_front(agents.calls);
......
return &agents.entries[i];
}
return NULL;
return nullptr;
}
/************************************************************************//**
......
{
struct my_agent *agent = agent_by_name(name_of_calling_agent);
fc_assert_ret(agent->agent.unit_callbacks[CB_CHANGE] != NULL);
fc_assert_ret(agent->agent.unit_callbacks[CB_CHANGE] != nullptr);
enqueue_call(OCT_UNIT, CB_CHANGE, agent, punit->id);
call_handle_methods();
}
......
{
struct my_agent *agent = agent_by_name(name_of_calling_agent);
fc_assert_ret(agent->agent.city_callbacks[CB_CHANGE] != NULL);
fc_assert_ret(agent->agent.city_callbacks[CB_CHANGE] != nullptr);
enqueue_call(OCT_CITY, CB_CHANGE, agent, pcity->id);
call_handle_methods();
}
client/agents/cma_core.c
/************************************************************************//**
Returns TRUE if the city is valid for CMA. Fills parameter if TRUE
is returned. Parameter can be NULL.
is returned. Parameter can be nullptr.
****************************************************************************/
static struct city *check_city(int city_id, struct cm_parameter *parameter)
{
......
if (!pcity
|| !cma_get_parameter(ATTR_CITY_CMA_PARAMETER, city_id, parameter)) {
return NULL;
return nullptr;
}
if (city_owner(pcity) != client.conn.playing) {
cma_release_city(pcity);
return NULL;
return nullptr;
}
return pcity;
......
* DEFAULT_SPECIALIST! */
city_tile_iterate_skip_free_worked(&(wld.map), city_radius_sq, pcenter, ptile, idx,
x, y) {
if (NULL == tile_worked(ptile)
if (tile_worked(ptile) == nullptr
&& result->worker_positions[idx]) {
log_apply_result("Putting worker at {%d,%d}.", x, y);
fc_assert_action(city_can_work_tile(pcity, ptile), break);
......
int city_id = pcity->id;
wait_for_requests("CMA", first_request_id, last_request_id);
if (pcity != check_city(city_id, NULL)) {
if (pcity != check_city(city_id, nullptr)) {
log_verbose("apply_result_on_server(city %d) !check_city()!", city_id);
return FALSE;
}
......
****************************************************************************/
static void release_city(int city_id)
{
attr_city_set(ATTR_CITY_CMA_PARAMETER, city_id, 0, NULL);
attr_city_set(ATTR_CITY_CMA_PARAMETER, city_id, 0, nullptr);
}
/****************************************************************************
......
} else {
if (!apply_result_on_server(pcity, result)) {
log_handle_city2(" doesn't cleanly apply");
if (pcity == check_city(city_id, NULL) && i == 0) {
if (pcity == check_city(city_id, nullptr) && i == 0) {
create_event(city_tile(pcity), E_CITY_CMA_RELEASE, ftc_client,
_("The citizen governor has gotten confused dealing "
"with %s. You may want to have a look."),
......
cm_result_destroy(result);
if (!handled) {
fc_assert_ret(pcity == check_city(city_id, NULL));
fc_assert_ret(pcity == check_city(city_id, nullptr));
log_handle_city2(" not handled");
create_event(city_tile(pcity), E_CITY_CMA_RELEASE, ftc_client,
......
* called multiple times per client invocation so that lead to memory
* leaks. */
stats.wall_timer = timer_renew(timer, TIMER_USER, TIMER_ACTIVE,
timer != NULL ? NULL : "agent: stats");
timer != nullptr ? nullptr : "agent: stats");
memset(&self, 0, sizeof(self));
strcpy(self.name, "CMA");
......
****************************************************************************/
bool cma_apply_result(struct city *pcity, const struct cm_result *result)
{
fc_assert(!cma_is_city_under_agent(pcity, NULL));
fc_assert(!cma_is_city_under_agent(pcity, nullptr));
if (result->found_a_valid) {
return apply_result_on_server(pcity, result);
......
return FALSE;
}
if (parameter != NULL) {
if (parameter != nullptr) {
memcpy(parameter, &my_parameter, sizeof(struct cm_parameter));
}
client/agents/cma_core.h
/*
* Test if the citizen in the given city are managed by the agent. The
* given parameter is filled if pointer is non-NULL. The parameter is
* given parameter is filled if pointer is non-nullptr. The parameter is
* only valid if cma_is_city_under_agent returns true.
*/
bool cma_is_city_under_agent(const struct city *pcity,
client/agents/cma_fec.c
#include "cma_fec.h"
#define RESULT_COLUMNS 10
#define BUFFER_SIZE 100
#define MAX_LEN_PRESET_NAME 80
#define RESULT_COLUMNS 10
#define BUFFER_SIZE 100
#define MAX_LEN_PRESET_NAME 80
struct cma_preset {
char *descr;
......
TYPED_LIST_ITERATE(struct cma_preset, presetlist, ppreset)
#define preset_list_iterate_end LIST_ITERATE_END
static struct preset_list *preset_list = NULL;
static struct preset_list *preset_list = nullptr;
/**********************************************************************//**
Is called if the game removes a city. It will clear the
......
**************************************************************************/
static void city_remove(int city_id)
{
attr_city_set(ATTR_CITY_CMAFE_PARAMETER, city_id, 0, NULL);
attr_city_set(ATTR_CITY_CMAFE_PARAMETER, city_id, 0, nullptr);
}
/**********************************************************************//**
......
{
struct agent self;
if (preset_list == NULL) {
if (preset_list == nullptr) {
preset_list = preset_list_new();
}
......
{
struct cma_preset *ppreset = fc_malloc(sizeof(struct cma_preset));
if (preset_list == NULL) {
if (preset_list == nullptr) {
preset_list = preset_list_new();
}
......
{
struct cma_preset *ppreset;
fc_assert_ret_val(idx >= 0 && idx < cmafec_preset_num(), NULL);
fc_assert_ret_val(idx >= 0 && idx < cmafec_preset_num(), nullptr);
ppreset = preset_list_get(preset_list, idx);
return ppreset->descr;
......
{
struct cma_preset *ppreset;
fc_assert_ret_val(idx >= 0 && idx < cmafec_preset_num(), NULL);
fc_assert_ret_val(idx >= 0 && idx < cmafec_preset_num(), nullptr);
ppreset = preset_list_get(preset_list, idx);
return &ppreset->parameter;
client/agents/sha.c
already got the new ones.
**************************************************************************/
static struct tile *previous_tiles = NULL;
static struct tile *previous_tiles = nullptr;
static struct unit_list *previous_units;
/**********************************************************************//**
......
log_debug("sha got unit: %d", id);
fc_assert_ret(NULL != pold_unit);
fc_assert_ret(pold_unit != nullptr);
*pold_unit = *punit;
}
......
static void sha_unit_new(int id)
{
struct unit *punit = game_unit_by_number(id);
struct unit *pold_unit = unit_virtual_create(unit_owner(punit), NULL,
struct unit *pold_unit = unit_virtual_create(unit_owner(punit), nullptr,
unit_type_get(punit), 0);
log_debug("sha got unit: %d", id);
......
log_debug("sha got unit: %d", id);
fc_assert_ret(NULL != pold_unit);
fc_assert_ret(pold_unit != nullptr);
unit_list_remove(previous_units, pold_unit);
/* List pointers were struct copied, cannot unit_virtual_destroy() */
memset(pold_unit, 0, sizeof(*pold_unit)); /* Ensure no pointers remain */
    (1-1/1)