From af6ea552c0b649c65af274f2db85055a701b60d4 Mon Sep 17 00:00:00 2001
From: Marko Lindqvist <cazfi74@gmail.com>
Date: Thu, 23 May 2024 21:50:39 +0300
Subject: [PATCH 92/92] bitvector.c: Replace parameter checking fc_asserts with
 nonnull attributes

See RM #665

Signed-off-by: Marko Lindqvist <cazfi74@gmail.com>
---
 utility/bitvector.c |  9 ---------
 utility/bitvector.h | 30 +++++++++++++++++++-----------
 2 files changed, 19 insertions(+), 20 deletions(-)

diff --git a/utility/bitvector.c b/utility/bitvector.c
index c4a435cc72..62891fd097 100644
--- a/utility/bitvector.c
+++ b/utility/bitvector.c
@@ -119,7 +119,6 @@ int dbv_bits(struct dbv *pdbv)
 ***************************************************************************/
 bool dbv_isset(const struct dbv *pdbv, int bit)
 {
-  fc_assert_ret_val(pdbv != nullptr, FALSE);
   fc_assert_ret_val(pdbv->vec != nullptr, FALSE);
   fc_assert_ret_val(bit < pdbv->bits, FALSE);
 
@@ -131,7 +130,6 @@ bool dbv_isset(const struct dbv *pdbv, int bit)
 ***************************************************************************/
 bool dbv_isset_any(const struct dbv *pdbv)
 {
-  fc_assert_ret_val(pdbv != nullptr, FALSE);
   fc_assert_ret_val(pdbv->vec != nullptr, FALSE);
 
   return bv_check_mask(pdbv->vec, pdbv->vec, _BV_BYTES(pdbv->bits),
@@ -143,7 +141,6 @@ bool dbv_isset_any(const struct dbv *pdbv)
 ***************************************************************************/
 void dbv_set(struct dbv *pdbv, int bit)
 {
-  fc_assert_ret(pdbv != nullptr);
   fc_assert_ret(pdbv->vec != nullptr);
   fc_assert_ret(bit < pdbv->bits);
 
@@ -155,7 +152,6 @@ void dbv_set(struct dbv *pdbv, int bit)
 ***************************************************************************/
 void dbv_set_all(struct dbv *pdbv)
 {
-  fc_assert_ret(pdbv != nullptr);
   fc_assert_ret(pdbv->vec != nullptr);
 
   memset(pdbv->vec, 0xff, _BV_BYTES(pdbv->bits));
@@ -166,7 +162,6 @@ void dbv_set_all(struct dbv *pdbv)
 ***************************************************************************/
 void dbv_clr(struct dbv *pdbv, int bit)
 {
-  fc_assert_ret(pdbv != nullptr);
   fc_assert_ret(pdbv->vec != nullptr);
   fc_assert_ret(bit < pdbv->bits);
 
@@ -178,7 +173,6 @@ void dbv_clr(struct dbv *pdbv, int bit)
 ***************************************************************************/
 void dbv_clr_all(struct dbv *pdbv)
 {
-  fc_assert_ret(pdbv != nullptr);
   fc_assert_ret(pdbv->vec != nullptr);
 
   memset(pdbv->vec, 0, _BV_BYTES(pdbv->bits));
@@ -189,9 +183,7 @@ void dbv_clr_all(struct dbv *pdbv)
 ***************************************************************************/
 bool dbv_are_equal(const struct dbv *pdbv1, const struct dbv *pdbv2)
 {
-  fc_assert_ret_val(pdbv1 != nullptr, FALSE);
   fc_assert_ret_val(pdbv1->vec != nullptr, FALSE);
-  fc_assert_ret_val(pdbv2 != nullptr, FALSE);
   fc_assert_ret_val(pdbv2->vec != nullptr, FALSE);
 
   return bv_are_equal(pdbv1->vec, pdbv2->vec, _BV_BYTES(pdbv1->bits),
@@ -254,7 +246,6 @@ void dbv_debug(struct dbv *pdbv)
   char test_str[51];
   int i, j, bit;
 
-  fc_assert_ret(pdbv != nullptr);
   fc_assert_ret(pdbv->vec != nullptr);
 
   for (i = 0; i < (pdbv->bits - 1) / 50 + 1; i++) {
diff --git a/utility/bitvector.h b/utility/bitvector.h
index 7c0879a4cf..e855c4e18a 100644
--- a/utility/bitvector.h
+++ b/utility/bitvector.h
@@ -40,23 +40,31 @@ void dbv_free(struct dbv *pdbv);
 
 int dbv_bits(struct dbv *pdbv);
 
-bool dbv_isset(const struct dbv *pdbv, int bit);
-bool dbv_isset_any(const struct dbv *pdbv);
-
-void dbv_set(struct dbv *pdbv, int bit);
-void dbv_set_all(struct dbv *pdbv);
-
-void dbv_clr(struct dbv *pdbv, int bit);
-void dbv_clr_all(struct dbv *pdbv);
-
-bool dbv_are_equal(const struct dbv *pdbv1, const struct dbv *pdbv2);
+bool dbv_isset(const struct dbv *pdbv, int bit)
+  fc__attribute((nonnull (1)));
+bool dbv_isset_any(const struct dbv *pdbv)
+  fc__attribute((nonnull (1)));
+
+void dbv_set(struct dbv *pdbv, int bit)
+  fc__attribute((nonnull (1)));
+void dbv_set_all(struct dbv *pdbv)
+  fc__attribute((nonnull (1)));
+
+void dbv_clr(struct dbv *pdbv, int bit)
+  fc__attribute((nonnull (1)));
+void dbv_clr_all(struct dbv *pdbv)
+  fc__attribute((nonnull (1)));
+
+bool dbv_are_equal(const struct dbv *pdbv1, const struct dbv *pdbv2)
+  fc__attribute((nonnull (1, 2)));
 bool bv_match_dbv(const struct dbv *match, const unsigned char *src);
 void dbv_copy(struct dbv *dest, const struct dbv *src);
 
 void dbv_to_bv(unsigned char *dest, const struct dbv *src);
 void bv_to_dbv(struct dbv *dest, const unsigned char *src);
 
-void dbv_debug(struct dbv *pdbv);
+void dbv_debug(struct dbv *pdbv)
+  fc__attribute((nonnull (1)));
 
 /* Maximal size of a dynamic bitvector.
    Use a large value to be on the safe side (4Mbits = 512kbytes). */
-- 
2.43.0

