bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bitsetv: allow free on NULL


From: Akim Demaille
Subject: bitsetv: allow free on NULL
Date: Sun, 27 Jan 2019 18:58:48 +0100

I can live with the 'if' on the caller of bitsetv_free, but I felt it's 
somewhat consistent with free accepting NULL.

commit 954d1e36aa815994f7f5b1fcd46ebc96a63b8df4
Author: Akim Demaille <address@hidden>
Date:   Sun Jan 27 18:49:36 2019 +0100

    bitsetv: allow free on NULL.
    
    * lib/bitsetv.c (bitsetv_free): Do nothing when the bitsetv is NULL.

diff --git a/ChangeLog b/ChangeLog
index 4e90bfd66..613404442 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2019-01-27  Akim Demaille  <address@hidden>
+
+       bitsetv: allow free on NULL.
+       * lib/bitsetv.c (bitsetv_free): Do nothing when the bitsetv is NULL.
+
 2019-01-27  Bruno Haible  <address@hidden>
 
        test-framework-sh: Improve maintainability.
diff --git a/lib/bitsetv.c b/lib/bitsetv.c
index e3cc5845a..b7d0a0191 100644
--- a/lib/bitsetv.c
+++ b/lib/bitsetv.c
@@ -71,9 +71,12 @@ bitsetv_create (bitset_bindex n_vecs, bitset_bindex n_bits, 
unsigned attr)
 void
 bitsetv_free (bitsetv bsetv)
 {
-  for (bitset_bindex i = 0; bsetv[i]; i++)
-    BITSET_FREE_ (bsetv[i]);
-  free (bsetv);
+  if (bsetv)
+    {
+      for (bitset_bindex i = 0; bsetv[i]; i++)
+        BITSET_FREE_ (bsetv[i]);
+      free (bsetv);
+    }
 }
 
 
diff --git a/lib/bitsetv.h b/lib/bitsetv.h
index 798b70d9b..0971d7adc 100644
--- a/lib/bitsetv.h
+++ b/lib/bitsetv.h
@@ -33,7 +33,7 @@ bitsetv bitsetv_alloc (bitset_bindex, bitset_bindex, enum 
bitset_type);
    attribute hints specified by ATTR.  */
 bitsetv bitsetv_create (bitset_bindex, bitset_bindex, unsigned);
 
-/* Free vector of bitsets.  */
+/* Free vector of bitsets.  Do nothing if NULL.  */
 void bitsetv_free (bitsetv);
 
 /* Zero vector of bitsets.  */




reply via email to

[Prev in Thread] Current Thread [Next in Thread]