diff options
Diffstat (limited to 'src/common/container.h')
-rw-r--r-- | src/common/container.h | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/common/container.h b/src/common/container.h index 6a795d996c..7560ad48c8 100644 --- a/src/common/container.h +++ b/src/common/container.h @@ -336,6 +336,21 @@ bitarray_init_zero(int n_bits) size_t sz = (n_bits+BITARRAY_MASK) / (1u << BITARRAY_SHIFT); return tor_malloc_zero(sz*sizeof(unsigned int)); } +static INLINE bitarray_t * +bitarray_expand(bitarray_t *ba, int n_bits_old, int n_bits_new) +{ + size_t sz_old = (n_bits_old+BITARRAY_MASK) / (1u << BITARRAY_SHIFT); + size_t sz_new = (n_bits_new+BITARRAY_MASK) / (1u << BITARRAY_SHIFT); + char *ptr; + if (sz_new <= sz_old) + return ba; + ptr = tor_realloc(ba, sz_new); + memset(ptr+sz_old, 0, sz_new-sz_old); /* This does nothing to the older + * excess bytes. But they were + * already set to 0 by + * bitarry_init_zero. */ + return (bitarray_t*) ptr; +} /** Free the bit array <b>ba</b>. */ static INLINE void bitarray_free(bitarray_t *ba) |