From 397b3a70c1870306d6873af2512be651e95f3e52 Mon Sep 17 00:00:00 2001
From: Marko Lindqvist <cazfi74@gmail.com>
Date: Sat, 14 Nov 2026 07:51:40 +0200
Subject: [PATCH 66/66] notify.c: Replace NULL with nullptr

See RM #2479

Signed-off-by: Marko Lindqvist <cazfi74@gmail.com>
---
 server/notify.c | 135 +++++++++++++++++++++++++-----------------------
 1 file changed, 69 insertions(+), 66 deletions(-)

diff --git a/server/notify.c b/server/notify.c
index f1bcf7d0d8..4e0fc306b3 100644
--- a/server/notify.c
+++ b/server/notify.c
@@ -62,9 +62,9 @@ static void package_event_full(struct packet_chat_msg *packet,
   char buf[MAX_LEN_MSG];
   char *str;
 
-  fc_assert_ret(NULL != packet);
+  fc_assert_ret(packet != nullptr);
 
-  packet->tile = (NULL != ptile ? tile_index(ptile) : -1);
+  packet->tile = (ptile != nullptr ? tile_index(ptile) : -1);
   packet->event = event;
   packet->conn_id = pconn ? pconn->id : -1;
   packet->turn = game.info.turn;
@@ -106,7 +106,7 @@ void vpackage_chat_msg(struct packet_chat_msg *packet,
                        const struct ft_color color,
                        const char *format, va_list vargs)
 {
-  package_event_full(packet, NULL, E_CHAT_MSG, sender, color, format, vargs);
+  package_event_full(packet, nullptr, E_CHAT_MSG, sender, color, format, vargs);
 }
 
 /**********************************************************************//**
@@ -150,7 +150,7 @@ void vpackage_event(struct packet_chat_msg *packet,
                     const struct ft_color color,
                     const char *format, va_list vargs)
 {
-  package_event_full(packet, ptile, event, NULL, color, format, vargs);
+  package_event_full(packet, ptile, event, nullptr, color, format, vargs);
 }
 
 /**********************************************************************//**
@@ -185,7 +185,7 @@ void package_event(struct packet_chat_msg *packet,
   Notify specified connections of an event of specified type (from events.h)
   and specified (x,y) coords associated with the event. Coords will only
   apply if game has started and the conn's player knows that tile (or
-  NULL == pconn->playing && pconn->observer). If coords are not required,
+  pconn->playing == nullptr && pconn->observer). If coords are not required,
   caller should specify (x,y) = (-1,-1); otherwise make sure that the
   coordinates have been normalized.
 **************************************************************************/
@@ -211,12 +211,12 @@ static void notify_conn_packet(struct conn_list *dest,
     }
 
     if (S_S_RUNNING <= server_state()
-        && ptile /* special case, see above */
-        && ((NULL == pconn->playing && pconn->observer)
-            || (NULL != pconn->playing
+        && ptile /* Special case, see above */
+        && ((pconn->playing == nullptr && pconn->observer)
+            || (pconn->playing != nullptr
                 && map_is_known(ptile, pconn->playing)))) {
-      /* tile info is OK; see above. */
-      /* FIXME: in the case this is a city event, we should check if the
+      /* Tile info is OK; see above. */
+      /* FIXME: In the case this is a city event, we should check if the
        * city is really known. */
       real_packet.tile = tile;
     } else {
@@ -225,7 +225,8 @@ static void notify_conn_packet(struct conn_list *dest,
     }
 
     if (early) {
-      send_packet_early_chat_msg(pconn, (struct packet_early_chat_msg *)(&real_packet));
+      send_packet_early_chat_msg(pconn,
+                                 (struct packet_early_chat_msg *)(&real_packet));
     } else {
       send_packet_chat_msg(pconn, &real_packet);
     }
@@ -283,9 +284,9 @@ void notify_conn_early(struct conn_list *dest,
 
 /**********************************************************************//**
   Similar to notify_conn_packet (see also), but takes player as "destination".
-  If player != NULL, sends to all connections for that player.
-  If player == NULL, sends to all game connections, to support
-  old code, but this feature may go away - should use notify_conn(NULL)
+  If player != nullptr, sends to all connections for that player.
+  If player == nullptr, sends to all game connections, to support
+  old code, but this feature may go away - should use notify_conn(nullptr)
   instead.
 **************************************************************************/
 void notify_player(const struct player *pplayer,
@@ -294,7 +295,7 @@ void notify_player(const struct player *pplayer,
                    const struct ft_color color,
                    const char *format, ...)
 {
-  struct conn_list *dest = pplayer ? pplayer->connections : NULL;
+  struct conn_list *dest = pplayer ? pplayer->connections : nullptr;
   struct packet_chat_msg genmsg;
   va_list args;
 
@@ -319,7 +320,7 @@ void notify_embassies(const struct player *pplayer,
                       const char *format, ...)
 {
   struct packet_chat_msg genmsg;
-  struct event_cache_players *players = NULL;
+  struct event_cache_players *players = nullptr;
   va_list args;
 
   va_start(args, format);
@@ -339,7 +340,7 @@ void notify_embassies(const struct player *pplayer,
 }
 
 /**********************************************************************//**
-  Sends a message to all players on pplayer's team. If 'pplayer' is NULL,
+  Sends a message to all players on pplayer's team. If 'pplayer' is nullptr,
   sends to all players.
 **************************************************************************/
 void notify_team(const struct player *pplayer,
@@ -350,7 +351,7 @@ void notify_team(const struct player *pplayer,
 {
   struct conn_list *dest = game.est_connections;
   struct packet_chat_msg genmsg;
-  struct event_cache_players *players = NULL;
+  struct event_cache_players *players = nullptr;
   va_list args;
 
   va_start(args, format);
@@ -397,11 +398,11 @@ void notify_research(const struct research *presearch,
                      const char *format, ...)
 {
   struct packet_chat_msg genmsg;
-  struct event_cache_players *players = NULL;
+  struct event_cache_players *players = nullptr;
   va_list args;
 
   va_start(args, format);
-  vpackage_event(&genmsg, NULL, event, color, format, args);
+  vpackage_event(&genmsg, nullptr, event, color, format, args);
   va_end(args);
 
   research_players_iterate(presearch, aplayer) {
@@ -437,11 +438,11 @@ void notify_research_embassies(const struct research *presearch,
                                const char *format, ...)
 {
   struct packet_chat_msg genmsg;
-  struct event_cache_players *players = NULL;
+  struct event_cache_players *players = nullptr;
   va_list args;
 
   va_start(args, format);
-  vpackage_event(&genmsg, NULL, event, color, format, args);
+  vpackage_event(&genmsg, nullptr, event, color, format, args);
   va_end(args);
 
   players_iterate(aplayer) {
@@ -493,7 +494,7 @@ struct event_cache_players {
 };
 
 /* The full list of the events. */
-static struct event_cache_data_list *event_cache = NULL;
+static struct event_cache_data_list *event_cache = nullptr;
 
 /* Event cache status: ON(TRUE) / OFF(FALSE); used for saving the
  * event cache */
@@ -520,26 +521,26 @@ event_cache_data_new(const struct packet_chat_msg *packet,
   struct event_cache_data *pdata;
   int max_events;
 
-  if (NULL == event_cache) {
+  if (event_cache == nullptr) {
     /* Don't do log for this, because this could make an infinite
      * recursion. */
-    return NULL;
+    return nullptr;
   }
-  fc_assert_ret_val(NULL != packet, NULL);
+  fc_assert_ret_val(packet != nullptr, nullptr);
 
   if (packet->event == E_MESSAGE_WALL) {
     /* No popups at save game load. */
-    return NULL;
+    return nullptr;
   }
 
   if (!game.server.event_cache.chat && packet->event == E_CHAT_MSG) {
-    /* chat messages should _not_ be saved */
-    return NULL;
+    /* Chat messages should _not_ be saved */
+    return nullptr;
   }
 
-  /* check if cache is active */
+  /* Check if cache is active */
   if (!event_cache_status) {
-    return NULL;
+    return nullptr;
   }
 
   pdata = fc_malloc(sizeof(*pdata));
@@ -569,7 +570,7 @@ event_cache_data_new(const struct packet_chat_msg *packet,
 **************************************************************************/
 void event_cache_init(void)
 {
-  if (event_cache != NULL) {
+  if (event_cache != nullptr) {
     event_cache_free();
   }
   event_cache = event_cache_data_list_new_full(event_cache_data_free);
@@ -581,9 +582,9 @@ void event_cache_init(void)
 **************************************************************************/
 void event_cache_free(void)
 {
-  if (event_cache != NULL) {
+  if (event_cache != nullptr) {
     event_cache_data_list_destroy(event_cache);
-    event_cache = NULL;
+    event_cache = nullptr;
   }
   event_cache_status = FALSE;
 }
@@ -606,7 +607,7 @@ void event_cache_remove_old(void)
   /* This assumes that entries are in order, the ones to be removed first. */
   current = event_cache_data_list_get(event_cache, 0);
 
-    while (current != NULL
+    while (current != nullptr
            && current->packet.turn + game.server.event_cache.turns <= game.info.turn) {
     event_cache_data_list_pop_front(event_cache);
     current = event_cache_data_list_get(event_cache, 0);
@@ -619,8 +620,8 @@ void event_cache_remove_old(void)
 void event_cache_add_for_all(const struct packet_chat_msg *packet)
 {
   if (0 < game.server.event_cache.turns) {
-    (void) event_cache_data_new(packet, time(NULL),
-                                server_state(), ECT_ALL, NULL);
+    (void) event_cache_data_new(packet, time(nullptr),
+                                server_state(), ECT_ALL, nullptr);
   }
 }
 
@@ -630,22 +631,22 @@ void event_cache_add_for_all(const struct packet_chat_msg *packet)
 void event_cache_add_for_global_observers(const struct packet_chat_msg *packet)
 {
   if (0 < game.server.event_cache.turns) {
-    (void) event_cache_data_new(packet, time(NULL),
-                                server_state(), ECT_GLOBAL_OBSERVERS, NULL);
+    (void) event_cache_data_new(packet, time(nullptr),
+                                server_state(), ECT_GLOBAL_OBSERVERS, nullptr);
   }
 }
 
 /**********************************************************************//**
   Add an event to the cache for one player.
 
-  N.B.: event_cache_add_for_player(&packet, NULL) will have the same effect
+  N.B.: event_cache_add_for_player(&packet, nullptr) will have the same effect
         as event_cache_add_for_all(&packet).
   N.B.: in pregame, this will never success, because players are not fixed.
 **************************************************************************/
 void event_cache_add_for_player(const struct packet_chat_msg *packet,
                                 const struct player *pplayer)
 {
-  if (NULL == pplayer) {
+  if (pplayer == nullptr) {
     event_cache_add_for_all(packet);
     return;
   }
@@ -654,9 +655,11 @@ void event_cache_add_for_player(const struct packet_chat_msg *packet,
       && (server_state() > S_S_INITIAL || !game.info.is_new_game)) {
     struct event_cache_data *pdata;
 
-    pdata = event_cache_data_new(packet, time(NULL),
-                                 server_state(), ECT_PLAYERS, NULL);
-    fc_assert_ret(NULL != pdata);
+    pdata = event_cache_data_new(packet, time(nullptr),
+                                 server_state(), ECT_PLAYERS, nullptr);
+
+    fc_assert_ret(pdata != nullptr);
+
     BV_SET(pdata->target, player_index(pplayer));
   }
 }
@@ -672,24 +675,24 @@ void event_cache_add_for_players(const struct packet_chat_msg *packet,
                                  struct event_cache_players *players)
 {
   if (0 < game.server.event_cache.turns
-      && NULL != players
+      && players != nullptr
       && BV_ISSET_ANY(players->vector)
       && (server_state() > S_S_INITIAL || !game.info.is_new_game)) {
-    (void) event_cache_data_new(packet, time(NULL),
+    (void) event_cache_data_new(packet, time(nullptr),
                                 server_state(), ECT_PLAYERS, players);
   }
 
-  if (NULL != players) {
+  if (players != nullptr) {
     free(players);
   }
 }
 
 /**********************************************************************//**
-  Select players for event_cache_add_for_players(). Pass NULL as players
+  Select players for event_cache_add_for_players(). Pass nullptr as players
   argument to create a new selection. Usually the usage of this function
   would look to:
 
-  struct event_cache_players *players = NULL;
+  struct event_cache_players *players = nullptr;
 
   players_iterate(pplayer) {
     if (some_condition) {
@@ -703,12 +706,12 @@ struct event_cache_players *
 event_cache_player_add(struct event_cache_players *players,
                        const struct player *pplayer)
 {
-  if (NULL == players) {
+  if (players == nullptr) {
     players = fc_malloc(sizeof(*players));
     BV_CLR_ALL(players->vector);
   }
 
-  if (NULL != pplayer) {
+  if (pplayer != nullptr) {
     BV_SET(players->vector, player_index(pplayer));
   }
 
@@ -737,7 +740,7 @@ static bool event_cache_match(const struct event_cache_data *pdata,
   case ECT_ALL:
     return include_public;
   case ECT_PLAYERS:
-    return (NULL != pplayer
+    return (pplayer != nullptr
             && BV_ISSET(pdata->target, player_index(pplayer)));
   case ECT_GLOBAL_OBSERVERS:
     return is_global_observer;
@@ -785,7 +788,7 @@ void event_cache_load(struct section_file *file, const char *section)
   struct packet_chat_msg packet;
   enum event_cache_target target_type;
   enum server_states server_status;
-  struct event_cache_players *players = NULL;
+  struct event_cache_players *players = nullptr;
   int i, x, y, event_count;
   time_t timestamp, now;
   const char *p, *q;
@@ -797,12 +800,12 @@ void event_cache_load(struct section_file *file, const char *section)
     return;
   }
 
-  now = time(NULL);
+  now = time(nullptr);
   for (i = 0; i < event_count; i++) {
     int turn;
     int phase;
 
-    /* restore packet */
+    /* Restore packet */
     x = secfile_lookup_int_default(file, -1, "%s.events%d.x", section, i);
     y = secfile_lookup_int_default(file, -1, "%s.events%d.y", section, i);
     packet.tile = (is_normal_map_pos(x, y)
@@ -810,7 +813,7 @@ void event_cache_load(struct section_file *file, const char *section)
     packet.conn_id = -1;
 
     p = secfile_lookup_str(file, "%s.events%d.event", section, i);
-    if (NULL == p) {
+    if (p == nullptr) {
       log_verbose("[Event cache %4d] Missing event type.", i);
       continue;
     }
@@ -821,13 +824,13 @@ void event_cache_load(struct section_file *file, const char *section)
     }
 
     p = secfile_lookup_str(file, "%s.events%d.message", section, i);
-    if (NULL == p) {
+    if (p == nullptr) {
       log_verbose("[Event cache %4d] Missing message.", i);
       continue;
     }
     sz_strlcpy(packet.message, p);
 
-    /* restore event cache data */
+    /* Restore event cache data */
     turn = secfile_lookup_int_default(file, 0, "%s.events%d.turn",
                                       section, i);
     packet.turn = turn;
@@ -841,7 +844,7 @@ void event_cache_load(struct section_file *file, const char *section)
                                            section, i);
 
     p = secfile_lookup_str(file, "%s.events%d.server_state", section, i);
-    if (NULL == p) {
+    if (p == nullptr) {
       log_verbose("[Event cache %4d] Missing server state info.", i);
       continue;
     }
@@ -852,7 +855,7 @@ void event_cache_load(struct section_file *file, const char *section)
     }
 
     p = secfile_lookup_str(file, "%s.events%d.target", section, i);
-    if (NULL == p) {
+    if (p == nullptr) {
       log_verbose("[Event cache %4d] Missing target info.", i);
       continue;
     } else if (0 == fc_strcasecmp(p, "All")) {
@@ -876,20 +879,20 @@ void event_cache_load(struct section_file *file, const char *section)
         q++;
       } players_iterate_end;
 
-      if (!valid && NULL == players) {
+      if (!valid && players == nullptr) {
         log_verbose("[Event cache %4d] invalid target bitmap: %s", i, p);
-        if (NULL != players) {
+        if (players != nullptr) {
           FC_FREE(players);
         }
       }
     }
 
-    /* insert event into the cache */
+    /* Insert event into the cache */
     (void) event_cache_data_new(&packet, timestamp, server_status,
                                 target_type, players);
 
-    if (NULL != players) {
-      /* free the event cache player selection */
+    if (players != nullptr) {
+      /* Free the event cache player selection */
       FC_FREE(players);
     }
 
@@ -914,7 +917,7 @@ void event_cache_save(struct section_file *file, const char *section)
     char *p;
     int tile_x = -1, tile_y = -1;
 
-    if (ptile != NULL) {
+    if (ptile != nullptr) {
       index_to_map_pos(&tile_x, &tile_y, tile_index(ptile));
     }
 
-- 
2.53.0

