Project

General

Profile

Feature #2501 ยป 0066-sernet.c-Replace-NULL-with-nullptr.patch

Marko Lindqvist, 11/22/2026 11:40 PM

View differences:

server/sernet.c
#endif /* FREECIV_HAVE_LIBREADLINE || (!FREECIV_SOCKET_ZERO_NOT_STDIN && !FREECIV_HAVE_LIBREADLINE) */
static char *current_internal = NULL;
static char *current_internal = nullptr;
#ifdef FREECIV_HAVE_LIBREADLINE
/****************************************************************************/
......
#define HISTORY_FILENAME "freeciv-server_history"
#define HISTORY_LENGTH 100
static char *history_file = NULL;
static char *history_file = nullptr;
static bool readline_handled_input = FALSE;
static bool readline_initialized = FALSE;
......
}
if (!line) {
handle_stdin_close(); /* maybe print an 'are you sure?' message? */
handle_stdin_close(); /* Maybe print an 'are you sure?' message? */
return;
}
......
add_history(line);
}
con_prompt_enter(); /* just got an 'Enter' hit */
con_prompt_enter(); /* Just got an 'Enter' hit */
current_internal = local_to_internal_string_malloc(line);
free(line); /* This is already freed if we exit() with /quit command */
handle_stdin_input_free(NULL, current_internal);
current_internal = NULL;
handle_stdin_input_free(nullptr, current_internal);
current_internal = nullptr;
readline_handled_input = TRUE;
}
......
}
#endif /* FREECIV_HAVE_LIBREADLINE */
if (current_internal != NULL) {
if (current_internal != nullptr) {
free(current_internal);
current_internal = NULL;
current_internal = nullptr;
}
}
......
return;
}
if (pconn->server.ping_timers != NULL) {
if (pconn->server.ping_timers != nullptr) {
timer_list_destroy(pconn->server.ping_timers);
pconn->server.ping_timers = NULL;
pconn->server.ping_timers = nullptr;
}
conn_pattern_list_destroy(pconn->server.ignore_list);
pconn->server.ignore_list = NULL;
pconn->server.ignore_list = nullptr;
/* safe to do these even if not in lists: */
/* Safe to do these even if not in lists: */
conn_list_remove(game.web_client_connections, pconn);
conn_list_remove(game.glob_observers, pconn);
conn_list_remove(game.all_connections, pconn);
conn_list_remove(game.est_connections, pconn);
pconn->playing = NULL;
pconn->playing = nullptr;
pconn->client_gui = GUI_STUB;
pconn->access_level = ALLOW_NONE;
connection_common_close(pconn);
send_updated_vote_totals(NULL);
send_updated_vote_totals(nullptr);
}
/*************************************************************************//**
......
write_history(history_file);
history_truncate_file(history_file, HISTORY_LENGTH);
free(history_file);
history_file = NULL;
history_file = nullptr;
clear_history();
}
#endif /* FREECIV_HAVE_LIBREADLINE */
......
conn_list_remove(game.glob_observers, pconn);
conn_list_remove(game.est_connections, pconn);
conn_list_remove(game.all_connections, pconn);
if (NULL != conn_get_player(pconn)) {
if (conn_get_player(pconn) != nullptr) {
conn_list_remove(conn_get_player(pconn)->connections, pconn);
}
}
......
for (;;) {
/* Can't assign to tv.tv_sec directly on systems where it's unsigned */
signed signsecs = (game.server.netwait - (time(NULL) - start));
signed signsecs = (game.server.netwait - (time(nullptr) - start));
if (signsecs < 0) {
return;
......
return;
}
if (fc_select(max_desc + 1, NULL, &writefs, &exceptfs, &tv) <= 0) {
if (fc_select(max_desc + 1, nullptr, &writefs, &exceptfs, &tv) <= 0) {
return;
}
for (i = 0; i < MAX_NUM_CONNECTIONS; i++) { /* check for freaky players */
for (i = 0; i < MAX_NUM_CONNECTIONS; i++) { /* Check for freaky players */
struct connection *pconn = &connections[i];
if (pconn->used && !pconn->server.is_closing) {
......
{
ppacket->data = get_packet_from_connection(pconn, &ppacket->type, FALSE);
return NULL != ppacket->data;
return ppacket->data != nullptr;
}
/*************************************************************************//**
......
{
struct packet_to_handle packet;
#if PROCESSING_TIME_STATISTICS
struct timer *request_time = NULL;
struct timer *request_time = nullptr;
#endif
while (get_packet(pconn, &packet)) {
......
int request_id;
request_time = timer_renew(request_time, TIMER_USER, TIMER_ACTIVE,
request_time != NULL ? NULL : "request");
request_time != nullptr ? nullptr : "request");
timer_start(request_time);
#endif /* PROCESSING_TIME_STATISTICS */
......
if (!no_input && !readline_initialized) {
char *storage_dir = freeciv_storage_dir();
if (storage_dir != NULL) {
if (storage_dir != nullptr) {
int fcdl = strlen(storage_dir) + 1;
char *fc_dir = fc_malloc(fcdl);
......
while (TRUE) {
int selret;
con_prompt_on(); /* accepting new input */
con_prompt_on(); /* Accepting new input */
if (force_end_of_sniff) {
force_end_of_sniff = FALSE;
......
get_lanserver_announcement();
/* end server if no players for 'srvarg.quitidle' seconds,
/* End server if no players for 'srvarg.quitidle' seconds,
* but only if at least one player has previously connected. */
if (srvarg.quitidle != 0) {
static time_t last_noplayers;
......
}
if (conns && conn_list_size(game.est_connections) == 0) {
if (last_noplayers != 0) {
if (time(NULL) > last_noplayers + srvarg.quitidle) {
if (time(nullptr) > last_noplayers + srvarg.quitidle) {
save_game_auto("Lost all connections", AS_QUITIDLE);
if (srvarg.exit_on_end) {
......
conns = FALSE;
}
} else {
last_noplayers = time(NULL);
last_noplayers = time(nullptr);
if (srvarg.exit_on_end) {
log_normal(_("Shutting down in %d seconds for lack of players."),
......
}
/* Pinging around for statistics */
if (time(NULL) > (game.server.last_ping + game.server.pingtime)) {
/* send data about the previous run */
if (time(nullptr) > (game.server.last_ping + game.server.pingtime)) {
/* Send data about the previous run */
send_ping_times_to_all();
conn_list_iterate(game.all_connections, pconn) {
......
connection_ping(pconn);
}
} conn_list_iterate_end;
game.server.last_ping = time(NULL);
game.server.last_ping = time(nullptr);
}
/* if we've waited long enough after a failure, respond to the client */
/* If we've waited long enough after a failure, respond to the client */
conn_list_iterate(game.all_connections, pconn) {
if (srvarg.auth_enabled
&& !pconn->server.is_closing
......
save_game_auto("Timer", AS_TIMER);
game.server.save_timer = timer_renew(game.server.save_timer,
TIMER_USER, TIMER_ACTIVE,
game.server.save_timer != NULL
? NULL : "save interval");
game.server.save_timer != nullptr
? nullptr : "save interval");
timer_start(game.server.save_timer);
}
......
current_internal = local_to_internal_string_malloc(bufptr);
con_prompt_enter(); /* Will need a new prompt, regardless */
handle_stdin_input_free(NULL, current_internal);
current_internal = NULL;
handle_stdin_input_free(nullptr, current_internal);
current_internal = nullptr;
}
#else /* !FREECIV_SOCKET_ZERO_NOT_STDIN */
if (!no_input && FD_ISSET(0, &readfs)) { /* input from server operator */
if (!no_input && FD_ISSET(0, &readfs)) { /* Input from server operator */
#ifdef FREECIV_HAVE_LIBREADLINE
rl_callback_read_char();
if (readline_handled_input) {
......
#ifdef HAVE_GETLINE
size_t len = 0;
buffer = NULL; /* Must be NULL when calling getline() */
buffer = nullptr; /* Must be nullptr when calling getline() */
didget = getline(&buffer, &len, stdin);
if (didget >= 1) {
buffer[--didget] = '\0'; /* Overwrite newline character */
......
if (didget >= 0) {
current_internal = local_to_internal_string_malloc(buffer);
handle_stdin_input_free(NULL, current_internal);
current_internal = NULL;
handle_stdin_input_free(nullptr, current_internal);
current_internal = nullptr;
}
free(buffer);
#endif /* !FREECIV_HAVE_LIBREADLINE */
......
save_game_auto("Timer", AS_TIMER);
game.server.save_timer = timer_renew(game.server.save_timer,
TIMER_USER, TIMER_ACTIVE,
game.server.save_timer != NULL
? NULL : "save interval");
game.server.save_timer != nullptr
? nullptr : "save interval");
timer_start(game.server.save_timer);
}
......
for (;;) {
if (i == (unsigned short) - 1) {
/* don't use 0 */
/* Don't use 0 */
i++;
}
fc_snprintf(name, sizeof(name), "c%u", (unsigned int)++i);
if (NULL == player_by_name(name)
&& NULL == player_by_user(name)
&& NULL == conn_by_number(i)
&& NULL == conn_by_user(name)) {
if (player_by_name(name) == nullptr
&& player_by_user(name) == nullptr
&& conn_by_number(i) == nullptr
&& conn_by_user(name) == nullptr) {
*id = i;
return name;
}
......
*****************************************************************************/
static int server_accept_connection(int sockfd)
{
/* This used to have size_t for some platforms. If this is necessary
/* This used to have size_t for some platforms. If this is necessary
* it should be done with a configure check not a platform check. */
socklen_t fromlen;
......
char dst[INET6_ADDRSTRLEN];
#else /* IPv6 support */
struct hostent *from;
const char *host = NULL;
const char *host = nullptr;
const char *dst;
#endif /* IPv6 support */
......
#else /* IPv6 support */
from = gethostbyaddr((char *) &fromend.saddr_in4.sin_addr,
sizeof(fromend.saddr_in4.sin_addr), AF_INET);
if (NULL != from && '\0' != from->h_name[0]) {
if (from != nullptr && '\0' != from->h_name[0]) {
host = from->h_name;
nameinfo = TRUE;
}
......
connection_common_init(pconn);
pconn->sock = new_sock;
pconn->observer = FALSE;
pconn->playing = NULL;
pconn->playing = nullptr;
pconn->capability[0] = '\0';
pconn->access_level = access_level_for_next_connection();
pconn->notify_of_writable_data = NULL;
pconn->notify_of_writable_data = nullptr;
pconn->server.currently_processed_request_id = 0;
pconn->server.last_request_id_seen = 0;
pconn->server.auth_tries = 0;
......
conn_pattern_list_new_full(conn_pattern_destroy);
pconn->server.is_closing = FALSE;
pconn->ping_time = -1.0;
pconn->incoming_packet_notify = NULL;
pconn->outgoing_packet_notify = NULL;
pconn->incoming_packet_notify = nullptr;
pconn->outgoing_packet_notify = nullptr;
sz_strlcpy(pconn->username, makeup_connection_name(&pconn->id));
sz_strlcpy(pconn->addr, client_addr);
......
struct fc_sockaddr_list *list;
int name_count;
fc_errno eno = 0;
union fc_sockaddr *problematic = NULL;
union fc_sockaddr *problematic = nullptr;
#ifdef FREECIV_IPV6_SUPPORT
struct ipv6_mreq mreq6;
......
if (listen_count == 0) {
log_fatal("%s failure: %s (%d failed)", cause, fc_strerror(eno), name_count);
if (problematic != NULL) {
if (problematic != nullptr) {
sockaddr_debug(problematic, LOG_NORMAL);
}
fc_sockaddr_list_iterate(list, paddr) {
......
tv.tv_sec = 0;
tv.tv_usec = 0;
while (fc_select(socklan + 1, &readfs, NULL, &exceptfs, &tv) == -1) {
while (fc_select(socklan + 1, &readfs, nullptr, &exceptfs, &tv) == -1) {
if (errno != EINTR) {
log_error("select failed: %s", fc_strerror(fc_get_errno()));
return;
......
/* We would need a raw network connection for broadcast messages */
if (FD_ISSET(socklan, &readfs)) {
if (0 < recvfrom(socklan, msgbuf, sizeof(msgbuf), 0, NULL, NULL)) {
if (0 < recvfrom(socklan, msgbuf, sizeof(msgbuf), 0, nullptr, nullptr)) {
dio_input_init(&din, msgbuf, 1);
dio_get_uint8_raw(&din, &type);
if (type == SERVER_LAN_VERSION) {
    (1-1/1)