From 1f4e972316fdeddfb85bccc843b77334f458ee24 Mon Sep 17 00:00:00 2001
From: Marko Lindqvist <cazfi74@gmail.com>
Date: Sun, 29 Mar 2026 09:59:12 +0300
Subject: [PATCH 22/22] government.c: Replace NULL with nullptr

See RM #1972

Signed-off-by: Marko Lindqvist <cazfi74@gmail.com>
---
 common/government.c | 92 ++++++++++++++++++++++++---------------------
 1 file changed, 50 insertions(+), 42 deletions(-)

diff --git a/common/government.c b/common/government.c
index fed4706455..87934bbc88 100644
--- a/common/government.c
+++ b/common/government.c
@@ -31,13 +31,13 @@
 
 #include "government.h"
 
-struct government *governments = NULL;
+struct government *governments = nullptr;
 
 static struct user_flag user_gov_flags[MAX_NUM_USER_GOVERNMENT_FLAGS];
 
 /**********************************************************************//**
   Returns the government that has the given (translated) name.
-  Returns NULL if none match.
+  Returns nullptr if none match.
 **************************************************************************/
 struct government *government_by_translated_name(const char *name)
 {
@@ -47,12 +47,12 @@ struct government *government_by_translated_name(const char *name)
     }
   } governments_iterate_end;
 
-  return NULL;
+  return nullptr;
 }
 
 /**********************************************************************//**
   Returns the government that has the given (untranslated) rule name.
-  Returns NULL if none match.
+  Returns nullptr if none match.
 **************************************************************************/
 struct government *government_by_rule_name(const char *name)
 {
@@ -64,7 +64,7 @@ struct government *government_by_rule_name(const char *name)
     }
   } governments_iterate_end;
 
-  return NULL;
+  return nullptr;
 }
 
 /**********************************************************************//**
@@ -83,7 +83,8 @@ Government_type_id government_count(void)
 **************************************************************************/
 Government_type_id government_index(const struct government *pgovern)
 {
-  fc_assert_ret_val(NULL != pgovern, -1);
+  fc_assert_ret_val(pgovern != nullptr, -1);
+
   return pgovern - governments;
 }
 
@@ -92,21 +93,23 @@ Government_type_id government_index(const struct government *pgovern)
 **************************************************************************/
 Government_type_id government_number(const struct government *pgovern)
 {
-  fc_assert_ret_val(NULL != pgovern, -1);
+  fc_assert_ret_val(pgovern != nullptr, -1);
+
   return pgovern->item_number;
 }
 
 /**********************************************************************//**
   Return the government with the given index.
 
-  This function returns NULL for an out-of-range index (some callers
+  This function returns nullptr for an out-of-range index (some callers
   rely on this).
 **************************************************************************/
 struct government *government_by_number(const Government_type_id gov)
 {
   if (gov < 0 || gov >= game.control.government_count) {
-    return NULL;
+    return nullptr;
   }
+
   return &governments[gov];
 }
 
@@ -115,7 +118,8 @@ struct government *government_by_number(const Government_type_id gov)
 **************************************************************************/
 struct government *government_of_player(const struct player *pplayer)
 {
-  fc_assert_ret_val(NULL != pplayer, NULL);
+  fc_assert_ret_val(pplayer != nullptr, nullptr);
+
   return pplayer->government;
 }
 
@@ -124,7 +128,8 @@ struct government *government_of_player(const struct player *pplayer)
 **************************************************************************/
 struct government *government_of_city(const struct city *pcity)
 {
-  fc_assert_ret_val(NULL != pcity, NULL);
+  fc_assert_ret_val(pcity != nullptr, nullptr);
+
   return government_of_player(city_owner(pcity));
 }
 
@@ -134,7 +139,8 @@ struct government *government_of_city(const struct city *pcity)
 **************************************************************************/
 const char *government_rule_name(const struct government *pgovern)
 {
-  fc_assert_ret_val(NULL != pgovern, NULL);
+  fc_assert_ret_val(pgovern != nullptr, nullptr);
+
   return rule_name_get(&pgovern->name);
 }
 
@@ -144,7 +150,7 @@ const char *government_rule_name(const struct government *pgovern)
 **************************************************************************/
 const char *government_name_translation(const struct government *pgovern)
 {
-  fc_assert_ret_val(NULL != pgovern, NULL);
+  fc_assert_ret_val(pgovern != nullptr, nullptr);
 
   return name_translation_get(&pgovern->name);
 }
