From: Akim Demaille Date: Fri, 6 Sep 2019 09:38:48 +0000 (+0200) Subject: bitset: style changes X-Git-Tag: v1.0~4674 X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=03add7eb9d06ab509034ba01c904a4cb36f5706b;p=gnulib.git bitset: style changes * lib/bitset/vector.c (vbitset_resize): Factor computation. * lib/bitset.c, lib/bitset/stats.c, lib/bitsetv.c: Prefer xzalloc to xcalloc. Suggested by Paul Eggert. --- diff --git a/ChangeLog b/ChangeLog index 077471de99..5c226ce436 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2019-09-06 Akim Demaille + + bitset: style changes + * lib/bitset/vector.c (vbitset_resize): Factor computation. + * lib/bitset.c, lib/bitset/stats.c, lib/bitsetv.c: Prefer + xzalloc to xcalloc. + Suggested by Paul Eggert. + 2019-09-06 Akim Demaille bitset: check memory allocation diff --git a/lib/bitset.c b/lib/bitset.c index cccb1e8347..6b983f438f 100644 --- a/lib/bitset.c +++ b/lib/bitset.c @@ -129,7 +129,7 @@ bitset_alloc (bitset_bindex n_bits, enum bitset_type type) { size_t bytes = bitset_bytes (type, n_bits); - bitset bset = xcalloc (1, bytes); + bitset bset = xzalloc (bytes); /* The cache is disabled until some elements are allocated. If we have variable length arrays, then we may need to allocate a dummy diff --git a/lib/bitset/stats.c b/lib/bitset/stats.c index da73cdcac5..fd1ca5912a 100644 --- a/lib/bitset/stats.c +++ b/lib/bitset/stats.c @@ -694,7 +694,7 @@ bitset_stats_init (bitset bset, bitset_bindex n_bits, enum bitset_type type) case BITSET_ARRAY: { size_t bytes = abitset_bytes (n_bits); - bset->s.bset = xcalloc (1, bytes); + bset->s.bset = xzalloc (bytes); abitset_init (bset->s.bset, n_bits); } break; @@ -702,7 +702,7 @@ bitset_stats_init (bitset bset, bitset_bindex n_bits, enum bitset_type type) case BITSET_LIST: { size_t bytes = lbitset_bytes (n_bits); - bset->s.bset = xcalloc (1, bytes); + bset->s.bset = xzalloc (bytes); lbitset_init (bset->s.bset, n_bits); } break; @@ -710,7 +710,7 @@ bitset_stats_init (bitset bset, bitset_bindex n_bits, enum bitset_type type) case BITSET_TABLE: { size_t bytes = tbitset_bytes (n_bits); - bset->s.bset = xcalloc (1, bytes); + bset->s.bset = xzalloc (bytes); tbitset_init (bset->s.bset, n_bits); } break; @@ -718,7 +718,7 @@ bitset_stats_init (bitset bset, bitset_bindex n_bits, enum bitset_type type) case BITSET_VECTOR: { size_t bytes = vbitset_bytes (n_bits); - bset->s.bset = xcalloc (1, bytes); + bset->s.bset = xzalloc (bytes); vbitset_init (bset->s.bset, n_bits); } break; diff --git a/lib/bitset/vector.c b/lib/bitset/vector.c index 5e543283a2..ac9ba803b6 100644 --- a/lib/bitset/vector.c +++ b/lib/bitset/vector.c @@ -82,7 +82,6 @@ vbitset_resize (bitset src, bitset_bindex n_bits) memset (VBITSET_WORDS (src) + oldsize, 0, (newsize - oldsize) * sizeof (bitset_word)); - VBITSET_SIZE (src) = newsize; } else { @@ -100,10 +99,9 @@ vbitset_resize (bitset src, bitset_bindex n_bits) } /* Need to prune any excess bits. FIXME. */ - - VBITSET_SIZE (src) = newsize; } + VBITSET_SIZE (src) = newsize; BITSET_NBITS_ (src) = n_bits; return n_bits; } diff --git a/lib/bitsetv.c b/lib/bitsetv.c index b7d0a01913..745f27aefc 100644 --- a/lib/bitsetv.c +++ b/lib/bitsetv.c @@ -41,7 +41,7 @@ bitsetv_alloc (bitset_bindex n_vecs, bitset_bindex n_bits, /* Allocate vector table at head of bitset array. */ size_t vector_bytes = (n_vecs + 1) * sizeof (bitset) + bytes - 1; vector_bytes -= vector_bytes % bytes; - bitset *bsetv = xcalloc (1, vector_bytes + bytes * n_vecs); + bitset *bsetv = xzalloc (vector_bytes + bytes * n_vecs); bitset_bindex i = 0; for (i = 0; i < n_vecs; i++)