From 91dc0332d8628f9d016960838c286a6df8c288af Mon Sep 17 00:00:00 2001
From: Marko Lindqvist <cazfi74@gmail.com>
Date: Sun, 22 Nov 2026 23:39:12 +0200
Subject: [PATCH 66/66] sernet.c: Replace NULL with nullptr

See RM #2501

Signed-off-by: Marko Lindqvist <cazfi74@gmail.com>
---
 server/sernet.c | 114 ++++++++++++++++++++++++------------------------
 1 file changed, 57 insertions(+), 57 deletions(-)

diff --git a/server/sernet.c b/server/sernet.c
index 5da9492926..403cd807f2 100644
--- a/server/sernet.c
+++ b/server/sernet.c
@@ -149,7 +149,7 @@ static void handle_stdin_close(void)
 
 #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
 /****************************************************************************/
@@ -157,7 +157,7 @@ static char *current_internal = NULL;
 #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;
 
@@ -171,7 +171,7 @@ static void handle_readline_input_callback(char *line)
   }
 
   if (!line) {
-    handle_stdin_close();  /* maybe print an 'are you sure?' message? */
+    handle_stdin_close();  /* Maybe print an 'are you sure?' message? */
     return;
   }
 
@@ -179,11 +179,11 @@ static void handle_readline_input_callback(char *line)
     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;
 }
@@ -210,9 +210,9 @@ void readline_atexit(void)
   }
 #endif /* FREECIV_HAVE_LIBREADLINE */
 
-  if (current_internal != NULL) {
+  if (current_internal != nullptr) {
     free(current_internal);
-    current_internal = NULL;
+    current_internal = nullptr;
   }
 }
 
@@ -226,26 +226,26 @@ static void close_connection(struct connection *pconn)
     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);
 }
 
 /*************************************************************************//**
@@ -285,7 +285,7 @@ void close_connections_and_socket(void)
     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 */
@@ -320,7 +320,7 @@ static void really_close_connections(void)
         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);
         }
       }
@@ -385,7 +385,7 @@ void flush_packets(void)
 
   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;
@@ -414,11 +414,11 @@ void flush_packets(void)
       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) {
@@ -453,7 +453,7 @@ static bool get_packet(struct connection *pconn,
 {
   ppacket->data = get_packet_from_connection(pconn, &ppacket->type, FALSE);
 
-  return NULL != ppacket->data;
+  return ppacket->data != nullptr;
 }
 
 /*************************************************************************//**
@@ -465,7 +465,7 @@ static void incoming_client_packets(struct connection *pconn)
 {
   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)) {
@@ -475,7 +475,7 @@ static void incoming_client_packets(struct connection *pconn)
     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 */
 
@@ -537,7 +537,7 @@ enum server_events server_sniff_all_input(void)
     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);
 
@@ -574,7 +574,7 @@ enum server_events server_sniff_all_input(void)
   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;
@@ -584,7 +584,7 @@ enum server_events server_sniff_all_input(void)
 
     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;
@@ -595,7 +595,7 @@ enum server_events server_sniff_all_input(void)
       }
       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) {
@@ -619,7 +619,7 @@ enum server_events server_sniff_all_input(void)
             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."),
@@ -640,8 +640,8 @@ enum server_events server_sniff_all_input(void)
     }
 
     /* 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) {
@@ -667,10 +667,10 @@ enum server_events server_sniff_all_input(void)
           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
@@ -748,8 +748,8 @@ enum server_events server_sniff_all_input(void)
         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);
       }
 
@@ -827,11 +827,11 @@ enum server_events server_sniff_all_input(void)
       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) {
@@ -846,7 +846,7 @@ enum server_events server_sniff_all_input(void)
 #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 */
@@ -871,8 +871,8 @@ enum server_events server_sniff_all_input(void)
 
       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 */
@@ -940,8 +940,8 @@ enum server_events server_sniff_all_input(void)
     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);
   }
 
@@ -963,14 +963,14 @@ static const char *makeup_connection_name(int *id)
 
   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;
     }
@@ -985,7 +985,7 @@ static const char *makeup_connection_name(int *id)
 *****************************************************************************/
 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;
 
@@ -997,7 +997,7 @@ static int server_accept_connection(int sockfd)
   char dst[INET6_ADDRSTRLEN];
 #else  /* IPv6 support */
   struct hostent *from;
-  const char *host = NULL;
+  const char *host = nullptr;
   const char *dst;
 #endif /* IPv6 support */
 
@@ -1052,7 +1052,7 @@ static int server_accept_connection(int sockfd)
 #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;
   }
@@ -1083,10 +1083,10 @@ int server_make_connection(int new_sock, const char *client_addr,
       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;
@@ -1098,8 +1098,8 @@ int server_make_connection(int new_sock, const char *client_addr,
           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);
@@ -1145,7 +1145,7 @@ int server_open_socket(void)
   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;
@@ -1250,7 +1250,7 @@ int server_open_socket(void)
 
   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) {
@@ -1510,7 +1510,7 @@ static void get_lanserver_announcement(void)
   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;
@@ -1521,7 +1521,7 @@ static void get_lanserver_announcement(void)
 
   /* 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) {
-- 
2.53.0

