* bitsetv: allow free on NULL
@ 2019-01-27 17:58 Akim Demaille
2019-01-27 18:39 ` Bruno Haible
0 siblings, 1 reply; 2+ messages in thread
From: Akim Demaille @ 2019-01-27 17:58 UTC (permalink / raw)
To: Gnulib bugs
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 <akim.demaille@gmail.com>
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 <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.
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. */
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: bitsetv: allow free on NULL
2019-01-27 17:58 bitsetv: allow free on NULL Akim Demaille
@ 2019-01-27 18:39 ` Bruno Haible
0 siblings, 0 replies; 2+ messages in thread
From: Bruno Haible @ 2019-01-27 18:39 UTC (permalink / raw)
To: bug-gnulib; +Cc: Akim Demaille
> bitsetv: allow free on NULL.
>
> * lib/bitsetv.c (bitsetv_free): Do nothing when the bitsetv is NULL.
Looks good to me.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2019-01-27 18:49 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-01-27 17:58 bitsetv: allow free on NULL Akim Demaille
2019-01-27 18:39 ` Bruno Haible
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).