From 57b45c663c3652e635e32a91619d2c758a36c267 Mon Sep 17 00:00:00 2001
From: Marko Lindqvist <cazfi74@gmail.com>
Date: Fri, 10 May 2024 17:13:44 +0300
Subject: [PATCH 72/72] Add nonnull attributes for string_vector.[ch] functions

See RM #582

Signed-off-by: Marko Lindqvist <cazfi74@gmail.com>
---
 utility/string_vector.c |  4 ---
 utility/string_vector.h | 54 +++++++++++++++++++++++++++--------------
 2 files changed, 36 insertions(+), 22 deletions(-)

diff --git a/utility/string_vector.c b/utility/string_vector.c
index 48564cc5be..bde00886d7 100644
--- a/utility/string_vector.c
+++ b/utility/string_vector.c
@@ -429,8 +429,6 @@ void strvec_to_str(const struct strvec *psv, char separator,
 const char *strvec_to_or_list(const struct strvec *psv,
                               struct astring *astr)
 {
-  fc_assert_ret_val(psv != nullptr, nullptr);
-
   return astr_build_or_list(astr, (const char **) psv->vec, psv->size);
 }
 
@@ -443,7 +441,5 @@ const char *strvec_to_or_list(const struct strvec *psv,
 const char *strvec_to_and_list(const struct strvec *psv,
                                struct astring *astr)
 {
-  fc_assert_ret_val(psv != nullptr, nullptr);
-
   return astr_build_and_list(astr, (const char **) psv->vec, psv->size);
 }
diff --git a/utility/string_vector.h b/utility/string_vector.h
index ee8224a2cb..b2905ce658 100644
--- a/utility/string_vector.h
+++ b/utility/string_vector.h
@@ -27,35 +27,53 @@ struct strvec;                  /* Opaque. */
 struct strvec *strvec_new(void);
 void strvec_destroy(struct strvec *psv);
 
-void strvec_reserve(struct strvec *psv, size_t reserve);
-void strvec_store(struct strvec *psv, const char *const *vec, size_t size);
-void strvec_from_str(struct strvec *psv,  char separator, const char *str);
-void strvec_clear(struct strvec *psv);
-void strvec_remove_empty(struct strvec *psv);
+void strvec_reserve(struct strvec *psv, size_t reserve)
+  fc__attribute((nonnull (1)));
+void strvec_store(struct strvec *psv, const char *const *vec, size_t size)
+  fc__attribute((nonnull (1, 2)));
+void strvec_from_str(struct strvec *psv,  char separator, const char *str)
+  fc__attribute((nonnull (1)));
+void strvec_clear(struct strvec *psv)
+  fc__attribute((nonnull (1)));
+void strvec_remove_empty(struct strvec *psv)
+  fc__attribute((nonnull (1)));
 void strvec_remove_duplicate(struct strvec *psv,
-                             int (*cmp_func) (const char *, const char *));
-void strvec_copy(struct strvec *dest, const struct strvec *src);
+                             int (*cmp_func) (const char *, const char *))
+  fc__attribute((nonnull (1)));
+void strvec_copy(struct strvec *dest, const struct strvec *src)
+  fc__attribute((nonnull (1, 2)));
 void strvec_sort(struct strvec *psv, int (*sort_func) (const char *const *,
-                                                       const char *const *));
+                                                       const char *const *))
+  fc__attribute((nonnull (1)));
 
-void strvec_prepend(struct strvec *psv, const char *string);
-void strvec_append(struct strvec *psv, const char *string);
-void strvec_insert(struct strvec *psv, size_t svindex, const char *string);
+void strvec_prepend(struct strvec *psv, const char *string)
+  fc__attribute((nonnull (1)));
+void strvec_append(struct strvec *psv, const char *string)
+  fc__attribute((nonnull (1)));
+void strvec_insert(struct strvec *psv, size_t svindex, const char *string)
+  fc__attribute((nonnull (1)));
 bool strvec_set(struct strvec *psv, size_t svindex, const char *string);
 bool strvec_remove(struct strvec *psv, size_t svindex);
 
-size_t strvec_size(const struct strvec *psv);
+size_t strvec_size(const struct strvec *psv)
+  fc__attribute((nonnull (1)));
 bool are_strvecs_equal(const struct strvec *stv1,
-                       const struct strvec *stv2);
-const char *const *strvec_data(const struct strvec *psv);
-bool strvec_index_valid(const struct strvec *psv, size_t svindex);
-const char *strvec_get(const struct strvec *psv, size_t svindex);
+                       const struct strvec *stv2)
+  fc__attribute((nonnull (1, 2)));
+const char *const *strvec_data(const struct strvec *psv)
+  fc__attribute((nonnull (1)));
+bool strvec_index_valid(const struct strvec *psv, size_t svindex)
+  fc__attribute((nonnull (1)));
+const char *strvec_get(const struct strvec *psv, size_t svindex)
+  fc__attribute((nonnull (1)));
 void strvec_to_str(const struct strvec *psv, char separator,
                    char *buf, size_t buf_len);
 const char *strvec_to_or_list(const struct strvec *psv,
-                              struct astring *astr);
+                              struct astring *astr)
+  fc__attribute((nonnull (1)));
 const char *strvec_to_and_list(const struct strvec *psv,
-                               struct astring *astr);
+                               struct astring *astr)
+  fc__attribute((nonnull (1)));
 
 /* Iteration macro. */
 #define strvec_iterate(psv, str) \
-- 
2.43.0

