changeset 40159:069b50a66104

bitsetv: allow free on NULL. * lib/bitsetv.c (bitsetv_free): Do nothing when the bitsetv is NULL.
author Akim Demaille <akim.demaille@gmail.com>
date Sun, 27 Jan 2019 18:49:36 +0100
parents 383f7a766b7c
children 5c7e0484c1e9
files ChangeLog lib/bitsetv.c lib/bitsetv.h
diffstat 3 files changed, 12 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Sun Jan 27 16:55:27 2019 +0100
+++ b/ChangeLog	Sun Jan 27 18:49:36 2019 +0100
@@ -1,3 +1,8 @@
+2019-01-27  Akim Demaille  <akim@lrde.epita.fr>
+
+	bitsetv: allow free on NULL.
+	* lib/bitsetv.c (bitsetv_free): Do nothing when the bitsetv is NULL.
+
 2019-01-27  Bruno Haible  <bruno@clisp.org>
 
 	test-framework-sh: Improve maintainability.
--- a/lib/bitsetv.c	Sun Jan 27 16:55:27 2019 +0100
+++ b/lib/bitsetv.c	Sun Jan 27 18:49:36 2019 +0100
@@ -71,9 +71,12 @@
 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);
+    }
 }
 
 
--- a/lib/bitsetv.h	Sun Jan 27 16:55:27 2019 +0100
+++ b/lib/bitsetv.h	Sun Jan 27 18:49:36 2019 +0100
@@ -33,7 +33,7 @@
    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.  */