@@ -167,12 +173,12 @@ const char *government_name_for_player(const struct player *pplayer)
    - no required tech (required is A_NONE)
    - player has required tech
    - we have an appropriate wonder
-  Returns FALSE if pplayer is NULL (used for observers).
+  Returns FALSE if pplayer is nullptr (used for observers).
 **************************************************************************/
 bool can_change_to_government(struct player *pplayer,
                               const struct government *gov)
 {
-  fc_assert_ret_val(NULL != gov, FALSE);
+  fc_assert_ret_val(gov != nullptr, FALSE);
 
   if (!pplayer) {
     return FALSE;
@@ -184,7 +190,7 @@ bool can_change_to_government(struct player *pplayer,
   }
 
   return are_reqs_active(&(const struct req_context) { .player = pplayer },
-                         NULL, &gov->reqs, RPT_CERTAIN);
+                         nullptr, &gov->reqs, RPT_CERTAIN);
 }
 
 
@@ -202,7 +208,7 @@ struct ruler_title {
 **************************************************************************/
 static genhash_val_t nation_hash_val(const struct nation_type *pnation)
 {
-  return NULL != pnation ? nation_number(pnation) : nation_count();
+  return pnation != nullptr ? nation_number(pnation) : nation_count();
 }
 
 /**********************************************************************//**
@@ -247,7 +253,7 @@ static bool ruler_title_check(const struct ruler_title *pruler_title)
   bool ret = TRUE;
 
   if (!formats_match(rule_name_get(&pruler_title->male), "%s")) {
-    if (NULL != pruler_title->pnation) {
+    if (pruler_title->pnation != nullptr) {
       log_error("\"%s\" male ruler title for nation \"%s\" (nb %d) "
                 "is not a format. It should match \"%%s\"",
                 rule_name_get(&pruler_title->male),
@@ -262,7 +268,7 @@ static bool ruler_title_check(const struct ruler_title *pruler_title)
   }
 
   if (!formats_match(rule_name_get(&pruler_title->female), "%s")) {
-    if (NULL != pruler_title->pnation) {
+    if (pruler_title->pnation != nullptr) {
       log_error("\"%s\" female ruler title for nation \"%s\" (nb %d) "
                 "is not a format. It should match \"%%s\"",
                 rule_name_get(&pruler_title->female),
@@ -277,7 +283,7 @@ static bool ruler_title_check(const struct ruler_title *pruler_title)
   }
 
   if (!formats_match(name_translation_get(&pruler_title->male), "%s")) {
-    if (NULL != pruler_title->pnation) {
+    if (pruler_title->pnation != nullptr) {
       log_error("Translation of \"%s\" male ruler title for nation \"%s\" "
                 "(nb %d) is not a format (\"%s\"). It should match \"%%s\"",
                 rule_name_get(&pruler_title->male),
@@ -294,7 +300,7 @@ static bool ruler_title_check(const struct ruler_title *pruler_title)
   }
 
   if (!formats_match(name_translation_get(&pruler_title->female), "%s")) {
-    if (NULL != pruler_title->pnation) {
+    if (pruler_title->pnation != nullptr) {
       log_error("Translation of \"%s\" female ruler title for nation \"%s\" "
                 "(nb %d) is not a format (\"%s\"). It should match \"%%s\"",
                 rule_name_get(&pruler_title->female),
@@ -319,13 +325,14 @@ static bool ruler_title_check(const struct ruler_title *pruler_title)
 const struct ruler_title_hash *
 government_ruler_titles(const struct government *pgovern)
 {
-  fc_assert_ret_val(NULL != pgovern, NULL);
+  fc_assert_ret_val(pgovern != nullptr, nullptr);
+
   return pgovern->ruler_titles;
 }
 
 /**********************************************************************//**
-  Add a new ruler title for the nation. Pass NULL for pnation for defining
-  the default title.
+  Add a new ruler title for the nation. Pass nullptr for pnation
+  for defining the default title.
 **************************************************************************/
 struct ruler_title *
 government_ruler_title_new(struct government *pgovern,
@@ -333,10 +340,10 @@ government_ruler_title_new(struct government *pgovern,
                            const char *ruler_male_title,
                            const char *ruler_female_title)
 {
-  const char *domain = NULL;
+  const char *domain = nullptr;
   struct ruler_title *pruler_title;
 
-  if (pnation != NULL) {
+  if (pnation != nullptr) {
     domain = pnation->translation_domain;
   }
   pruler_title =
@@ -344,12 +351,12 @@ government_ruler_title_new(struct government *pgovern,
 
   if (!ruler_title_check(pruler_title)) {
     ruler_title_destroy(pruler_title);
-    return NULL;
+    return nullptr;
   }
 
   if (ruler_title_hash_replace(pgovern->ruler_titles,
                                pnation, pruler_title)) {
-    if (NULL != pnation) {
+    if (pnation != nullptr) {
       log_error("Ruler title for government \"%s\" (nb %d) and "
                 "nation \"%s\" (nb %d) was set twice.",
                 government_rule_name(pgovern), government_number(pgovern),
@@ -365,7 +372,7 @@ government_ruler_title_new(struct government *pgovern,
 }
 
 /**********************************************************************//**
-  Return the nation of the ruler title. Returns NULL if this is default.
+  Return the nation of the ruler title. Returns nullptr if this is default.
 **************************************************************************/
 const struct nation_type *
 ruler_title_nation(const struct ruler_title *pruler_title)
@@ -401,15 +408,15 @@ const char *ruler_title_for_player(const struct player *pplayer,
   const struct nation_type *pnation = nation_of_player(pplayer);
   struct ruler_title *pruler_title;
 
-  fc_assert_ret_val(NULL != buf, NULL);
-  fc_assert_ret_val(0 < buf_len, NULL);
+  fc_assert_ret_val(buf != nullptr, nullptr);
+  fc_assert_ret_val(0 < buf_len, nullptr);
 
   /* Try specific nation ruler title. */
   if (!ruler_title_hash_lookup(pgovern->ruler_titles,
                                pnation, &pruler_title)
       /* Try default ruler title. */
       && !ruler_title_hash_lookup(pgovern->ruler_titles,
-                                  NULL, &pruler_title)) {
+                                  nullptr, &pruler_title)) {
     log_error("Missing title for government \"%s\" (nb %d) "
               "nation \"%s\" (nb %d).",
               government_rule_name(pgovern), government_number(pgovern),
@@ -504,13 +511,13 @@ static inline void government_init(struct government *pgovern)
   memset(pgovern, 0, sizeof(*pgovern));
 
   pgovern->item_number = pgovern - governments;
-  pgovern->ruler_titles =
-      ruler_title_hash_new_full(nation_hash_val, nation_hash_comp,
-                                NULL, NULL, NULL, ruler_title_destroy);
+  pgovern->ruler_titles
+    = ruler_title_hash_new_full(nation_hash_val, nation_hash_comp,
+                                nullptr, nullptr, nullptr, ruler_title_destroy);
   requirement_vector_init(&pgovern->reqs);
   pgovern->changed_to_times = 0;
   pgovern->ruledit_disabled = FALSE;
-  pgovern->ruledit_dlg = NULL;
+  pgovern->ruledit_dlg = nullptr;
 }
 
 /**********************************************************************//**
@@ -519,11 +526,11 @@ static inline void government_init(struct government *pgovern)
 static inline void government_free(struct government *pgovern)
 {
   ruler_title_hash_destroy(pgovern->ruler_titles);
-  pgovern->ruler_titles = NULL;
+  pgovern->ruler_titles = nullptr;
 
-  if (NULL != pgovern->helptext) {
+  if (pgovern->helptext != nullptr) {
     strvec_destroy(pgovern->helptext);
-    pgovern->helptext = NULL;
+    pgovern->helptext = nullptr;
   }
 
   requirement_vector_free(&pgovern->reqs);
@@ -536,7 +543,8 @@ void governments_alloc(int num)
 {
   int i;
 
-  fc_assert(NULL == governments);
+  fc_assert(governments == nullptr);
+
   governments = fc_malloc(sizeof(*governments) * num);
   game.control.government_count = num;
 
@@ -552,7 +560,7 @@ void governments_free(void)
 {
   int i;
 
-  if (NULL == governments) {
+  if (governments == nullptr) {
     return;
   }
 
@@ -561,7 +569,7 @@ void governments_free(void)
   }
 
   free(governments);
-  governments = NULL;
+  governments = nullptr;
   game.control.government_count = 0;
 }
 
-- 
2.53.0

