From 24dc83813a6c4942f65dde7f6902674fb27f0aac Mon Sep 17 00:00:00 2001
From: Marko Lindqvist <cazfi74@gmail.com>
Date: Sun, 26 Apr 2026 10:41:41 +0300
Subject: [PATCH 31/31] government.c: Replace parameter checking fc_asserts
 with nonnull attributes

See RM #1971

Signed-off-by: Marko Lindqvist <cazfi74@gmail.com>
---
 common/government.c | 19 +------------------
 common/government.h | 27 ++++++++++++++++++---------
 2 files changed, 19 insertions(+), 27 deletions(-)

diff --git a/common/government.c b/common/government.c
index 87934bbc88..ce96a4c246 100644
--- a/common/government.c
+++ b/common/government.c
@@ -83,8 +83,6 @@ Government_type_id government_count(void)
 **************************************************************************/
 Government_type_id government_index(const struct government *pgovern)
 {
-  fc_assert_ret_val(pgovern != nullptr, -1);
-
   return pgovern - governments;
 }
 
@@ -93,8 +91,6 @@ Government_type_id government_index(const struct government *pgovern)
 **************************************************************************/
 Government_type_id government_number(const struct government *pgovern)
 {
-  fc_assert_ret_val(pgovern != nullptr, -1);
-
   return pgovern->item_number;
 }
 
@@ -118,8 +114,6 @@ struct government *government_by_number(const Government_type_id gov)
 **************************************************************************/
 struct government *government_of_player(const struct player *pplayer)
 {
-  fc_assert_ret_val(pplayer != nullptr, nullptr);
-
   return pplayer->government;
 }
 
@@ -128,8 +122,6 @@ struct government *government_of_player(const struct player *pplayer)
 **************************************************************************/
 struct government *government_of_city(const struct city *pcity)
 {
-  fc_assert_ret_val(pcity != nullptr, nullptr);
-
   return government_of_player(city_owner(pcity));
 }
 
@@ -139,8 +131,6 @@ struct government *government_of_city(const struct city *pcity)
 **************************************************************************/
 const char *government_rule_name(const struct government *pgovern)
 {
-  fc_assert_ret_val(pgovern != nullptr, nullptr);
-
   return rule_name_get(&pgovern->name);
 }
 
@@ -150,8 +140,6 @@ const char *government_rule_name(const struct government *pgovern)
 **************************************************************************/
 const char *government_name_translation(const struct government *pgovern)
 {
-  fc_assert_ret_val(pgovern != nullptr, nullptr);
-
   return name_translation_get(&pgovern->name);
 }
 
@@ -178,9 +166,7 @@ const char *government_name_for_player(const struct player *pplayer)
 bool can_change_to_government(struct player *pplayer,
                               const struct government *gov)
 {
-  fc_assert_ret_val(gov != nullptr, FALSE);
-
-  if (!pplayer) {
+  if (pplayer == nullptr) {
     return FALSE;
   }
 
@@ -325,8 +311,6 @@ 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(pgovern != nullptr, nullptr);
-
   return pgovern->ruler_titles;
 }
 
@@ -408,7 +392,6 @@ 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(buf != nullptr, nullptr);
   fc_assert_ret_val(0 < buf_len, nullptr);
 
   /* Try specific nation ruler title. */
diff --git a/common/government.h b/common/government.h
index 69a2e44731..a27ecd250a 100644
--- a/common/government.h
+++ b/common/government.h
@@ -76,23 +76,30 @@ struct government {
 
 /* General government accessor functions. */
 Government_type_id government_count(void);
-Government_type_id government_index(const struct government *pgovern);
-Government_type_id government_number(const struct government *pgovern);
+Government_type_id government_index(const struct government *pgovern)
+  fc__attribute((nonnull(1)));
+Government_type_id government_number(const struct government *pgovern)
+  fc__attribute((nonnull(1)));
 
 struct government *government_by_number(const Government_type_id gov);
-struct government *government_of_player(const struct player *pplayer);
-struct government *government_of_city(const struct city *pcity);
+struct government *government_of_player(const struct player *pplayer)
+  fc__attribute((nonnull(1)));
+struct government *government_of_city(const struct city *pcity)
+  fc__attribute((nonnull(1)));
 
 struct government *government_by_rule_name(const char *name);
 struct government *government_by_translated_name(const char *name);
 
-const char *government_rule_name(const struct government *pgovern);
-const char *government_name_translation(const struct government *pgovern);
+const char *government_rule_name(const struct government *pgovern)
+  fc__attribute((nonnull(1)));
+const char *government_name_translation(const struct government *pgovern)
+  fc__attribute((nonnull(1)));
 const char *government_name_for_player(const struct player *pplayer);
 
 /* Ruler titles. */
 const struct ruler_title_hash *
-government_ruler_titles(const struct government *pgovern);
+government_ruler_titles(const struct government *pgovern)
+  fc__attribute((nonnull(1)));
 struct ruler_title *
 government_ruler_title_new(struct government *pgovern,
                            const struct nation_type *pnation,
@@ -107,13 +114,15 @@ const char *
 ruler_title_female_untranslated_name(const struct ruler_title *pruler_title);
 
 const char *ruler_title_for_player(const struct player *pplayer,
-                                   char *buf, size_t buf_len);
+                                   char *buf, size_t buf_len)
+  fc__attribute((nonnull(2)));
 const char *default_title_for_player(const struct player *pplayer,
                                      char *buf, size_t buf_len);
 
 /* Ancillary routines */
 bool can_change_to_government(struct player *pplayer,
-                              const struct government *pgovern);
+                              const struct government *pgovern)
+  fc__attribute((nonnull(2)));
 
 /* Initialization and iteration */
 void governments_alloc(int num);
-- 
2.53.0

