summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAkim Demaille <akim.demaille@gmail.com>2019-09-06 11:38:48 +0200
committerAkim Demaille <akim.demaille@gmail.com>2019-09-08 08:38:49 +0200
commit03add7eb9d06ab509034ba01c904a4cb36f5706b (patch)
tree553447c02501bfcb7c117d9729190ff23e21b1e7
parentd3bb911fd0f53b2c69c96da43cc0f6557f3d2dd8 (diff)
downloadgnulib-03add7eb9d06ab509034ba01c904a4cb36f5706b.tar.gz
gnulib-03add7eb9d06ab509034ba01c904a4cb36f5706b.tar.bz2
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.
-rw-r--r--ChangeLog8
-rw-r--r--lib/bitset.c2
-rw-r--r--lib/bitset/stats.c8
-rw-r--r--lib/bitset/vector.c4
-rw-r--r--lib/bitsetv.c2
5 files changed, 15 insertions, 9 deletions
diff --git a/ChangeLog b/ChangeLog
index 077471de99..5c226ce436 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,13 @@
2019-09-06 Akim Demaille <akim@lrde.epita.fr>
+ 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 <akim@lrde.epita.fr>
+
bitset: check memory allocation
Reported by 江 祖铭 (Zu-Ming Jiang).
With help from Paul Eggert.
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++)

Return to:

Send suggestions and report system problems to the System administrator.